ZooKeeper Client Tutorial
ZooKeeper is a distributed configuration and synchronization service for large distributed systems. ZooKeeper's architecture supports high availability through redundant services. In the following tutorial we are going to start a group of ZooKeeper servers, then interact with them from both the command line and a GUI client. First download the zip file which contains everything you need:
Contents
- ZooKeeper Architecture
- Run ZooKeeper Servers - locally start three servers
- Start a Client and connect to server
- ZooKeeper GUI
- Create/Watch/Delete zNodes
ZooKeeper Tutorial
ZooKeeper Architecture
First it would be best to introduce what ZooKeeper is. ZooKeeper is a replicated service spread over a number of servers called an ensemble. It provides a set of reliable basic services, similar to a filesystem to allow coordination. It's architecture looks like this:

ZooKeeper nodes store their data in a hierarchical name space, much like a file system or a tree data structure. Clients can read from and write to the nodes and in this way have a shared configuration service. Updates are totally ordered.
Run ZooKeeper Servers
First download the demo files. Once unzipped you will see it has a number
of folders s1/s2/s3 that contains the config for three servers and a number of .bat files for launching.
To run a single server we could specify the command: java -jar ../zookeeper-3.3.3-fatjar.jar server s.cfg
within the .cfg file is the config which looks like this:
We are going to run three servers to demonstrate failover, to do this use start-servers.bat
. These
three servers run based on config in directories s1/s2/s3 respectively like so:

Start a Client and connect to server
To start a client that will connect to our servers we can either run start-client.bat
or the command
java -jar zookeeper-3.3.3-fatjar.jar client -server
.
Below you can see me starting a command line client and then using the ls and create commands.
I use create /demo1 "example of zk"
to create a new node demo1 with some string data:
ZooKeeper GUI Client
To start the zooinspector client run javaw -cp * org.apache.zookeeper.inspector.ZooInspector
:


Create/Watch/Delete zNodes
Some Commands available in the cli client include:
ZooKeeper Command Line Commands
Command | Description |
---|---|
help | Display possible commands |
ls path [watch] | List the contents of a zNode and optionally watch it for changes. |
create path data | Create a new zNode containing the data specified. |
set path data | Set the data for an existing zNode. |
delete path | Delete an existing path. |