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 http://zookeeper.apache.org/releases.html.

#wget http://mirror.symnds.com/software/Apache/zookeeper/stable/zookeeper-3.4.6.tar.gz
#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,

tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.0.1:2888:3888
server.2=192.168.0.2:2888:3888
server.3=192.168.0.3:2888:3888

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.

clientPort=2181
clientPort=2182
clientPort=2183

dataDir=/var/lib/zookeeper/1/
dataDir=/var/lib/zookeeper/2/
dataDir=/var/lib/zookeeper/3/

server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

#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/zkServer.sh start zoo1.cfg
bin/zkServer.sh start zoo2.cfg
bin/zkServer.sh start zoo3.cfg

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

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

Connect client,

/bin/zkCli.sh -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/zkServer.sh stop zoo1.cfg
bin/zkServer.sh stop zoo2.cfg
bin/zkServer.sh stop zoo3.cfg

Thanks you.

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

Leave a Reply