当然这是在我们solr单机版已经搭建好了的情况下
mkdir /usr/local/solr-cloud
复制3个zookeeper [最少的集群至少有3个zookeeper集群]
cp zookeeper /usr/local/solr-cloud/zookeeper01
cp zookeeper /usr/local/solr-cloud/zookeeper02
cp zookeeper /usr/local/solr-cloud/zookeeper03
cd zookeeper01
mkdir data
cd data
echo 1 > /data/myid
cd conf
mv zoo_sample.cfg zoo.cfg
vim zoo.cfg
dataDir=/usr/local/solr-cloud/zookeeper01/data
clientPort=2182 修改端口号,这个是客户端连接的端口
server.1=172.16.82.68:2881:3881 这里2881是zookeeper内部通讯的端口号,3881是选举的端口号
server.2=172.16.82.68:2882:3882
server.3=172.16.82.68:2883:3883
其余同理 * 3
启动zookeeper集群
cd /usr/local/solr-cloud/zookeeper01/bin
./zkServer.sh start
cd ../../
cd /usr/local/solr-cloud/zookeeper02/bin
./zkServer.sh start
cd ../../
cd /usr/local/solr-cloud/zookeeper03/bin
./zkServer.sh start
cd ../../
chomd +x start-zookeeper.sh
复制4个tomcat过去
cp tomcat /usr/local/solr-cloud/tomcat01
cp tomcat /usr/local/solr-cloud/tomcat02
cp tomcat /usr/local/solr-cloud/tomcat03
cp tomcat /usr/local/solr-cloud/tomcat04
配置tomcat端口号
vim tomcat01/conf/server.xml
/port
8105 8180 8109
:wq
_____________________________________________
vim tomcat02/conf/server.xml
/port
8205 8280 8209
:wq
....其余tomcat同理
把solr拷贝到每个tomcat下
cp -r solr /tomcat01/webapps/
cp -r solr /tomcat02/webapps/
cp -r solr /tomcat03/webapps/
cp -r solr /tomcat04/webapps/
拷贝一下solrhome
cp -r solrhome /usr/local/solr-cloud/solrhome01
cp -r solrhome /usr/local/solr-cloud/solrhome02
cp -r solrhome /usr/local/solr-cloud/solrhome03
cp -r solrhome /usr/local/solr-cloud/solrhome04
接下来配置一下solrhome
118.31.42.117
8180
_________________________________________________
118.31.42.117
8280
....同理
修改一下solr下的web.xml 修改
vim /usr/local/solr-cloud/tomcat01/webapps/solr/WEB-INF/web.xml
solr/home
/usr/local/solr-cloud/solrhome01
java.lang.String
_________________________________________________
vim /usr/local/solr-cloud/tomcat02/webapps/solr/WEB-INF/web.xml
solr/home
/usr/local/solr-cloud/solrhome02
java.lang.String
...其余同理
配置tomcat 将solr和zookeeper的关联关系建立起来 配置JAVA_OPTS指定一下zkHost
cd tomcat01/bin
vim catalina.sh
JAVA_OPTS="-DzkHost=118.31.42.117:2182,118.31.42.117:2183,118.31.42.117:2184"
其他tomcat同理
配置文件上传zookeeper
每个tomcat下的solr都有他的solrhome,但solrhome下他们的配置文件可能会不一样,在集群环境下配置一般都是一份儿的,所以我们需要把配置文件上传到zookeeper,让zookeeper管理我们的配置文件
我们需要上传 solrhome/conf
这里我们需要用到 solr/example/scripts/cloud-scripts/zkcli.sh 我们用这个来上传
cd solr/example/scripts/cloud-scripts/
./zkcli.sh -zkhost 192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183 -cmd upconfig -confdir /usr/local/solr-cloud/solrhome01/collection1/conf/ -confname myconf
链接zookeeper检查一下conf文件是否上传成功了
./zkCli.sh -server 192.168.25.154:2182
ls /configs
启动tomcat
/usr/local/solr-cloud/tomcat01/bin/startup.sh
/usr/local/solr-cloud/tomcat02/bin/startup.sh
/usr/local/solr-cloud/tomcat03/bin/startup.sh
/usr/local/solr-cloud/tomcat04bin/startup.sh
chomd +x start-tomcat.sh
最后,SolrCloud创建Collection的命令
http://192.168.25.154:8180/solr/admin/collections?action=CREATE&name=collection2&numShards=2&replicationFactor=2
删除Collection1的分片
http://192.168.25.154:8180/solr/admin/collections?action=DELETE&name=collection1