Installation and Configuration of ZooKeeper High Availability Cluster

Installation and Configuration of ZooKeeper High Availability Cluster

Zookeeper is the registration and coordination center of many services (dubbo, jstom, etc.), so high-availability cluster solutions are also essential. When clustering Zookeeper, pay attention to the number of nodes in the ZK cluster to be an odd number (2n+1: such as 3, 5, 7 nodes) is more suitable.

Example project:  http://wosyingjun.iteye.com/blog/2312553

 

1. Download and upload zookeeper-3.4.6.tar.gz to the /usr/local/ directory of each server
$ cd /usr/local/
$ wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
2. Unzip the zookeeper installation package on each server, and rename the zookeeper directory according to the node number
$ tar -zxvf zookeeper-3.4.6.tar.gz
服务器 1:
$ mv zookeeper-3.4.6 zookeeper-3.4.6_(1)
服务器 2:
$ mv zookeeper-3.4.6 zookeeper-3.4.6_(2)
服务器 3:
$ mv zookeeper-3.4.6 zookeeper-3.4.6_(3)
3. Create the following directories under each zookeeper node directory:
$ cd /usr/local/zookeeper-3.4.6_(x)(x代表节点号)
$ mkdir data
$ mkdir logs
4. Copy the zoo_sample.cfg file in the zookeeper/zookeeper-3.4.6_(x)/conf directory and name it zoo.cfg:
$ cp zoo_sample.cfg zoo.cfg
5. Modify the zoo.cfg configuration file
#zookeeper-3.4.6_(1)的配置(/usr/local/zookeeper-3.4.6_(1)/conf/zoo.cfg)如下:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper-3.4.6_(1)/data
dataLogDir=/usr/local/zookeeper-3.4.6_(1)/logs
clientPort=2181
server.1=192.168.11.97:2881:3881
server.2=192.168.11.98:2882:3882
server.3=192.168.11.99:2883:3883

#zookeeper-3.4.6_(2)的配置(/usr/local/zookeeper-3.4.6_(2)/conf/zoo.cfg)如下:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper-3.4.6_(2)/data
dataLogDir=/usr/local/zookeeper-3.4.6_(2)/logs
clientPort=2182
server.1=192.168.11.97:2881:3881
server.2=192.168.11.98:2882:3882
server.3=192.168.11.99:2883:3883

#zookeeper-3.4.6_(3)的配置(/usr/local/zookeeper-3.4.6_(3)/conf/zoo.cfg)如下:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper-3.4.6_(3)/data
dataLogDir=/usr/local/zookeeper-3.4.6_(3)/logs
clientPort=2183
server.1=192.168.11.97:2881:3881
server.2=192.168.11.98:2882:3882
server.3=192.168.11.99:2883:3883

Parameter Description

tickTime=2000
tickTime is the time interval for maintaining heartbeats between Zookeeper servers or between clients and servers, that is, a heartbeat is sent every tickTime.

initLimit=10
This configuration item initLimit is used to configure Zookeeper to accept clients (the client mentioned here is not the client that the user connects to the Zookeeper server, but the Follower server connected to the Leader in the Zookeeper server cluster). How many heartbeat intervals to tolerate. When the Zookeeper server has not received the return information from the client after more than 10 heartbeats (that is, tickTime), it indicates that the client connection failed. The total time length is 10*2000=20 seconds.

syncLimit=5
syncLimit 这个配置项标识Leader与Follower之间发送消息,请求和应答时间长度,最长不能超过多少个tickTime的时间长度,总的时间长度就是5*2000=10秒。

dataDir=/usr/local/zookeeper-3.4.6_(x)/data
dataDir顾名思义就是Zookeeper保存数据的目录,默认情况下Zookeeper将写数据的日志文件也保存在这个目录里。

clientPort=2181
clientPort这个端口就是客户端(应用程序)连接Zookeeper服务器的端口,Zookeeper 会监听这个端 口接受客户端的访问请求。

server.A=B:C:D
server.1=192.168.11.97:2881:3881
server.2=192.168.11.98:2882:3882
server.3=192.168.11.99:2883:3883
A 是一个数字,表示这个是第几号服务器;
B 是这个服务器的IP地址(或者是与IP地址做了映射的主机名);
C 第一个端口用来集群成员的信息交换,表示这个服务器与集群中的 Leader 服务器交换信息的端口;
D 是在leader挂掉时专门用来进行选举 leader 所用的端口。

6、在dataDir=/usr/local/zookeeper-3.4.6_(x)/data下创建 myid 文件

$ vi /usr/local/zookeeper-3.4.6(1) /data/myid 设置值为1
$ vi /usr/local/zookeeper-3.4.6
(2) /data/myid 设置值为1
$ vi /usr/local/zookeeper-3.4.6_(3) /data/myid 设置值值为3

7、在防火墙中打开要用到的端口218X、288X、388X

$ vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 218X -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 288X -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 388X -j ACCEPT
$ service iptables restart

8、启动并查看zookeeper:

$ /usr/local/zookeeper-3.4.6(x)/bin/zkServer.sh start
$ /usr/local/zookeeper-3.4.6
(x)/bin/zkServer.sh status

9、连接zookeeper的客户端配置修改:

zookeeper://192.168.11.97:2181?backup=192.168.11.98:2182,192.168.11.99:2183

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326772001&siteId=291194637