Thursday, November 20, 2014

Setup ZooKeeper in a cluster

To setup ZooKeeper in a cluster, suppose we have the following computers interconnected (via a switch, e.g.) with the following ip address:

Lets assign a unique ID to each computer (ID taken from 1 to 255), said, we assign with id = 1, and assign with id = 2. 

Firstly lets setup the Zookeeper on each machine. This can be done by following instructions in 

Once the zookeeper is setup, log into the terminal of each computer, create a "zookeeper" folder under /var directory and create a myid file in it to contains the unique id assigned to the computer, by running the following commands:

> cd /var
> sudo mkdir zookeeper
> sudo chmod -R 777 zookeeper
> cd zookeeper
> sudo touch myid
> sudo gedit myid

In the myid opened, put the unique id and save the file. For example the content of myid file on is


and the content of myid file on is 


Now navigate to the ZK_HOME directory on each computer and update the zoo.cfg in the conf sub-directory, by running the following commnads:
> cd $ZK_HOME
> cd conf
> gedit zoo.cfg

In the zoo.cfg file, write the following as its content:


Save and close the zoo.cfg file. Run start the zookeeper on each computer by running the following commands in their terminal:

> cd $ZK_HOME
> bin/ start

To check the status of the zookeeper cluster, type the following command in each computers' terminal:
> cd $ZK_HOME
> bin/ status

To stop a zookeeper on a computer, run the following command:
> cd $ZK_HOME
> bin/ stop

Common problems encountered will cause the status command to display the following messages:

Error contacting service. It is probably not running.

When this message appeared, it may be because one of the computer is not connected to the network (e.g. the ethernet cable is loose). In this case, try to ping each computer to see if they are connected.

Another caution is to make sure the the /var/zookeeper folder on each computer has write permission (e.g. by running the "sudo chmod -R 777 /var/zookeeper" command in the terminal)

No comments:

Post a Comment