Zookeeper Tutorial – Tutorialspoint

Before installing ZooKeeper, make sure your system is running on any of the following

operating systems, any of

  • the Linux operating systems, supports development and deployment. Preferred for demonstration applications.

  • Windows operating system: Supports development only.

  • Mac OS – Only supports development.

The ZooKeeper server is created in Java and runs in JVM. You must use JDK 6 or higher.

Now, follow the steps given below to install the ZooKeeper framework on your machine.

Step 1: Verifying the installation of


We believe you already have a Java environment installed on your system. Just check it using the following command.

$ java -version If you have Java installed

on your machine, then you could see the version of Java installed. Otherwise, follow the simple steps given below to install the latest version of Java.

Step 1.1: Download

JDK Download the latest version

of JDK by visiting the link below and download the latest version. Java

The latest version (while writing this tutorial) is JDK 8u 60 and the file is “jdk-8u60-linuxx64.tar.gz”. Download the file to your machine.

Step 1.2: Extract

the files

Generally, the files are downloaded to the Downloads folder. Check it and extract the tar configuration using the following commands.

$ cd /go/to/download/path $ tar -zxf jdk-8u60-linux-x64.gz Step 1.3: Move to the opt directory To

make Java available to all users, move the extracted java content to the “/usr/local/java” folder

. $ your password: (type the root user’s password) $ mkdir /opt/jdk $ mv jdk-1.8.0_60 /opt/jdk/

Step 1.4: Set Path

To set the path and JAVA_HOME variables, Add the following commands to the ~/.bashrc file.

export JAVA_HOME = /usr/jdk/jdk-1.8.0_60 export PATH=$PATH:$JAVA_HOME/bin

Now, apply all changes to the current running system

. $ source ~/.bashrc Step

1.5: Java Alternatives

Use the following command to change Java alternatives

. update-alternatives -install /usr/bin/java java /opt/jdk/jdk1.8.0_60/bin/java 100 Step 1.6

Verify the Java installation using the verification command (java -version) explained in step

1. Step 2: Install ZooKeeper Framework Step 2.1: Download ZooKeeper To install ZooKeeper

framework on your machine, visit the link below and download the

latest version of ZooKeeper



As of now, the latest version of

ZooKeeper is 3.4.6 (ZooKeeper-3.4.6.tar.gz). Step 2.2: Extract the tar file Extract the tar file using

the following commands

: $ cd opt/ $ tar -zxf zookeeper-3.4.6.tar.gz $ cd zookeeper-3.4.6 $ mkdir data

Step 2.3


Create Configuration File Open the configuration file named conf/zoo.cfg using the vi conf/zoo command.cfg

and all of the following parameters to set as a starting point. $ vi conf/zoo.cfg

tickTime = 2000 dataDir = /path/to/zookeeper/data clientPort = 2181 initLimit = 5 syncLimit = 2

Once the configuration file has been successfully saved, return to the terminal again. You can now start the zookeeper server.

Step 2.4: Start the ZooKeeper server

Run the

following command: $ bin/zkServer.sh start

After running this command, you will get a response as follows

: $ JMX enabled by default $ Using config: /Users/.. /zookeeper-3.4.6/bin/.. /conf/zoo.cfg$ Starting zookeeper… STARTED

Step 2.5: Start CLI

Type the following command


$ bin/zkCli.sh

After typing the above command, you will connect to the ZooKeeper server and should get the following response.

Connection to localhost:2181 ……………. Welcome to ZooKeeper! ……………. ……………. WATCHER:: WatchedEvent state:SyncConnected type: None path:null [zk: localhost:2181(CONNECTED) 0]

Stop the ZooKeeper

server After connecting the server

and performing all operations, you can stop the zookeeper server by using the following command.

$ bin/zkServer.sh stop

Contact US