官方文档
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
注: 如果确保配置正确,启动第一台报错,坚持启动完三台就可以了。
本文详细介绍ZooKeeper集群的部署步骤,包括修改配置文件、创建myid文件及启动集群的方法。通过设置tickTime、initLimit等参数优化集群性能,确保各节点间的同步与通信。适用于分布式系统协调服务的搭建。
1008

被折叠的 条评论
为什么被折叠?



