本文所描述的SolrCloud环境搭建使用版本是v6.6,是在windows环境下操作的。
官网有一个自动化的交互式的脚本,引导你如何快速简单地创建一个SolrCloud集群。
官网的最后一段话也说明了,如果你已经熟悉了SolrCloud是如何工作的,建议学习[如何将Solr运用到生产章节][2]
所谓伪集群搭建,是利用单机的多个端口来模拟多台机器组成集群。
1)下载安装
官网下载solr-6.6.0.zip
,解压安装包3次到同一目录下(如E:\solr-rc\
),生成文件夹E:\solr-rc\solr-6.6.0-1
,E:\solr-rc\solr-6.6.0-1
,E:\solr-rc\solr-6.6.0-1
。目前三个文件夹完全一致,用作伪集群的三个单点。三个文件夹起个别名,分别是A,B,C。
E:\solr-rc\solr-6.6.0-1\bin\solr.in.cmd
。依据文件内部提示需要设置如下几个变量。set ZK_HOST=localhost:2181/rc
set SOLR_TIMEZONE=UTC+8
set SOLR_PORT=8983
这三个变量我认为是必须设置的,ZK_HOST用来管理配置文件,SOLR_TIMEZONE用来设置时区(方便log4j输出当地时间,增量/全量索引时间戳记录值也与时区相关),SOLR_PORT设置后通过bin/solr.cmd start 启动solr单节点时不必再明确指定端口
B文件夹修改端口为8984,C文件夹修改端口为8985
3)启动脚本组成SolrCloud
三个节点下依次执行bin/solr.cmd start
命令启动后,将会组成一个SolrCloud。
4)上传模板配置到zookeeper上。
solrCloud使用zookeeper作为配置管理中心。你需要将默认配置上传到zookeeper中。
具体命令参考[官网][4]
我这里以A文件夹来做操作示范,执行
./server/scripts/cloud-scripts/zkcli.bat -zkhost 127.0.0.1:2181/rc -cmd upconfig -confname item -confdir server/solr/configsets/basic_configs/conf
将在zookeeper上生成如下节点,见下图
特别说明,rc节点是启动集群前手动创建的,rc节点下的非configs节点是启动集群后自动生成的,configs节点是上传配置模板到zookeeper上后自动生成的。
5)新建collection
1)通过SolrUI界面可以新建collection
config set 里可以选择第4步设置的confname,本示例教程中是item,还可以设置分片数,设置副本数,默认情况下单节点最多只能拥有一个分片,高级选项中可以更改。
/admin/collections?action=CREATE&name=name&numShards=number&replicationFactor=number&maxShardsPerNode=number&createNodeSet=nodelist&collection.configName=configname
,具体参数意义参见官网[相关章节][5][CentOS7下Solr6.6+ZooKeeper 集群安装部署][3]
[1]:https://lucene.apache.org/solr/guide/6_6/getting-started-with-solrcloud.html#GettingStartedwithSolrCloud-Addinganodetoacluster
[2]:https://lucene.apache.org/solr/guide/6_6/taking-solr-to-production.html#taking-solr-to-production
[3]:https://www.linuxidc.com/Linux/2017-12/149902.htm
[4]:https://lucene.apache.org/solr/guide/6_6/command-line-utilities.html#CommandLineUtilities-Uploadaconfigurationdirectory
[5]:https://lucene.apache.org/solr/guide/6_6/collections-api.html#CollectionsAPI-create
版本6.6
Microsoft Windows [版本 10.0.16299.371]
(c) 2017 Microsoft Corporation。保留所有权利。
E:\solr-6.6.0\bin>solr -e cloud
Welcome to the SolrCloud example!
This interactive session will help you launch a SolrCloud cluster on your local workstation.
To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2]:
Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.
Please enter the port for node1 [8983]:
Please enter the port for node2 [7574]:
Creating Solr home directory E:\solr-6.6.0\example\cloud\node1\solr
Cloning E:\solr-6.6.0\example\cloud\node1 into
E:\solr-6.6.0\example\cloud\node2
Starting up Solr on port 8983 using command:
"E:\solr-6.6.0\bin\solr.cmd" start -cloud -p 8983 -s "E:\solr-6.6.0\example\cloud\node1\solr"
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!
Starting up Solr on port 7574 using command:
"E:\solr-6.6.0\bin\solr.cmd" start -cloud -p 7574 -s "E:\solr-6.6.0\example\cloud\node2\solr" -z localhost:9983
Waiting up to 30 to see Solr running on port 7574
Started Solr server on port 7574. Happy searching!
INFO - 2018-04-22 19:10:19.388; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready
Now let's create a new collection for indexing documents in your 2-node cluster.
Please provide a name for your new collection: [gettingstarted]
How many shards would you like to split gettingstarted into? [2]
How many replicas per shard would you like to create? [2]
Please choose a configuration for the gettingstarted collection, available options are:
basic_configs, data_driven_schema_configs, or sample_techproducts_configs [data_driven_schema_configs]
Connecting to ZooKeeper at localhost:9983 ...
INFO - 2018-04-22 19:11:00.027; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready
Uploading E:\solr-6.6.0\server\solr\configsets\data_driven_schema_configs\conf for config gettingstarted to ZooKeeper at localhost:9983
Creating new collection 'gettingstarted' using command:
http://localhost:8983/solr/admin/collections?action=CREATE&name=gettingstarted&numShards=2&replicationFactor=2&maxShardsPerNode=2&collection.configName=gettingstarted
{
"responseHeader":{
"status":0,
"QTime":15391},
"success":{
"192.168.56.1:8983_solr":{
"responseHeader":{
"status":0,
"QTime":13445},
"core":"gettingstarted_shard2_replica1"},
"192.168.56.1:7574_solr":{
"responseHeader":{
"status":0,
"QTime":13821},
"core":"gettingstarted_shard1_replica2"}}}
Enabling auto soft-commits with maxTime 3 secs using the Config API
POSTing request to Config API: http://localhost:8983/solr/gettingstarted/config
{"set-property":{"updateHandler.autoSoftCommit.maxTime":"3000"}}
Successfully set-property updateHandler.autoSoftCommit.maxTime to 3000
SolrCloud example running, please visit: http://localhost:8983/solr
E:\solr-6.6.0\bin>
solr start -cloud -s E:\solr-6.6.0\example\cloud\node3\solr -p 8984 -z localhost:9983