11 Şubat 2015 Çarşamba

Install and Run Zookeeper in Replicated Mode

I will explain the steps for installing Zookeeper and running in standalone and replicated mode.

It is tested with Zookeeper 3.4.6 on Ubuntu 12.04.

1. Prerequisites 

i. Java 1.6 or greater is needed to run Zookeeper. I will continue with Java 1.7
> apt-get install openjdk-7-jdk

ii. I will use supervisord to control Zookeeper
> apt-get install supervisor

2. Install Zookeeper

Get a Zookeeper binary. I will use http://ftp.itu.edu.tr/Mirror/Apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

> cd /usr/local
> wget http://ftp.itu.edu.tr/Mirror/Apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
> tar -xzvf zookeeper-3.4.6.tar.gz
> ln -s zookeeper-3.4.6 zookeeper

Create data and log directories for Zookeeper
> mkdir /var/zookeeper
> mkdir /var/zookeeper-log
> mkdir /var/log/zookeeper

Enter into /usr/local/zookeeper/conf directory
> cd /usr/local/zookeeper/conf
> vi zoo.cfg

Enter following configuration properties:
tickTime=2000
dataDir=/var/zookeeper
dataLogDir=/var/zookeeper-log
clientPort=2181
autopurge.purgeInterval=24
autopurge.snapRetainCount=5

Save and exit.
Following are explanations for these parameters, excerpt from Zookeeper documentation:

tickTime
the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.

dataDir
the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.

dataLogDir
the location to store the transaction log of updates to the database.

clientPort
the port to listen for client connections

3. Run In Standalone Mode

Lets run Zookeeper:
> cd /usr/local/zookeeper/bin
> ./zkServer.sh start

This will start Zookeeper and will fork into background. You can start in the foreground:
> ./zkServer.sh start-foreground

You can stop Zookeeper with:
> ./zkServer.sh stop

4. Run with Supervisord

Edit supervisord config
> vi /etc/supervisor/supervisord.conf

Enter following entry to the end of the file.

[program:zookeeper]
command=/usr/local/zookeeper/bin/zkServer.sh start-foreground
user=root
autostart=true
autorestart=true
startsecs=10
startretries=999
log_stdout=true
log_stderr=true
logfile=/var/log/zookeeper/zookeeper.out
logfile_maxbytes=20MB
logfile_backups=10

Enter into supervisord console
> sudo supervisorctl

You can monitor and start/stop Zookeeper from supervisor console
supervisor > status zookeeper
supervisor > start zookeeper
supervisor > stop zookeeper
supervisor > tail zookeeper

5. Run in Replicated Mode

In order to run Zookeeper in replicated mode, we will install Zookeeper to 3 machines. It is the least number recommended for production deployments. It is wise to install odd numbers of servers greater or equal to 3. Zookeeper needs more than half of the ensemble (Zookeeper cluster) up and running to be operational.

In each server, apply following:
Edit zoo.cfg
> cd /usr/local/zookeeper/conf
> vi zoo.cfg

initLimit=10
syncLimit=5
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888

Enter into data directory and create a file named myid:
> cd /var/zookeeper
> vi myid
Enter 1 for zoo1 server stating server id.
Enter 2 for zoo2 server stating server id.
Enter 3 for zoo3 server stating server id.


Following are explanations for these parameters, excerpt from Zookeeper documentation

The new entry, initLimit is timeouts ZooKeeper uses to limit the length of time the ZooKeeper servers in quorum have to connect to a leader. The entry syncLimit limits how far out of date a server can be from a leader.

With both of these timeouts, you specify the unit of time using tickTime. In this example, the timeout for initLimit is 10 ticks at 2000 milleseconds a tick, or 20 seconds.

The entries of the form server.X list the servers that make up the ZooKeeper service. When the server starts up, it knows which server it is by looking for the file myid in the data directory. That file has the contains the server number, in ASCII.

Finally, note the two port numbers after each server name: " 2888" and "3888". Peers use the former port to connect to other peers. Such a connection is necessary so that peers can communicate, for example, to agree upon the order of updates. More specifically, a ZooKeeper server uses this port to connect followers to the leader. When a new leader arises, a follower opens a TCP connection to the leader using this port. Because the default leader election also uses TCP, we currently require another port for leader election. This is the second port in the server entry.



Hiç yorum yok:

Yorum Gönder