Install Zookeeper Cluster on Centos7 with docker

Zookeeper May 13, 2020

The last blog we make it possible to login into docker container with ssh, now we can install zookeeper with ssh on centos7 container.

Download Zookeeper

Download zookeeper from

unzip zookeeper with tar -xvzf zookeeper-3.6.1-bin.tar.gz and rename the directory to zookeeper.

Start Centos7 Container

docker run --name zookeeper.1 -itd --network ideras --restart always --privileged=true --ip centos:7 /usr/sbin/init
docker run --name zookeeper.2 -itd --network ideras --restart always --privileged=true --ip centos:7 /usr/sbin/init
docker run --name zookeeper.3 -itd --network ideras --restart always --privileged=true --ip centos:7 /usr/sbin/init

Here we start three centos7 container, with name from zookeeper.1 to zookeepr.3, and give them fixed ip address, so we can ssh into the container with the ip address.

Copy zookeeper to the three container with scp.

scp -r /f/download/zookeeper [email protected]:/home/app
scp -r /f/download/zookeeper [email protected]:/home/app
scp -r /f/download/zookeeper [email protected]:/home/app

Setup Zookeeper Environment

On all three containers, cd into your zookeeper directory, here we use /home/app/zookeeper,edit conf/zoo.cfg, add the content below, it tells zookeeper that the cluster has three nodes, with port 2888 and 3888.


Next on generate a myid file under /home/app/zookeeper with content 1.

On generate a myid file under /home/app/zookeeper with content 2.

On generate a myid file under /home/app/zookeeper with content 3.

Start Zookeeper

On the three containers, run below command to start zookeeper program.

/home/app/zookeeper/bin/ start

Test zookeeper cluster status with command /home/app/zookeeper/bin/ status , it will show output like below.

ZooKeeper JMX enabled by default
Using config: /home/app/zookeeper/bin/../conf/zoo.cfg
Mode: leader

This means zookeeper is started successfully.

What's Next

The Apache Zookeeper system for distributed coordination is a high-performance service for building distributed applications.

Many program depends on zookeeper cluster, that's why we install cluster first, next we will install flink cluster with zookeeper cluster installed.

Shaoyang Liu

Founder of and, write blog about java and node.js technology.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.