先下载配置好jdk已经JAVA_HOME和path
下载解压ZooKeeper后,复制粘贴在多个路径中,比如:
server1/zookeeper-3.4.12
server2/zookeeper-3.4.12
server3/zookeeper-3.4.12
打开conf中的zoo_sample.cfg,修改后另存为zoo.cfg
因为是一台机器模拟的伪集群,三个服务端的ClientPort不能相同,我这里是
ClientPort=2181 ClientPort=2182 和ClientPort=2183
配置三个服务端,server.id(数字)=ip:集群交互端口:选举leader端口
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
配置保存数据的目录和日志目录,eg:
dataDir=F:/server1/zookeeper-3.4.12/dataTmp
dataDir=F:/server2/zookeeper-3.4.12/dataTmp
dataDir=F:/server3/zookeeper-3.4.12/dataTmp
dataLogDir=\log
然后在配置的保存数据目录,分别新建名为myid的txt文件
分别存入 1 2 3 后去掉后缀(若不存,server启动后会不知自己的id而报错)
cmd进入各自解压路径的bin目录,启动zkServer.cmd
配置的server没有全部启动时,由于leader选举机制,窗口会不断报错不必理会。
最后三台启动成功,leader选举完成。jps能看到三个QuorumPeerMain进程
可以通过 netstat -ano 命令查看是否有你配置的 clientPort 端口号在监听服务。
以下为zoo.cfg加注释配置:
# The number of milliseconds of each tick
#心跳时间间隔
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
#follower与leader之间建立连接后进行同步的最长时间
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
#配置follower和leader之间发送消息,请求和应答的最大时间长度
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#保存数据目录,若不单独配置日志路径,默认包含日志
dataDir=F:/server1/zookeeper-3.4.12/dataTmp
#配置日志目录
dataLogDir=\log
# the port at which the clients will connect
#客户端连接服务器的端口,zookeeper会监听并接受访问请求
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.id(数字)=ip:集群交互端口:选举leader端口
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389