Operations 5 min read

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.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How to Build a Reliable Zookeeper Cluster on Three Servers

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.gz

Copy the archive to each server’s /opt directory and extract:

cd /opt
 tar xzvf zookeeper-3.4.8.tar.gz

2 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.cfg

Set 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:3888

Each 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 → 3

3 Start

Run the start script on all three machines:

/opt/zookeeper-3.4.8/bin/zkServer.sh start

4 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxCluster Setup
Java High-Performance Architecture
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.