zookeeper集群搭建

本文介绍如何配置ZooKeeper集群环境,包括创建配置文件、设置myid文件及启动ZooKeeper等步骤。详细解释了配置参数的意义,如dataDir、clientPort等。

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

zookeeper集群环境有集群环境、单机环境、伪集群三种情况。
1:创建配置文件。进入conf目录,运行命令:

cp zoo_sample.cfg zoo.cfg

zoo_sample.cfg是一个配置样例文件。修改其配置文件如下:

  1 # The number of milliseconds of each tick                                                                                       
  2 tickTime=2000
  3 # The number of ticks that the initial 
  4 # synchronization phase can take
  5 initLimit=10
  6 # The number of ticks that can pass between 
  7 # sending a request and getting an acknowledgement
  8 syncLimit=5
  9 # the directory where the snapshot is stored.
 10 # do not use /tmp for storage, /tmp here is just 
 11 # example sakes.
 12 dataDir=/opt/zookeeper/2181
 13 # the port at which the clients will connect
 14 clientPort=2181
 15 # the maximum number of client connections.
 16 # increase this if you need to handle more clients
 17 #maxClientCnxns=60
 18 #
 19 # Be sure to read the maintenance section of the 
 20 # administrator guide before turning on autopurge.
 21 #
 22 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
 23 #
 24 # The number of snapshots to retain in dataDir
 25 #autopurge.snapRetainCount=3
 26 # Purge task interval in hours
 27 # Set to "0" to disable auto purge feature
 28 #autopurge.purgeInterval=1
 29 
 30 server.1=10.66.140.32:2888:3888
 31 server.2=10.66.131.57:2888:3888
 32 server.3=10.66.140.32:2889:3889

配置说明:
dataDir:为zookeeper运行时数据的快照文件。
clientPort:为客户端连接端口。
server.id=host.port.port:集群节点配置。
id:为集群节点的标识。一般为整数。其他的没试过~
host:为集群节点的ip。
第一个port:follower服务器和leader服务器通信的端口。
第二个port:用于leader选举过程中的投票通信。(具体内容后续更新)


2:进入上述配置文件dataDir配置的目录中创建文件myid,并将内容设置为上述server中的id。
配置例子如下:
这里写图片描述

3:进入bin目录下启动zk。

./zkServer.sh start

4:测试启动是否正常
运行命令:telnet ip port之后输入netstat检查情况。
这里写图片描述
出现该情况原因是在集群环境下,如果只有1台服务器在运行时,zk是不对外提供的。
启动其他机器节点后,再运行该命令就可以看到各个节点自己的情况。
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值