Apache ZooKeeper 3.4.6 Multi Server setup on Ubuntu 14.04

posted on Nov 20th, 2016

Apache ZooKeeper

Apache ZooKeeper is a software project of the Apache Software Foundation. It is essentially a distributed hierarchical key-value store, which is used to provide a distributed configuration service, synchronization service, and naming registry for large distributed systems. ZooKeeper was a sub-project of Hadoop but is now a top-level project in its own right.

ZooKeeper's architecture supports high availability through redundant services. The clients can thus ask another ZooKeeper leader if the first fails to answer. 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.

Pre Requirements

1) 3 machines with Ubuntu 14.04 LTS operating system installed.

2) Apache Hadoop 2.6.4 pre installed (How to install Hadoop on Ubuntu 14.04)

3) Apache ZooKeeper 3.4.6 software (Download Here)

Apache ZooKeeper 3.4.6 Multi Server setup on Ubuntu

Installation Steps

On All machines - (zoo1, zoo2, zoo3)

Step 1 - Update. Open a terminal (CTRL + ALT + T) and type the following sudo command. It is advisable to run this before installing any package, and necessary to run it to install the latest updates, even if you have not added or removed any Software Sources.

$ sudo apt-get update

Step 2 - Installing Java 7.

$ sudo apt-get install openjdk-7-jdk

Step 3 - Edit $HOME/.bashrc file by adding the java path.

$ sudo gedit $HOME/.bashrc

$HOME/.bashrc file. Add the following lines

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

Step 4 - Reload your changed $HOME/.bashrc settings

$ source $HOME/.bashrc

Step 5 - Edit /etc/hosts file.

$ sudo gedit /etc/hosts

/etc/hosts file. Add all machines IP address and hostname. Save and close.

192.168.2.14	zoo1
192.168.2.15	zoo2
192.168.2.16	zoo3

Step 6 - Creating zookeeper directory.

$ sudo mkdir /usr/local/zookeeper

Step 7 - Change the ownership and permissions of the directory /usr/local/zookeeper. Here 'hduser' is an Ubuntu username.

$ sudo chown -R hduser /usr/local/zookeeper
$ sudo chmod -R 755 /usr/local/zookeeper

Step 8 - Creating /zookeeper/data directory.

$ sudo mkdir /usr/local/zookeeper/data

Step 9 - Change the ownership and permissions of the directory /usr/local/zookeeper/data. Here 'hduser' is an Ubuntu username.

$ sudo chown -R hduser /usr/local/zookeeper/data
$ sudo chmod -R 755 /usr/local/zookeeper/data

Step 10 - Creating /zookeeper/log directory.

$ sudo mkdir /usr/local/zookeeper/log

Step 11 - Change the ownership and permissions of the directory /usr/local/zookeeper/log. Here 'hduser' is an Ubuntu username.

$ sudo chown -R hduser /usr/local/zookeeper/log
$ sudo chmod -R 755 /usr/local/zookeeper/log

Only on zoo1

Step 12 - Change the directory to /home/hduser/Desktop , In my case the downloaded zookeeper-3.4.6.tar.gz file is in /home/hduser/Desktop folder. For you it might be in /downloads folder check it.

$ cd /home/hduser/Desktop/

Step 13 - Untar the zookeeper-3.4.6.tar.gz file.

$ tar xzf zookeeper-3.4.6.tar.gz

Step 14 - Move the contents of zookeeper-3.4.6 folder to /usr/local/zookeeper

$ mv zookeeper-3.4.6/* /usr/local/zookeeper

Step 15 - Change the directory to /usr/local/zookeeper/conf

$ cd /usr/local/zookeeper/conf

Step 16 - Edit zoo.cfg file. If this file doesn't exists it will create one for you and it ll open for you to edit.

$ gedit zoo.cfg

Step 17 - Add following lines to zoo.cfg file. Save and close.

tickTime=2000
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log 
clientPort=2181
initLimit=10
syncLimit=2
server.1=192.168.2.14:2888:3888
server.2=192.168.2.15:2888:3888
server.3=192.168.2.16:2888:3888 

Step 18 - Change the directory to /usr/local/zookeeper/data

cd /usr/local/zookeeper/data

Step 19 - Edit mypid file. If this file doesn't exists it will create one for you and it ll open for you to edit.

$ gedit mypid

Step 20 - Add following lines to mypid file. Save and close.

1

Only on zoo2

Step 21 - Change the directory to /home/hduser/Desktop , In my case the downloaded zookeeper-3.4.6.tar.gz file is in /home/hduser/Desktop folder. For you it might be in /downloads folder check it.

$ cd /home/hduser/Desktop/

Step 22 - Untar the zookeeper-3.4.6.tar.gz file.

$ tar xzf zookeeper-3.4.6.tar.gz

Step 23 - Move the contents of zookeeper-3.4.6 folder to /usr/local/zookeeper

$ mv zookeeper-3.4.6/* /usr/local/zookeeper

Step 24 - Change the directory to /usr/local/zookeeper/conf

$ cd /usr/local/zookeeper/conf

Step 25 - Edit zoo.cfg file. If this file doesn't exists it will create one for you and it ll open for you to edit.

$ gedit zoo.cfg

Step 26 - Add following lines to zoo.cfg file. Save and close.

tickTime=2000
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log 
clientPort=2181
initLimit=10
syncLimit=2
server.1=192.168.2.14:2888:3888
server.2=192.168.2.15:2888:3888
server.3=192.168.2.16:2888:3888 

Step 27 - Change the directory to /usr/local/zookeeper/data

cd /usr/local/zookeeper/data

Step 28 - Edit mypid file. If this file doesn't exists it will create one for you and it ll open for you to edit.

$ gedit mypid

Step 29 - Add following lines to mypid file. Save and close.

2

Only on zoo3

Step 30 - Change the directory to /home/hduser/Desktop , In my case the downloaded zookeeper-3.4.6.tar.gz file is in /home/hduser/Desktop folder. For you it might be in /downloads folder check it.

$ cd /home/hduser/Desktop/

Step 31 - Untar the zookeeper-3.4.6.tar.gz file.

$ tar xzf zookeeper-3.4.6.tar.gz

Step 32 - Move the contents of zookeeper-3.4.6 folder to /usr/local/zookeeper

$ mv zookeeper-3.4.6/* /usr/local/zookeeper

Step 33 - Change the directory to /usr/local/zookeeper/conf

$ cd /usr/local/zookeeper/conf

Step 34 - Edit zoo.cfg file. If this file doesn't exists it will create one for you and it ll open for you to edit.

$ gedit zoo.cfg

Step 35 - Add following lines to zoo.cfg file. Save and close.

tickTime=2000
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log 
clientPort=2181
initLimit=10
syncLimit=2
server.1=192.168.2.14:2888:3888
server.2=192.168.2.15:2888:3888
server.3=192.168.2.16:2888:3888 

Step 36 - Change the directory to /usr/local/zookeeper/data

cd /usr/local/zookeeper/data

Step 37 - Edit mypid file. If this file doesn't exists it will create one for you and it ll open for you to edit.

$ gedit mypid

Step 38 - Add following lines to mypid file. Save and close.

3

On All machines - (zoo1, zoo2, zoo3)

Step 1 - Change the directory to /usr/local/zookeeper/bin

$ cd /usr/local/zookeeper/bin

Step 2 - Start zookeeper server

$ ./zkServer.sh start

Step 3 - Stop zookeeper server

$ ./zkServer.sh stop

Please share this blog post and follow me for latest updates on

facebook             google+             twitter             feedburner

Previous Post                                                                                          Next Post

Labels : ZooKeeper Single Server Setup   ZooKeeper Command Line Interface(CLI) usage   ZooKeeper Java API Usage