Setup ZooKeeper Ensemble on Ubuntu

Setup ZooKeeper Ensemble on Ubuntu:

Download Apache ZooKeeper:

The first step in setting up Apache ZooKeeper is, of course, to download the software. It’s available from

#tar -xvf zookeeper-3.4.6.tar.gz

Configure the instance:
Lets create one in conf/zoo1.cfg:

#sudo mkdir -p /usr/lib/zookeeper-3.4.6
#sudo mv zookeeper-3.4.6/* /usr/lib/zookeeper-3.4.6/
#cd /usr/lib/zookeeper-3.4.6/
#cp conf/zoo_sample.cfg conf/zoo1.cfg
#vim conf/zoo1.cfg

Add following settings,


The parameters are as follows:
tickTime: Part of what ZooKeeper does is to determine which servers are up and running at any given time, and the minimum session time out is defined as two “ticks”. The tickTime parameter specifies, in miliseconds, how long each tick should be.
dataDir: This is the directory in which ZooKeeper will store data about the cluster. This directory should start out empty.
clientPort: This is the port on which Solr will access ZooKeeper.
initLimit: Amount of time, in ticks, to allow followers to connect and sync to a leader. In this case, you have 5 ticks, each of which is 2000 milliseconds long, so the server will wait as long as 10 seconds to connect and sync with the leader.
syncLimit: Amount of time, in ticks, to allow followers to sync with ZooKeeper. If followers fall too far behind a leader, they will be dropped.
server.X: These are the IDs and locations of all servers in the ensemble, the ports on which they communicate with each other. The server ID must additionally stored in the /myid file and be located in the dataDir of each ZooKeeper instance. The ID identifies each server, so in the case of this first instance, you would create the file /var/lib/zookeeper/1/myid with the content “1″.

Once this file is in place, you’re ready to start the ZooKeeper instance.

Then create /var/lib/zookeeper directory And create myid file, so each node can identify itself:

#sudo mkdir -p /var/lib/zookeeper
#echo "1" > /var/lib/zookeeper/myid

Where “1″ is the node number (so put “2″ for the next node and so on)
Do same for all nodes.

Standalone Setup:

You can also setup multiple instances on localhost. You just need to create separate data directory per instance for storing id and data and make all instances listen on different ports.




#echo "1" > /var/lib/zookeeper/1/myid
#echo "2" > /var/lib/zookeeper/2/myid
#echo "3" > /var/lib/zookeeper/3/myid

Once you have each node set up, you can start ZooKeeper by issuing on each node:

bin/ start zoo1.cfg
bin/ start zoo2.cfg
bin/ start zoo3.cfg

Check servers are running,
$bin/ status zoo1.cfg
$bin/ status zoo2.cfg
$bin/ status zoo3.cfg

$echo status | nc localhost 2181
$echo status | nc localhost 2182
$echo status | nc localhost 2183

Connect client,

/bin/ -server localhost:2181
[zk: localhost:2181(CONNECTED) 1] ls /
[zk: localhost:2181(CONNECTED) 2] ls /configs/
[zk: localhost:2181(CONNECTED) 3] ls /collections/
[zk: localhost:2181(CONNECTED) 4] get /configs/gettingstarted/solrconfig.xml
[zk: localhost:2181(CONNECTED) 5] quit

Stop them,

bin/ stop zoo1.cfg
bin/ stop zoo2.cfg
bin/ stop zoo3.cfg

Thanks you.

This entry was posted in Zookeeper and tagged . Bookmark the permalink.

Leave a Reply