zookeeper 集群安装

1、【下载】到官网下在安装包:http://zookeeper.apache.org/,如:zookeeper-3.4.10.tar.gz,下载后上传到linux系统

2、【解压】执行 #tar -zxvf  zookeeper-3.4.10.tar.gz -C [path]  

3、【修改配置】修改 zoo.cfg ,在zoo.cfg 的 dataDir 设置的目录中 新建myid文件,在myid文件中写入,在zoo.cfg 的 server.x=zk01:2888:3888 填写对应的 x;如在zk01机器上的myid文件 填1,在zk02机器上的myid文件 填2,具体看配置

[root@zk03 conf]# cat zoo.cfg
# 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=/export/servers/zookeeper-3.4.10/data #服务信息
dataLogDir=/export/servers/zookeeper-3.4.10/logs #数据log


# 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=zk01:2888:3888
server.2=zk02:2888:3888
server.3=zk03:2888:3888

 

4、【分发安装目录】 把配置好的安装目录scp到其他机器上,然后修改对应的myid的值

5、【启动服务】 在每台机器上都开启zk服务,执行 #./bin/zkServer start 注意:只开一条机器,集群是开不起来的,因为要过半的节点正常,集群才正常;本例有3个节点:

server.1=zk01:2888:3888

server.2=zk02:2888:3888

server.3=zk03:2888:3888

只开启一个节点,1/3,没有过半,所以集群不能正常运行,虽然jps,可以看到QuorumpeerMain进程,看日志,会看到链接其他两个节点,一直报错:拒绝连接

用 执行 #./bin/zkServer status 看节点状态,会提示:

ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

如果在开一个节点,等一会,就会正常了,因为2/3过半了,虽然第3个节点拒接节点;这就是HA(集群高可用)

此时,执行 #./bin/zkServer status ,会提示节点状态:Mode: leader或者Mode: follower,具体谁是leader,有选举算法,这个可以进一步了解

在此情况下,再开启第3个节点,前面2节点状态不变,3节点是Mode: follower

 

posted @ 2018-08-22 23:44  SeamanWang  阅读(153)  评论(0编辑  收藏  举报