Download and Install Apache Zookeeper on Ubuntu

In previous article of this Big-Data tutorials series we have seen, What is Apache Zookeeper, Why do we need it and How it works ?. In this particular article we will see how to download and install Zookeeper on Ubuntu. We will install Zookeepr on single node, here are steps you need to follow to start Zookeepr:

1) Download and install JDK, Java is required because Zookeeper server runs on Java. If not installed already go through the link Resources.

2) Download a stable version of Zookeeper from this link (Resource), and un-tar it to an appropriate location.
For simplicity lets create a directory zoo and than download and un-tar zookeepr package there like :

techie@techie-Satellite-L50-B:~$ mkdir /home/techie/zoo
techie@techie-Satellite-L50-B:~$ cd /home/techie/zoo
techie@techie-Satellite-L50-B:~/zoo$ wget
techie@techie-Satellite-L50-B:~/zoo$ tar xzvf zookeeper-3.4.6.tar.gz

3) Now create and configure a .cfg file in conf folder, there is a sample file zoo_sample.cfg lets copy the same file with zoo.conf name and use it as it is.

techie@techie-Satellite-L50-B:~/zoo$ cd zookeeper-3.4.6/conf/
techie@techie-Satellite-L50-B:~/zoo/zookeeper-3.4.6/conf$ ls
configuration.xsl zoo_sample.cfg

techie@techie-Satellite-L50-B:~/zoo/zookeeper-3.4.6/conf$ cp zoo_sample.cfg zoo.cfg

4) Now lets see our configuration file content and understand what is inside it:

techie@techie-Satellite-L50-B:~/zoo/zookeeper-3.4.6/conf$ vim zoo.cfg

# The number of milliseconds of each tick
# The number of ticks that the initial
# synchronization phase can take
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# the port at which the clients will connect
# the maximum number of client connections.
# increase this if you need to handle more clients
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
# The number of snapshots to retain in dataDir
# Purge task interval in hours
# Set to "0" to disable auto purge feature

The file is self explanatory, see the comments for more understanding, zookeeper will run on port 2181, thats default port.

5) Here we are done with configuration, lets start the server by supplieng folliwng command:

techie@techie-Satellite-L50-B:~/zoo/zookeeper-3.4.6$ bin/ start
JMX enabled by default
Using config: /home/techie/zoo/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

If everything goes right you will see, something listed above.

6) Now lets connect to Zookeeper server using Java, supply following command to connect:

techie@techie-Satellite-L50-B:~/zoo/zookeeper-3.4.6$ bin/ -server

Connecting to
2015-06-21 16:18:33,935 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2015-06-21 16:18:33,938 [myid:] - INFO [main:Environment@100] - Client
2015-06-21 16:18:33,938 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_80
2015-06-21 16:18:33,940 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2015-06-21 16:18:33,940 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-7-oracle/jre
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/home/techie/zoo/zookeeper-3.4.6/bin/../build/classes:/home/techie/zoo/zookeeper-3.4.6/bin/../buil
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.16.0-30-generic
2015-06-21 16:18:33,941 [myid:] - INFO [main:Environment@100] - Client
2015-06-21 16:18:33,942 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/techie
2015-06-21 16:18:33,942 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/techie/zoo/zookeeper-3.4.6
2015-06-21 16:18:33,943 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString= sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@194d62f1
Welcome to ZooKeeper!
2015-06-21 16:18:33,976 [myid:] - INFO [main-SendThread($SendThread@975] - Opening socket connection to server Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2015-06-21 16:18:33,991 [myid:] - INFO [main-SendThread($SendThread@852] - Socket connection established to, initiating session
[zk: 0] 2015-06-21 16:18:34,114 [myid:] - INFO [main-SendThread($SendThread@1235] - Session establishment complete on server, sessionid = 0x14e15b8ee090000, negotiated timeout = 30000


WatchedEvent state:SyncConnected type:None path:null

If everything goes right, you will see a screen showing some logs as listed above.

7) Now we can see content and folders at root by following cd command to root path like this:

[zk: 2] ls /

As we can see there is no znode created already, lets create a new one with name znode1

[zk: 11] create /znode1 data1
Created /znode1
[zk: 12]

Now lets see the created nodes by following command:

[zk: 12] ls /
[znode1, zookeeper, zk_test]

We have see a new node znode1 is create with data1, lets verify if the data is associated with this node:

[zk: 13] get /znode1
cZxid = 0x7
ctime = Sun Jun 21 16:30:45 IST 2015
mZxid = 0x7
mtime = Sun Jun 21 16:30:45 IST 2015
pZxid = 0x7
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0

Now lets delete one of the create znode from the server by following command:

[zk: 15] delete /znode1

Now if you will see present nodes by cd command, znode1 os gone from there:

[zk: 16] ls /
[zookeeper, zk_test]

That's it for now, we have seen how to download, install and deploy apache Zookeepr in Ubuntu, we also saw how to create a znode and associate data with it and how to delete a znode from the server. In upcoming articles we will see more about Apache Zoookeeepr and other open-source technologies.

About The Author

Nagesh Chauhan

Nagesh Chauhan has 8+ years of software design and development experience in variety of technologies like - Core Java, Java 8 (Streams, Lambda), J2EE (Servlet, JSP), Spring Framework (MVC, IOC, JDBC, SECURITY etc), Spring Boot and Microservices, Kafla, Redis, Cassandra and Spark.