Wednesday, March 30, 2016

Setup ZooKeeper cluster in CentOS VMs.

This post summarizes my experience on setting up a zookeeper cluster in CentOS VMs.

Before start, setup three VMs with the following hostname/ipaddress (Refer to this on how to set up and configure CentOS VMs using VirtualBox  http://czcodezone.blogspot.sg/2016/03/setup-centos-vm-in-virtualbox-for.html):

zoo01/192.168.56.91
zoo02/192.168.56.92
zoo03/192.168.56.93

1. Edit /etc/hosts

On each VM, edit /etc/hosts to add the following lines:

192.168.56.91 zoo01
192.168.56.92 zoo02
192.168.56.93 zoo03

2. Download and configure zookeeper

2.1 Download zookeeper


On each VM, download and unzip the zookeeper to the folder "/root/zookeeper".

2.2. Configure zookeeper


On each VM, run the following command to edit the /root/zookeeper/conf/zoo.cfg:

```bash
`cp zookeeper/conf/zoo_sample.cfg zookeeper/conf/zoo.cfg
`vi zookeeper/conf/zoo.cfg

In the zookeeper/conf/zoo.cfg, add the following configuration:

dataDir=/root/zookeeper_data

server.1=zoo01:2222:2223
server.2=zoo02:2222:2223
server.3=zoo03:2222:2223

Run the following comand to create the directory for holding the data storage for zookeeper in each VM (the /root/zookeeper_data/myid must have an unique id on each VM):

```bash
`ssh root@zoo01
`mkdir /root/zookeeper_data
`touch /root/zookeeper_data/myid
`echo 1 >> /root/zookeeper_data/myid
`ssh root@zoo02
`mkdir /root/zookeeper_data
`touch /root/zookeeper_data/myid
`echo 2 >> /root/zookeeper_data/myid
`ssh root@zoo03
`mkdir /root/zookeeper_data
`touch /root/zookeeper_data/myid
`echo 3 >> /root/zookeeper_data/myid

3. Start zookeeper cluster


To start the zookeeper cluster, on each VM zoo01/2/3, run the following command:

```bash
`zookeeper/bin/zkServer.sh start zookeeper/conf/zoo.cfg

(Note that for testing, you may want to use the command "start-foreground" instead of "start")

4. Test zookeeper running


To check whether the zookeeper cluster is running, run the following command:

```bash
`zookeeper/bin/zkServer.sh status

To testing the zookeeper cluster, run the following command:

```bash
`zookeeper/bin/zkCli.sh -server 192.168.56.91:2181,192.168.56.92:2181,192.168.56.93:2181




No comments:

Post a Comment