每个节点对应一个zoo.cfg配置文件。每个节点对应一个启动的ZKServer.cmd
1、复制zoo.cfg,为zoo2.cfg、zoo3.cfg。内容如下:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=D:\Development\ZZKK\apache-zookeeper-3.6.2-bin\dataDir
clientPort=2181
server.1 = 127.0.0.1:2887:3887
server.2 = 127.0.0.1:2888:3888
server.3 = 127.0.0.1:2889:3889
tickTime=2000
initLimit=10
syncLimit=5
dataDir=D:\Development\ZZKK\apache-zookeeper-3.6.2-bin\dataDir2
clientPort=2182
server.1 = 127.0.0.1:2887:3887
server.2 = 127.0.0.1:2888:3888
server.3 = 127.0.0.1:2889:3889
tickTime=2000
initLimit=10
syncLimit=5
dataDir=D:\Development\ZZKK\apache-zookeeper-3.6.2-bin\dataDir3
clientPort=2183
server.1 = 127.0.0.1:2887:3887
server.2 = 127.0.0.1:2888:3888
server.3 = 127.0.0.1:2889:3889
2、复制zkServer.cmd为zkServer2.cmd、zkServer3.cmd内容如下
@echo off setlocal call "%~dp0zkEnv.cmd" set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain set ZOO_LOG_FILE=zookeeper-%USERNAME%-server-%COMPUTERNAME%.log set ZOOCFG=D:DevelopmentZKKapache-zookeeper-3.6.2-binconfzoo.cfg echo on call %JAVA% "-Dzookeeper.extendedTypesEnabled=true" "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" "-Dzookeeper.log.file=%ZOO_LOG_FILE%" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%%%p /t /f" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* endlocal
@echo off setlocal call "%~dp0zkEnv.cmd" set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain set ZOO_LOG_FILE=zookeeper-%USERNAME%-server-%COMPUTERNAME%.log set ZOOCFG=D:DevelopmentZKKapache-zookeeper-3.6.2-binconfzoo2.cfg echo on call %JAVA% "-Dzookeeper.extendedTypesEnabled=true" "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" "-Dzookeeper.log.file=%ZOO_LOG_FILE%" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%%%p /t /f" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* endlocal
@echo off setlocal call "%~dp0zkEnv.cmd" set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain set ZOO_LOG_FILE=zookeeper-%USERNAME%-server-%COMPUTERNAME%.log set ZOOCFG=D:DevelopmentZKKapache-zookeeper-3.6.2-binconfzoo3.cfg echo on call %JAVA% "-Dzookeeper.extendedTypesEnabled=true" "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" "-Dzookeeper.log.file=%ZOO_LOG_FILE%" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%%%p /t /f" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* endlocal
3、在各自的dataDir文件夹下新增一个文件名为myid的文件。内容为节点的唯一标识。我这里dataDir的myid为1,dataDir2的myid为2,dataDir3的myid为3,
4、依次启动zkServer.cmd、zkServer2.cmd、zkServer3.cmd不按照顺序启动也可