Zookeeper单机下的集群配置(windows版)

1. 下载zookeeper。如果是跟kafka一起用的话,要注意两者的版本对应情况,否则会出现各种各样奇怪的问题, 具体对应情况如下:

我这里下载的是3.4.10,为了跟kafka_2.12对应:

http://archive.apache.org/dist/zookeeper/zookeeper-3.4.10/

2. 解压,并配置cfg文件。解压到文件夹后,从zoo_sample.cfg复制三份,分别命名为zoo-1.cfg、zoo-2.cfg、zoo-3.cfg,区别仅在于dataDir和clientPort,dir分别为zoo-1、zoo-2、zoo-3,而port分别为2181、2182、2183,zoo-1.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=D:\\zk_tmp\\zoo-1
dataLogDir=D:\\zk_tmp\\log
# 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=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890

注:dataDir的路径这里,一定要注意路径的写法!!反斜杠的一定是双反斜杠!!血的教训!

  • tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
  • initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 10*2000=20 秒
  • syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 5*2000=10秒
  • dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
  • clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
  • server.A=B:C:D,其中:
    • A 是一个数字,表示这个是第几号服务器;
    • B 是这个服务器的 ip 地址;
    • C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;
    • D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

3. 为dataDir和dataLogDir建立文件夹,在D:/zk_tmp/下,分别建立子文件夹zoo-1、zoo-2、zoo-3和log。

    在zoo-1下建立myid文件,里面写入1,其他-2、-3文件夹同理,内容分别为2和3:

4. 配置cmd文件。windows下如果不改cmd文件,指定zoo-1.cfg文件并没有用。因为zkServer.cmd默认去调的zkEnv.cmd的配置信息,而zkEnv.cmd里是指定了cfg文件为zoo.cfg:

所以在运行的时候会直接去找zoo.cfg,找不到就会报错。

因此,我们可以直接改zkEnv.cmd文件,将zkEnv文件里的cfg文件改成真正存在的zoo-1.cfg文件,同时也要修改zkServer.cmd文件,把里面取zkEnv.cmd文件的地方一起改了,具体如下:

对应的zkServer.cmd也作相应的调整:

5. 启动zookeeper,就成功了(^-^)V:

6. 用netstat查看一下服务监听情况,有在监听端口,证明启动成功了。

后面会研究一下zookeeper的原理和机制,看看背后有什么值得借鉴的设计思想,哈哈哈

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值