【Zookeeper】Win平台伪集群搭建

 

下载稳定版Zookeeper

https://downloads.apache.org/zookeeper/stable/

GZ包:

apache-zookeeper-3.6.3-bin.tar.gz 

 

解压一份到本地磁盘中

1、将conf目录下的zoo_sample.cfg复制一份改名为zoo.cfg

2、更改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=D:\\develop\\ZookeeperCluster\\apache-zookeeper-3.5.9-2\\data
# the port at which the clients will connect
clientPort=2182
# 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:2184:3887
server.2 = 127.0.0.1:2185:3888
server.3 = 127.0.0.1:2186:3889

由于是在一台机器上部署三个Zookeeper实例,必然占用系统很多端口资源

每个实例的客户端口不能一致,服务端口和选举端口也不能一致

1个实例占用 3个端口 (客户端口 + 服务端口 + 选举端口)

 

然后把Zookeeper的目录复制2份出来,分别重命名以区分

apache-zookeeper-3.5.9-1
apache-zookeeper-3.5.9-2
apache-zookeeper-3.5.9-3

写入服务ID标识

ECHO 1 > %CD%\ZookeeperCluster\apache-zookeeper-3.5.9-1\data\myid
ECHO 2 > %CD%\ZookeeperCluster\apache-zookeeper-3.5.9-2\data\myid
ECHO 3 > %CD%\ZookeeperCluster\apache-zookeeper-3.5.9-3\data\myid

 

更改 apache-zookeeper-3.5.9-2 的zoo.cfg 客户端端口为 2182

更改 apache-zookeeper-3.5.9-3 的zoo.cfg 客户端端口为 2183

clientPort=2181
clientPort=2182
clientPort=2183

 

为了方便启动,可以编写集群启动脚本:

@ECHO OFF
start %CD%\apache-zookeeper-3.5.9-1\bin\zkServer.cmd
start %CD%\apache-zookeeper-3.5.9-2\bin\zkServer.cmd
start %CD%\apache-zookeeper-3.5.9-3\bin\zkServer.cmd

 

posted @ 2022-03-04 14:18  emdzz  阅读(48)  评论(0编辑  收藏  举报