0020-zookeeper集群搭建

本文详细介绍ZooKeeper集群的部署步骤,包括修改配置文件、创建myid文件及启动集群的方法。通过设置tickTime、initLimit等参数优化集群性能,确保各节点间的同步与通信。适用于分布式系统协调服务的搭建。

官方文档

官方文档

1. 修改配置文件

# 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=/home/rongyao/install/zookeeper-3.4.5/data
# the port at which the clients will connect
clientPort=2181
#
# 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=ubuntu0010:2888:3888
server.2=ubuntu0020:2888:3888
server.3=ubuntu0030:2888:3888

解释说明:server.1=ubuntu0010:2888:3888 第一个端口号2888是leader和follower交换信息用的;3888是用来选取leader用的。

2. 新建myid文件

The entries of the form server.X list the servers that make up the ZooKeeper service. When the server starts up, it knows which server it is by looking for the file myid in the data directory. That file has the contains the server number, in ASCII.

zookeeper服务器在启动的时候通过data文件夹下myid文件来识别当前是哪台机子。
所以创建myid。

echo server.X(具体的id) > data/myid

3. 启动集群

# 启动
bin/zkServer.sh start

# 查看启动日志
tail -fn 100 zookeeper.out

# 查看状态
bin/zkServer.sh status

注: 如果确保配置正确,启动第一台报错,坚持启动完三台就可以了。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值