How to Build a Reliable Zookeeper Cluster on Three Servers
This step‑by‑step guide shows how to install Zookeeper on three Linux servers, configure the ensemble with proper data directories and server IDs, start the services, verify their status, and perform basic client operations to confirm the cluster works correctly.
1 Install Zookeeper
Zookeeper can be installed quickly by downloading the binary package, confirming that Java is already installed, and extracting it to the desired location.
Download URL:
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gzCopy the archive to each server’s /opt directory and extract:
cd /opt
tar xzvf zookeeper-3.4.8.tar.gz2 Configure
Enter the configuration directory, copy the sample file, and edit it:
cd /opt/zookeeper-3.4.8/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfgSet the data directory, for example: dataDir=/var/zookeeper Add the three server entries at the end of the file (replace IPs with your own):
server.1=172.17.0.2:2888:3888
server.2=172.17.0.3:2888:3888
server.3=172.17.0.4:2888:3888Each server.X line defines a unique integer ID for the server.
Create a myid file in the data directory containing the corresponding ID on each host: /var/zookeeper/myid Example contents:
172.17.0.2 → 1
172.17.0.3 → 2
172.17.0.4 → 33 Start
Run the start script on all three machines:
/opt/zookeeper-3.4.8/bin/zkServer.sh start4 Status Check
Verify each node’s status with the status command: /opt/zookeeper-3.4.8/bin/zkServer.sh status Typical successful output is shown in the images below:
5 Operation Test
Execute a few Zookeeper client commands to ensure the ensemble works.
List nodes – the initial state shows only the default /zookeeper node.
Add a node – create a new znode and verify its creation.
Get node data – retrieve the data stored in the newly created node.
Delete the node – remove the znode and confirm deletion.
All tested operations succeed, confirming that the Zookeeper cluster is functioning correctly.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
