Zookeeper在Windows下搭建集群教程

每个节点对应一个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
zoo.cfg
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
zoo2.cfg
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
zoo3.cfg

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:\Development\ZZKK\apache-zookeeper-3.6.2-bin\conf\zoo.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
zkServer.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:\Development\ZZKK\apache-zookeeper-3.6.2-bin\conf\zoo2.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
zkServer2.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:\Development\ZZKK\apache-zookeeper-3.6.2-bin\conf\zoo3.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
zkServer3.cmd

3、在各自的dataDir文件夹下新增一个文件名为myid的文件。内容为节点的唯一标识。我这里dataDir的myid为1,dataDir2的myid为2,dataDir3的myid为3,

4、依次启动zkServer.cmd、zkServer2.cmd、zkServer3.cmd不按照顺序启动也可

posted @ 2020-12-05 10:49  Java民工陆小凤  阅读(429)  评论(0编辑  收藏  举报