ZooKeeper集群搭建教程

前言

如果对英文比较熟悉,建议直接看zookeeper官网

本文以zookeeper-3.4.14为例来分享一下zookeeper集群的安装部署。实验环境使用三个节点

node01.aries.com
node02.aries.com
node03.aries.com

关于如何设置hostname可以参考CentOS6修改hostname及hosts映射,这里不做赘述。

下载安装

# 下载zookeeper
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
# 解压
tar -zxvf ./zookeeper-3.4.14.tar.gz -C /usr/local

配置修改

下载的zookeeper包内一般没有默认的zoo.cfg配置文件,但是提供了示例配置文件zoo_sample.cfg。
我们可以以此为模板来进行修改,建议采取拷贝的方式,避免直接覆盖。

cp ./conf/zoo_sample.cfg ./conf/zoo.cfg

拷贝后通过vim ./conf/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=/usr/local/zookeeper-3.4.14/data
# 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=node01.aries.com:2888:3888
server.2=node02.aries.com:2888:3888
server.3=node03.aries.com:2888:3888

注意事项

  • dataDir配置的目录请提前创建好
  • 配置文件最后server.x=node**.aries.com:2888:3888x必须为数字,后文会详细介绍

内容分发

接下来将配置好的部署包分发到其他节点。

scp -p -r zookeeper-3.4.14 root@node02.aries.com:/usr/local
scp -p -r zookeeper-3.4.14 root@node03.aries.com:/usr/local

其他配置

之前提到配置文件中配置server.x=node**:2888:3888x必须为数字,其实x是这个节点的唯一数字标识,我们需要在每个节点配置的dataDir目录下,创建一个名为myid的文件,其内容为该节点的唯一数字标识。例如上述示例配置中node02的标识为2。

服务启动

完成上述配置后,我们就可以启动服务了,在每个节点执行启动命令,即可完成服务启动。
常用命令如下:

# 启动命令
./bin/zkServer.sh start
# 停止命令
./bin/zkServer.sh stop  
# 重启命令
./bin/zkServer.sh restart
# 状态查看命令
./bin/zkServer.sh status

服务验证

每个节点执行上文状态查看命令,可以看到其中一个节点为leader,其余节点为follower。

转载请注明出处,如有错误的地方请留言给我更正,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值