前提条件
三个zookeeper实例。Zookeeper也是java开发的所以需要安装jdk。3、Zookeeper。
[root@solr ~]# tar -zxvf zookeeper-3.4.6.tar.gz
[root@solr ~]# mkdir /home/solrcloud
[root@solr ~]# mv zookeeper-3.4.6 /home/solrcloud/zookeeper1
[root@solr ~]# cd /home/solrcloud/
[root@solr solrcloud]# cp -r zookeeper1/ zookeeper2
[root@solr solrcloud]# cp -r zookeeper1/ zookeeper3
1、在每个zookeeper文件夹下创建一个data目录。
2、在data文件夹下创建一个文件名称为myid,文件的内容就是此zookeeper的编号1、2、3
[root@solr solrcloud]# echo 1 >> zookeeper1/data/myid
[root@solr solrcloud]# echo 2 >> zookeeper2/data/myid
[root@solr solrcloud]# echo 3 >> zookeeper3/data/myid
3、分别把zookeeper1、2、3下conf目录下的zoo_sample.cfg文件复制一份改名为zoo.cfg
[root@solr conf]# cp zoo_sample.cfg zoo.cfg
4、分别修改zookeeper1、2、3的配置文件zoo.cfg(zookeeper2的clientPort=2182,zookeeper3的clientPort=2183)
dataDir=/home/solrcloud/zookeeper1/data/
clientPort=2181
server.1=192.168.168.128:2881:3881
server.2=192.168.168.128:2882:3882
server.3=192.168.168.128:2883:3883
启动zookeeper:./zkServer.sh start
关闭:./zkServer.sh stop
查看状态:./zkServer.sh status
[root@solr solrcloud]# zookeeper1/bin/zkServer.sh start
JMX enabled by default
Using config: /home/solrcloud/zookeeper1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@solr solrcloud]# zookeeper2/bin/zkServer.sh start
JMX enabled by default
Using config: /home/solrcloud/zookeeper2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@solr solrcloud]# zookeeper3/bin/zkServer.sh start
JMX enabled by default
Using config: /home/solrcloud/zookeeper3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
查看状态:
[root@solr solrcloud]# zookeeper1/bin/zkServer.sh status
JMX enabled by default
Using config: /home/solrcloud/zookeeper1/bin/../conf/zoo.cfg
Mode: follower
[root@solr solrcloud]# zookeeper2/bin/zkServer.sh status
JMX enabled by default
Using config: /home/solrcloud/zookeeper2/bin/../conf/zoo.cfg
Mode: leader
[root@solr solrcloud]# zookeeper3/bin/zkServer.sh status
JMX enabled by default
Using config: /home/solrcloud/zookeeper3/bin/../conf/zoo.cfg
Mode: follower