01: Getting started with Zookeeper tutorial

Installing Zookeepr on Windows

Step 1: Download Zookeeper from http://zookeeper.apache.org/. At the time of writing downloading zookeeper-3.4.11.tar.gz.

Step 2: Using 7-zip on windows unpack the gzipped tar file into a folder. E.g. c:\development\zookeeper-3.4.11. you can see “zkServer.cmd” in the bin folder for windows & “zkServer.sh” for Unix.

Starting the Zookeeper Server

Step 3: Copy the conf/zoo-sample.cfg to conf/zoo.cfg and the contents should look like the following for the standalone mode.

In production, you should run ZooKeeper in replicated mode. A replicated group of servers in the same application is called a quorum, and in replicated mode, all servers in the quorum have copies of the same configuration file. The file is similar to the one used in standalone mode, but with a few differences. Here is an example:

two port numbers after each server name: ” 2888″ and “3888” means the former is used to connect to other peers. More specifically, a ZooKeeper server uses this port to connect followers to the leader. When a new leader arises, a follower opens a TCP connection to the leader using this port.

Step 4: Open a DOS command prompt run the zkserver with the standalone mode config.

This will start the Zookeeper server with a single node.

If you want to use a replicated mode, then you need to create a “myid” file in “c:/data/zookeeper”, and also separate dataDirs and distinct clientPorts are also necessary. Running on a single localhost requires three config files.

Connecting to ZooKeeper

Once ZooKeeper server is running, clients can connect to it.

1. Open a new DOS command-line and type

2. You can use the Java programming API

Step 1: Firstly, the pom.xml file needs to have the Zookeeper dependency.

Step 2: The Java program using the Zookeeper API.

Step 3: Make sure that the zkserver is running via a DOS command line as explained earlier. Now run ZkConnect as a Java application.


300+ Java Interview FAQs

Tutorials on Java & Big Data