Step‑by‑Step Guide to Installing a ZooKeeper Pseudo‑Cluster on a Single Machine
This guide explains the concepts of ZooKeeper cluster roles and provides step‑by‑step instructions, including configuration file edits and command‑line operations, to set up a pseudo‑cluster on a single machine for testing and learning purposes.
In the previous article we introduced ZooKeeper fundamentals such as its concepts, use cases, and data model, and demonstrated a single‑node installation. This article extends the tutorial to show how to install a ZooKeeper cluster, albeit a pseudo‑cluster performed on one host, which mirrors the steps required for a real multi‑node deployment.
ZooKeeper clusters consist of three types of servers: Leader – the sole node that handles write requests and coordinates the ensemble; Follower – processes client requests, participates in leader election, and forwards writes to the leader; and Observer – like a follower but does not vote in elections, typically omitted in small clusters.
First, download the ZooKeeper package to /usr/local and extract it. Then rename the sample configuration file conf/zoo_sample.cfg to conf/zoo1.cfg and edit it with the following parameters:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper-1
clientPort=2181
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890Copy zoo1.cfg to create zoo2.cfg and zoo3.cfg , then adjust the dataDir and clientPort values for each:
dataDir=/tmp/zookeeper-2
clientPort=2182 dataDir=/tmp/zookeeper-3
clientPort=2183Create the data directories and a myid file in each, containing the server’s numeric ID (1, 2, or 3):
mkdir /tmp/zookeeper-1
mkdir /tmp/zookeeper-2
mkdir /tmp/zookeeper-3 cd /tmp/zookeeper-1
touch myid
vim myid # write "1"
# repeat for myid in zoo2 and zoo3 with "2" and "3" respectivelyStart the three ZooKeeper instances from the installation root:
bin/zkServer.sh start conf/zoo1.cfg
bin/zkServer.sh start conf/zoo2.cfg
bin/zkServer.sh start conf/zoo3.cfgCheck the ensemble status; you will see that one of the nodes (e.g., the second) has assumed the Leader role. At this point the basic ZooKeeper cluster is up and running, ready for further tuning based on specific business requirements.
Note that this tutorial provides an introductory setup; ZooKeeper offers many additional configuration options that may need adjustment for production environments.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
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.