准备工作
1. 集群机器
192.168.8.2
192.168.8.6
192.168.8.11
2. 包
zookeeper-3.4.10.tar.gz
集群配置
1. 解压路径
192.168.8.2 /data1/projectX/zookeeper-3.4.10
192.168.8.6 /data1/projectX/zookeeper-3.4.10
192.168.8.11 /home/projectX/zookeeper-3.4.10
2. zoo.cnf
进入conf/ 目录,新建zoo.cnf文件,内容如下。(确保 dataDir 及 dataLogDir 所指向的路径已经存在)
192.168.8.2
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data1/projectX/zookeeper-3.4.10/data
dataLogDir=/data1/projectX/zookeeper-3.4.10/data/log
clientPort=2182
server.82=192.168.8.2:2887:3887
server.86=192.168.8.6:2887:3887
server.811=192.168.8.11:2887:3887
#maxClientCnxns=60
#autopurge.snapRetainCount=3
#autopurge.purgeInterval=1
192.168.8.6
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data1/projectX/zookeeper-3.4.10/data
dataLogDir=/data1/projectX/zookeeper-3.4.10/data/log
clientPort=2182
server.82=192.168.8.2:2887:3887
server.86=192.168.8.6:2887:3887
server.811=192.168.8.11:2887:3887
#maxClientCnxns=60
#autopurge.snapRetainCount=3
#autopurge.purgeInterval=1
192.168.8.11
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/projectX/zookeeper-3.4.10/data
dataLogDir=/home/projectX/zookeeper-3.4.10/data/log
clientPort=2182
server.82=192.168.8.2:2887:3887
server.86=192.168.8.6:2887:3887
server.811=192.168.8.11:2887:3887
#maxClientCnxns=60
#autopurge.snapRetainCount=3
#autopurge.purgeInterval=1
3. server.x 的配置
在三个机器的dataDir路径下面新建myid文件,内容分别为82,86 及 811 与 zoo.cnf中的保持一致。
server.82=192.168.8.2:2887:3887
server.86=192.168.8.6:2887:3887
server.811=192.168.8.11:2887:3887
启动Zookeeper
执行下面的命令分别启动三个zookeeper,无所谓顺序。
[root@RH bin]# cd /data1/projectX/zookeeper-3.4.10/bin/
[root@RH bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /data1/projectX/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@RH bin]# tail -f zookeeper.out
查看运行状态
192.168.8.2
-bash-4.1# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data1/projectX/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
192.168.8.6
[root@RH bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data1/projectX/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
192.168.8.11 << 被推选为Leader,其他两个为follower
[root@RDHW02-RIS bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/projectX/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
简单测试
-bash-4.1# ./zkCli.sh -server 192.168.8.11:2182
[zk: 192.168.8.11:2182(CONNECTED) 0] ls /
[zk: 192.168.8.11:2182(CONNECTED) 1] ls2 /
[zk: 192.168.8.11:2182(CONNECTED) 2] create /test helloworld
[zk: 192.168.8.11:2182(CONNECTED) 4] get /test
[zk: 192.168.8.11:2182(CONNECTED) 5] set /test newvalue
[zk: 192.168.8.11:2182(CONNECTED) 7] delete /test