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 http://mirrors.advancedhosters.com/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
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 log4j.properties 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
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1


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/zkServer.sh 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/zkCli.sh -server 127.0.0.1:2181

Connecting to 127.0.0.1:2181
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 environment:host.name=techie-Satellite-L50-B
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
d/lib/*.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../lib/nett
y-3.7.0.Final.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../zookeeper-3.
4.6.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/home/techie/zoo/zookeeper-3.4.6/bin/../conf:
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 environment:java.io.tmpdir=/tmp
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 environment:os.name=Linux
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 environment:user.name=techie
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=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@194d62f1
Welcome to ZooKeeper!
2015-06-21 16:18:33,976 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2015-06-21 16:18:33,991 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
[zk: 127.0.0.1:2181(CONNECTING) 0] 2015-06-21 16:18:34,114 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x14e15b8ee090000, negotiated timeout = 30000

WATCHER::

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: 127.0.0.1:2181(CONNECTED) 2] ls /
[zookeeper]


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

[zk: 127.0.0.1:2181(CONNECTED) 11] create /znode1 data1
Created /znode1
[zk: 127.0.0.1:2181(CONNECTED) 12]


Now lets see the created nodes by following command:

[zk: 127.0.0.1:2181(CONNECTED) 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: 127.0.0.1:2181(CONNECTED) 13] get /znode1
data1
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: 127.0.0.1:2181(CONNECTED) 15] delete /znode1


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

[zk: 127.0.0.1:2181(CONNECTED) 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.
  • By Techburps.com
  • Jun 21, 2015
  • Big Data