首页 > 代码库 > zookeeper集群搭建

zookeeper集群搭建

1上传三个zookeeper到三个服务器,服务器ip分别为192.168.199.71,192.168.199.72,192.168.199.73,因为zookeeper会实行投票选举机制,所以集群数最好为奇数

2zookeeper分别解压到/usr/local/zookeeper目录下

3在zookeeper/conf下,复制zoo_sample.cfg为zoo.cfg,并修改zoo.cfg配置文件

tickTime=2000
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
server.0=192.168.199.71:2888:3888    
server.1=192.168.199.72:2888:3888     
server.2=192.168.199.73:2888:3888

4在zookeeper下,分别建立文件夹data和logs

5 192.168.199.71,192.168.199.72,192.168.199.73三个服务器,在data目录分别建立文件myid,并且里面内容分别为0,1,2,和配置文件的配置对应

6分别启动三个zookeeper bin/zkServer.sh start

7查看三个状态 bin/zkServer.sh status,会看其实一台服务器mode为leader,另外两台为follower

[root@localhost zookeeper]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader

[root@localhost zookeeper]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower


[root@localhost zookeeper]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower

8关闭leader服务器,另外两台会有一台变为leader,而关闭的这台重新启动,会变成follower模式  

zookeeper集群搭建