环境版本: CDH 5.12.0; Solr 4.10.3
CDH搭建SolrCloud集群十分方便,添加服务->solr->选择主机->next即可
在SolrCloud中,跨多个节点的索引分割称为集合(collection),见下图:
[root@DXHY-YFEB-01 solr]# pwd
/var/lib/solr
[root@DXHY-YFEB-01 solr]# mv Invoice_bak/ test_invoice
[root@DXHY-YFEB-01 solr]# ls
#创建 collection 实例并将配置文件上传到 zookeeper
[root@DXHY-YFEB-01 solr]# solrctl instancedir --create test_invoice ./test_invoice
#在Zookeeper查看配置文件
[root@DXHY-YFEB-01 solr]# zookeeper-client
[zk: localhost:2181(CONNECTED) 1] ls /solr
[configs, overseer, aliases.json, live_nodes, collections, overseer_elect, clusterstate.json, solr.xml, zkdtsm, clusterprops.json, token]
[zk: localhost:2181(CONNECTED) 2] ls /solr/configs
[realestate, schemalessTemplateSecure, managedTemplate, schemalessTemplate, predefinedTemplate, managedTemplateSecure, predefinedTemplateSecure, test_invoice]
#查看上传的实体
[root@DXHY-YFEB-01 solr]# solrctl instancedir --list
managedTemplate
managedTemplateSecure
predefinedTemplate
predefinedTemplateSecure
realestate
schemalessTemplate
schemalessTemplateSecure
solrtest
test_invoice
#创建 collection
[root@DXHY-YFEB-01 solr]# solrctl collection --create test_invoice -s 2 -c test_invoice -r 2 -m 3
#如果新集合可以使用与现有集合一样的配置文件,不需重新复制上传
[root@DXHY-YFEB-01 solr]# solrctl collection --create test_invoice2 -s 2 -c test_invoice -r 2 -m 3
#-c <collection.configName> -s <numShards> -r <replicationFactor> -m <maxShardsPerNode>
#注意:numShards*replicationFactor <= maxShardsPerNode*numNode
#更新配置,更新后新建的索引会按更新后的配置创建,之前的不变。
[root@DXHY-YFEB-01 solr-doc-4.10.3+cdh5.12.0+513]# solrctl instancedir --update test_invoice ./test_invoice
Uploading configs from ./realestate/conf to DXHY-YFEB-03:2181,DXHY-YFEB-01:2181,DXHY-YFEB-02:2181/solr. This may take up to a minute.
[root@DXHY-YFEB-01 solr-doc-4.10.3+cdh5.12.0+513]# solrctl collection --reload test_invoice
备注:
solrctl命令
solrctl [options] command [command-arg] [command [command-arg]] ...
可选参数有:
--solr:指定 SolrCloud 的 web API,如果在 SolrCloud 集群之外的节点运行命令,就需要指定该参数。
--zk:指定 zk 集群solr目录。
--help:打印帮助信息。
--quiet:静默模式运行。
command 命令有:
init [--force]:初始化配置。
instancedir:维护实体目录。可选的参数有:
--generate path
--create name path
--update name path
--get name path
--delete name
--list
collection:维护 collections。可选的参数有:
--create name -s <numShards> [-c <collection.configName>] [-r <replicationFactor>] [-m <maxShardsPerNode>] [-n <createNodeSet>]]
--delete name: Deletes a collection.
--reload name: Reloads a collection.
--stat name: Outputs SolrCloud specific run-time information fora collection.
--list: Lists all collections registered in SolrCloud.
--deletedocs name: Purges all indexed documents from a collection.
core:维护 cores。可选的参数有:
--create name [-p name=value]...]
--reload name: Reloads a core.
--unload name: Unloads a core.
--status name: Prints status of a core.
cluster:维护集群配置信息。可选的参数有:
--get-solrxml file
--put-solrxml file
#全的参数列表
[root@DXHY-YFEB-03 kylin]# solrctl --help
usage: /opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12.0.p0.29/bin/../lib/solr/bin/solrctl.sh [options] command [command-arg] [command [command-arg]] ...
Options:
--solr solr_uri
--zk zk_ensemble
--jaas jaas.conf
--help
--quiet
--debug Prints error output of calls
--trace Prints executed commands
Commands:
init [--force]
instancedir [--generate path [-schemaless]]
[--create name path]
[--update name path]
[--get name path]
[--delete name]
[--list]
config [--create name baseConfig [-p name=value]...]
[--delete name]
collection [--create name -s <numShards>
[-a Create collection with autoAddReplicas=true]
[-c <collection.configName>]
[-r <replicationFactor>]
[-m <maxShardsPerNode>]
[-n <createNodeSet>]]
[--delete name]
[--reload name]
[--stat name]
[--deletedocs name]
[--list]
[--create-snapshot snapshotName -c <collectionName>]
[--delete-snapshot snapshotName -c <collectionName>]
[--list-snapshots collectionName]
[--describe-snapshot snapshotName -c <collectionName>]
[--prepare-snapshot-export snapshotName -c <collectionName> -d <destDir> [-p <fsPathPrefix>]]
[--export-snapshot snapshotName [-s <sourceDir>] [-c <collectionName>] -d <destDir>]
[--restore name -b <backupName> -l <backupLocation> -i <requestId>
[-a Restore collection with autoAddReplicas=true]
[-c <collection.configName>]
[-r <replicationFactor>]
[-m <maxShardsPerNode>]]
[--request-status requestId]
core [--create name [-p name=value]...]
[--reload name]
[--unload name]
[--status name]
cluster [--get-solrxml file]
[--put-solrxml file]
[--set-property name value]
[--remove-property name]
[--get-clusterstate file]
sentry [--create-role role]
[--drop-role role]
[--add-role-group role group]
[--delete-role-group role group]
[--list-roles [-g group]]
[--grant-privilege role privilege]
[--revoke-privilege role privilege]
[--list-privileges role]
[--convert-policy-file file [-dry-run]]
参考链接:http://blog.csdn.net/kissmelove01/article/details/45043955