1 环境 win7-64位环境 zookeeper-3.4.11
zk002当选为leader
2 将 zookeeper-3.4.11拷贝三份放置目录结构如下
D:\Program Files\zookeeper\zookeeper-cluster\zk001\zookeeper-3.4.11
D:\Program Files\zookeeper\zookeeper-cluster\zk002\zookeeper-3.4.11
D:\Program Files\zookeeper\zookeeper-cluster\zk003\zookeeper-3.4.11
3 配置服务zk001 的配置文件
配置文件目录:D:\Program Files\zookeeper\zookeeper-cluster\zk001\zookeeper-3.4.11\conf
将zoo_sample.cfg拷贝一份zoo.cfg
zoo.cfg内容如下:
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:/Program Files/zookeeper/zookeeper-cluster/zk001/zookeeper-3.4.11/data
dataLogDir=D:/Program Files/zookeeper/zookeeper-cluster/zk001/zookeeper-3.4.11/logs
# the port at which the clients will connect
clientPort=2181
server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
4 配置服务zk002 的配置文件
参考步骤3
# 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:/Program Files/zookeeper/zookeeper-cluster/zk002/zookeeper-3.4.11/data
dataLogDir=D:/Program Files/zookeeper/zookeeper-cluster/zk002/zookeeper-3.4.11/logs
# the port at which the clients will connect
clientPort=2182
server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
5 配置服务zk003 的配置文件
参考步骤3
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:/Program Files/zookeeper/zookeeper-cluster/zk003/zookeeper-3.4.11/data
dataLogDir=D:/Program Files/zookeeper/zookeeper-cluster/zk003/zookeeper-3.4.11/logs
# the port at which the clients will connect
clientPort=2183
server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
6 配置文件说明
“
server.id=host:port:port.
”指示了不同的
ZooKeeper
服务器的自身标识,作为集群的一部分的机器应该知道
ensemble
中的其它机器。用户可以从“
server.id=host:port:port.
”中读取相关的信息。
在服务器的 data( dataDir 参数所指定的目录)目录下创建一个文件名为 myid 的文件,这个文件中仅含有一行的内容,指定的是自身的 id
值。比如,服务器“
1 ”应该在 myid 文件中写入“ 1
”。这个
id
值必须是
ensemble
中唯一的,且大小在
1
到
255
之间。这一行配置中,第一个端口(
port
)是从(
follower
)机器连接到主(
leader
)机器的端口,第二个端口是用来进行
leader
选举的端口。
6 部署myid文件
D:\Program Files\zookeeper\zookeeper-cluster\zk001\zookeeper-3.4.11\data\myid 文件内容 1
D:\Program Files\zookeeper\zookeeper-cluster\zk002\zookeeper-3.4.11\data\myid 文件内容 2
D:\Program Files\zookeeper\zookeeper-cluster\zk003\zookeeper-3.4.11\data\myid 文件内容 3
7 分别启动3个服务
D:\Program Files\zookeeper\zookeeper-cluster\zk001\zookeeper-3.4.11\bin\zkServer.cmd
D:\Program Files\zookeeper\zookeeper-cluster\zk002\zookeeper-3.4.11\bin\zkServer.cmd
D:\Program Files\zookeeper\zookeeper-cluster\zk003\zookeeper-3.4.11\bin\zkServer.cmd
8 三个服务器没启动完成时,各个服务器会报错,都启动完成后,停止报错
zk002当选为leader