zookeeper集群搭建

本文详细介绍如何快速搭建ZooKeeper集群,包括安装配置、集群节点设置及启动步骤。通过具体实例,帮助读者掌握ZooKeeper集群部署流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近比较有空,赶紧挤出时间来总结前段时间的知识。

zookeeper的集群搭建非常快捷方便,下面简单说一下。

1.安装zookeeper,去官网下载压缩包解压到一个路径下
首先到解压目录下进入conf目录,执行命令cp zoo_sample.cfg zoo.cfg,复制一份配置文件,zookeeper运行期间读取的配置文件就是zoo.cfg

2.配置集群节点机器的serverid,看到我们zoo.cfg中默认配置dataDir的路径是/tmp/zookeeper,这个路径最好修改一下,因为服务器会定时清理这个tmp文件夹,我们先把dataDir修改为自定义的/usr/local/apps/zookeeper,没有的话就自己创建文件夹,然后进入/usr/local/apps/zookeeper文件夹创建一个myid文件,内容就是我们的serverid,这是我的定义
1-》192.168.0.15
2-》192.168.0.14
3-》192.168.0.13
192.168.0.15 的myid内容

1

其他的机器的同样地方也需要设置myid

3.进入 zookeeper解压路径的配置文件夹下面,设置集群机器配置,同样也是编辑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/apps/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.0.15:2888:3888
server.2=192.168.0.14:2888:3888
server.3=192.168.0.13:2888:3888

最下面的配置就是集群配置,
server.s=192.168.0.13:ssss:llll
上面的s表示就是机器ip对应的myid,ssss表示zookeeper集群内部数据同步时使用的端口可以自定义,llll表示集群内部选举时通信使用的端口,可以自定义。

4.每台机器都设置好后就,就可以启动集群,在bin目录下 ./zkServer.sh start
leader节点
这里写图片描述
follower节点
这里写图片描述

尝试对192.168.0.15进行数据插入,创建一个testNode
这里写图片描述

在192.168.0.13可以查询到同样数据
这里写图片描述

以上就是快速搭建一个zookeeper集群方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值