Zookeeper Cluster Deployment

build Zookeeper cluster

  • Download Zookeeper

Using the Zookeeper 3.4.11 as example. Please make sure the java open jdk7 runtime environment is installed on the server.

  1. $ cd /opt/app
  2. $ wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
  3. $ tar -xzvf zookeeper-3.4.11.tar.gz
  4. $ mv zookeeper-3.4.11 zookeeper
  5. $ cd zookeeper
  • Modify the configuration file
  1. $ cp conf/zoo_sample.cfg conf/zoo.cfg
  2. $ vim conf/zoo.cfg
  • The configuration file is modified as below
  1. tickTime=2000
  2. initLimit=10
  3. syncLimit=5
  4. dataDir=/opt/app/zookeeper/zkdata
  5. dataLogDir=/opt/app/zookeeper/logs
  6. clientPort=2181
  7. server.1=192.168.2.80:2888:3888
  8. server.2=192.168.2.81:2888:3888
  9. server.3=192.168.2.82:2888:3888
  • Create a data folder
  1. mkdir -p /opt/app/zookeeper/zkdata
  2. mkdir -p /opt/app/zookeeper/logs

Do the same installation to the other servers which need install zookeeper.

Next we will build zookeeper cluster.

  • Create a Zookeeper node identification file myid

Create myid number, execution on each server, pay attention to each servermyid to correspond to the correct number.

  1. 192.168.2.80
  2. $ echo "1" > /opt/app/zookeeper/zkdata/myid
  1. 192.168.2.81
  2. $ echo "2" > /opt/app/zookeeper/zkdata/myid
  1. 192.168.2.82
  2. $ echo "3" > /opt/app/zookeeper/zkdata/myid
  • Start Zookeeper
  1. 192.168.2.80
  2. $ /opt/app/zookeeper/bin/zkServer.sh start
  1. 192.168.2.81
  2. $ /opt/app/zookeeper/bin/zkServer.sh start
  1. 192.168.2.82
  2. $ /opt/app/zookeeper/bin/zkServer.sh start
  • Zookeeper status check
  1. 192.168.2.80
  2. $ /opt/app/zookeeper/bin/zkServer.sh status

If the Zookeeper start failed, please check the below reasons:

1、Zoo.cfg file configuration error: dataLogDir specified directory is not created.

2、The integer in the myid file is not formatted correctly or does not correspond to the server integer inzoo.cfg.

3、The firewall does not open the Zookeeper service port, such as 2888 and3888.