终于搭建好了一个SolrCloud并可以正常运行了。下面总结一下其中的过程。。。SolrCloud使用ZooKeeper来管理配置文件,所以需要安装、配置、并启动ZooKeeper。
主要步骤:
- 安装和启动Solr(Service方式)
- 配置和启动ZooKeeper
- 配置和启动一个collection:
- 为新的collection创建配置文件目录、准备好配置文件
- 把配置文件上传到ZooKeeper
- 创建新的collection(使用Collections API)
1、安装和启动Solr(Service方式)
参考:Solr在Linux系统中的产品化安装
确保Solr是在solrCloud模式下运行(查询solr service状态,看看是否有“clound”字样):
# service solr status
Found 1 Solr nodes:
Solr process 2394 running on port 8983
{
"solr_home":"/var/solr/data/",
"version":"5.2.1 1684708 - shalin - 2015-06-10 23:20:13",
"startTime":"2015-09-01T02:41:12.845Z",
"uptime":"0 days, 0 hours, 0 minutes, 23 seconds",
"memory":"26.4 MB (%5.4) of 490.7 MB",
" cloud":{
"ZooKeeper":"localhost:2181,localhost:2182,localhost:2183",
"liveNodes":"1",
"collections":"0"}}
Found 1 Solr nodes:
Solr process 2394 running on port 8983
{
"solr_home":"/var/solr/data/",
"version":"5.2.1 1684708 - shalin - 2015-06-10 23:20:13",
"startTime":"2015-09-01T02:41:12.845Z",
"uptime":"0 days, 0 hours, 0 minutes, 23 seconds",
"memory":"26.4 MB (%5.4) of 490.7 MB",
" cloud":{
"ZooKeeper":"localhost:2181,localhost:2182,localhost:2183",
"liveNodes":"1",
"collections":"0"}}
2、配置和启动ZooKeeper
参考:Zookeeper及其安装配置和启动
3、配置和启动一个collection
3.1、为新的collection创建配置文件目录、准备好配置文件
从模板拷贝一份配置文件后自己修改:
cd /opt/app/solr/server/solr/configsets
cp -r basic_configs/conf course_video
cd course_video
以DIH为例,修改配置文件:
参考:Solr DataImportHandler 配置
其他相关配置文件的配置方法:
- Solr 配置文件之schema.xml:http://blog.youkuaiyun.com/clementad/article/details/47666043
- Solr 配置文件之solrconfig.xml:http://blog.youkuaiyun.com/clementad/article/details/47975007
- Solr 配置文件之core.properties、solr.xml和Config Sets:http://blog.youkuaiyun.com/clementad/article/details/48004315
zkcli.sh位于<solr_home>/server/scripts/cloud-scripts/目录下面。
# cd <solr_home>
# ./server/scripts/cloud-scripts/zkcli.sh -z localhost:2181
-cmd upconfig -confname <config_name> -confdir
server/solr/configsets/<conf_dir>
例如:
cd /opt/app/solr
./server/scripts/cloud-scripts/zkcli.sh -z localhost:2181
-cmd upconfig -confname course_video -confdir server/solr/configsets/course_video
查看配置文件列表:
/opt/app/solr/server/scripts/cloud-scripts/zkcli.sh -cmd list -z localhost:2181
注:修改配置文件后,需要使它生效:
- 管理界面方法:Core Admin -> 选择修改过的core -> reload
- Collections API方法:curl 'http://localhost:8983/solr/admin/collections?action=RELOAD&name=course_video'
3.3、创建新的collection(使用Collections API)
curl 'http://<hostname>:<port>/solr/admin/collections?action=CREATE&name=<name>&numShards=1' (其他都是非必填参数)
例如:
curl 'http://localhost:8983/solr/admin/collections?action=CREATE&name=course_video&numShards=1'
如果需要修改配置:
- 修改配置文件
- 上传到ZooKeeper
- Reload Collection:curl 'http://localhost:8983/solr/admin/collections?action=RELOAD&name=course_video'
- 重建索引:curl 'http://localhost:8983/solr/course_video/dataimport?command=full-import&wt=json'
附:监看solr的log:
tail -f /var/solr/logs/solr.log
附:Collections API列表:
Base URL:http://<hostname>:<port>/solr
/admin/collections?action=CREATE: create a collection
/admin/collections?action=RELOAD: reload a collection
/admin/collections?action=SPLITSHARD: split a shard into two new shards
/admin/collections?action=CREATESHARD: create a new shard
/admin/collections?action=DELETESHARD: delete an inactive shard
/admin/collections?action=CREATEALIAS: create or modify an alias for a collection
/admin/collections?action=DELETEALIAS: delete an alias for a collection
/admin/collections?action=DELETE: delete a collection
/admin/collections?action=DELETEREPLICA: delete a replica of a shard
/admin/collections?action=ADDREPLICA: add a replica of a shard
/admin/collections?action=CLUSTERPROP: Add/edit/delete a cluster-wide property
/admin/collections?action=MIGRATE: Migrate documents to another collection
/admin/collections?action=ADDROLE: Add a specific role to a node in the cluster
/admin/collections?action=REMOVEROLE: Remove an assigned role
/admin/collections?action=OVERSEERSTATUS: Get status and statistics of the overseer
/admin/collections?action=CREATE: create a collection
/admin/collections?action=RELOAD: reload a collection
/admin/collections?action=SPLITSHARD: split a shard into two new shards
/admin/collections?action=CREATESHARD: create a new shard
/admin/collections?action=DELETESHARD: delete an inactive shard
/admin/collections?action=CREATEALIAS: create or modify an alias for a collection
/admin/collections?action=DELETEALIAS: delete an alias for a collection
/admin/collections?action=DELETE: delete a collection
/admin/collections?action=DELETEREPLICA: delete a replica of a shard
/admin/collections?action=ADDREPLICA: add a replica of a shard
/admin/collections?action=CLUSTERPROP: Add/edit/delete a cluster-wide property
/admin/collections?action=MIGRATE: Migrate documents to another collection
/admin/collections?action=ADDROLE: Add a specific role to a node in the cluster
/admin/collections?action=REMOVEROLE: Remove an assigned role
/admin/collections?action=OVERSEERSTATUS: Get status and statistics of the overseer
/admin/collections?action=CLUSTERSTATUS: Get cluster status
/admin/collections?action=REQUESTSTATUS: Get the status of a previous asynchronous request
/admin/collections?action=LIST: List all collections
/admin/collections?action=ADDREPLICAPROP: Add an arbitrary property to a replica specified by
collection/shard/replica
/admin/collections?action=DELETEREPLICAPROP: Delete an arbitrary property from a replica specified
by collection/shard/replica
/admin/collections?action=BALANCESHARDUNIQUE: Distribute an arbitrary property, one per shard,
across the nodes in a collection
/admin/collections?action=REBALANCELEADERS: Distribute leader role based on the "preferredLeader"
assignments
附:zkcli.sh命令参数列表: