下载地址
http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/
先下载配置好jdk已经JAVA_HOME和path之类的
解压到各个目录
D:\server\server1\zookeeper-3.4.14
D:\server\server2\zookeeper-3.4.14
D:\server\server3\zookeeper-3.4.14
打开conf中的zoo_sample.cfg,修改后另存为zoo.cfg
修改配置
ClientPort=2181 ClientPort=2182 和ClientPort=2183
配置保存数据的目录和日志目录
dataDir=D:/server/server1/data
dataDir=D:/server/server2/data
dataDir=D:/server/server3/data
-
server1
* -
server2
-
server3
配置
# 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:/server/server3/data
# the port at which the clients will connect
clientPort=2183
# 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
然后在配置的保存数据目录,分别新建名为myid的txt文件,去掉扩展名
分别存入 1 2 3 后去掉后缀
2,3内容不一样
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