首先,下载windows版本的zk,自己可以去官网下载
第一步,在/conf下面建立zoo1.cfg、zoo2.cfg、zoo3.cfg三个文件,其中代码如下:
zoo1.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:/ProfessionalKl/apache-zookeeper-3.5.5-bin/data/1
# the port at which the clients will connect
clientPort=2181
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
zoo2.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:/ProfessionalKl/apache-zookeeper-3.5.5-bin/data/2
# the port at which the clients will connect
clientPort=2182
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
zoo3.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:/ProfessionalKl/apache-zookeeper-3.5.5-bin/data/3
# the port at which the clients will connect
clientPort=2183
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目录分别建立对应的目录,如在data文件夹1的文件夹下建立文件myid,该文件没有格式,名称就是myid,其中填写内容,1,另外两个文件也类似,文件夹2下myid的内容为2,文件夹3下myid的内容为3。
第三步:启动脚本
我们打开bin目录下面的zkEnv.cmd文件,发现最后一行代码为:
set ZOOCFG=%ZOOCFGDIR%\zoo.cfg
由此我们可以看出,这里就是读配置的地方。我们分别改成我们第一步中的配置文件,如第一个zk节点,改动完保存一次,然后直接点击zkServer.cmd,此时我们发现zookeeper端口2181已经启动,再继续改成zoo2.cfg,再启动,依次类推。
注意:三个都未完全启动时,先启动的会一直报错,当全部节点启动完成时,才不会报错。
set ZOOCFG=%ZOOCFGDIR%\zoo1.cfg