zookeeper集群配置

前言:zookeeper支持本机多个进程之间的集群,本文描述的是多个独立主机的分布式集群。

一、前提条件

至少需要3台独立主机(不管是虚拟机还是独立硬件)

因为zookeeper支持“大多数节点可用时的服务保障”,而1台和2台是无法满足“大多数节点可用”的条件的。

二、N(N>=3)台主机的配置

它们的配置文件是一样的,例如:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.25.128:2888:3888
server.2=192.168.25.129:2888:3888
server.3=192.168.25.130:2888:3888

三、不一样的配置

1. 步骤二中的server.1中1指的是zookeeper的编号,需要根据配置定义每台机器编号。

2. 编号配置文件名称为myid,路径为步骤二中的配置项dataDir=/tmp/zookeeper指示的路径。

配置实例,在IP地址为192.168.25.128的主机上执行如下命令:

 echo "1" >/tmp/zookeeper/myid

类似的配置其它主机。

四、启动服务

/usr/local/zookeeper-3.4.9/bin/zkServer.sh start

五、查看节点状态

./zkServer.sh status

能看到Mode: leader或者Mode: follower

顾名思义,就是主节点和从节点了。

做个测试,down掉主节点的机器,你会发现剩下的两个follower会有一个变成leader。

posted @ 2017-03-23 09:44  一沙世界  阅读(487)  评论(0编辑  收藏  举报