Zookeeper Installation Guide for CentOS

1. Download the latest installation package:
cd /home
wget http://mirror.cnop.net/apache/zookeeper/zookeeper-3.4.10.tar.gz
tar zxvf zookeeper-3.4.10.tar.gz  && mv zookeeper-3.4.10 zookeeper && cd zookeeper/conf && cp zoo_sample.cfg zoo.cfg

2. Configure Firewall
CentOS 6.x :
/sbin/iptables -I INPUT -p tcp –dport 2181 -j ACCEPT  && /sbin/iptables -I INPUT -p tcp –dport 2888 -j ACCEPT  && /sbin/iptables -I INPUT -p tcp –dport 3888 -j ACCEPT
/etc/rc.d/init.d/iptables save
service iptables restart

CentOS 7 :

firewall-cmd –zone=public –add-port=2181/tcp –permanent  && firewall-cmd –zone=public –add-port=2888/tcp –permanent && firewall-cmd –zone=public –add-port=3888/tcp –permanent

systemctl restart firewalld.service

Standalone Mode Configuration:
vi  zoo.cfg

tickTime=2000        # The unit of time is milliseconds, which is the basic time unit used by ZK. The default value of tickTime is 2000 milliseconds. A lower tickTime value can detect timeout issues faster, but it also leads to higher network traffic (heartbeat messages) and higher CPU usage.
dataDir=/tmp/zookeeper   # Must be configured, used to specify the directory for storing snapshot files. If dataLogDir is not configured, transaction logs will also be stored in this directory.
clientPort=2181
initLimit=5
syncLimit=2

Startup:

/home/zookeeper/bin/zkServer.sh start
/home/zookeeper/bin/zkServer.sh status

To connect to Zookeeper from a Linux client, use the following command. If you want to connect to a specific IP, enter:
/home/zookeeper/bin/zkCli.sh -server 192.168.0.1:2181
The TCP port the server process listens on; by default, the server listens on port 2181.

Cluster Mode

In cluster mode, all ZK processes can use the same configuration file (meaning each ZK process is deployed on a different machine). For example, the configuration is as follows:
vi  zoo.cfg

tickTime=2000
dataDir=/tmp/zookeeper 
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.1.100:2888:3888
server.2=192.168.1.101:2888:3888
server.3=192.168.1.102:2888:3888

The following operations should be completed on three different hosts, with server.【id】 being the id to print (please refer to the IDs above):
192.168.1.100           mkdir /tmp/zookeeper && echo "1"> /tmp/zookeeper/myid
192.168.1.102           mkdir /tmp/zookeeper && echo "2"> /tmp/zookeeper/myid
192.168.1.103           mkdir /tmp/zookeeper && echo "3"> /tmp/zookeeper/myid

Startup:

/home/zookeeper/bin/zkServer.sh start    # Sometimes there may be a few seconds delay before it starts
/home/zookeeper/bin/zkServer.sh status  # Under normal circumstances, one will be the leader and the other two will be followers

Auto-start on Boot (CentOS 6.x):
vi /etc/rc.local  # Add the following

su – jjzb -c "/home/zookeeper/bin/zkServer.sh start"

reboot

Logs:
The default startup directory contains zookeeper.out

Leave a Comment

Your email address will not be published.