至D:\dev\zookeeper\zookeeper-3.4.10\conf 复制 zoo_sample.cfg 并粘贴到当前目录下,命名zoo.cfg.
1、编辑zoo.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:\\dev\\zookeeper\\data
dataLogDir=D:\\dev\\zookeeper\\log
# the port at which the clients will connect
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
2、cmd命令下进入D:\dev\zookeeper\zookeeper-3.4.10\bin目录下运行zkserver.cmd.如下所示:
2018-11-21 17:32:36,043 [myid:] - INFO [main:Environment@100] - Server environment:java.compiler=
2018-11-21 17:32:36,045 [myid:] - INFO [main:Environment@100] - Server environment:os.name=Windows 10
2018-11-21 17:32:36,045 [myid:] - INFO [main:Environment@100] - Server environment:os.arch=amd64
2018-11-21 17:32:36,046 [myid:] - INFO [main:Environment@100] - Server environment:os.version=10.0
2018-11-21 17:32:36,046 [myid:] - INFO [main:Environment@100] - Server environment:user.name=admin
2018-11-21 17:32:36,047 [myid:] - INFO [main:Environment@100] - Server environment:user.home=C:\Users\admin
2018-11-21 17:32:36,047 [myid:] - INFO [main:Environment@100] - Server environment:user.dir=D:\dev\zookeeper\zookeeper-3.4.10\bin
2018-11-21 17:32:36,060 [myid:] - INFO [main:ZooKeeperServer@829] - tickTime set to 2000
2018-11-21 17:32:36,060 [myid:] - INFO [main:ZooKeeperServer@838] - minSessionTimeout set to -1
2018-11-21 17:32:36,061 [myid:] - INFO [main:ZooKeeperServer@847] - maxSessionTimeout set to -1
2018-11-21 17:32:36,560 [myid:] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181
3、启动完成后cmd命令下,netstat-ano查看端口监听服务。
4、cmd下进入D:\machine\zookeeper-3.4.6\bin目录下运行zkcli.cmd.如下所示:
2018-11-21 17:34:18,097 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=
2018-11-21 17:34:18,098 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Windows 10
2018-11-21 17:34:18,099 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2018-11-21 17:34:18,100 [myid:] - INFO [main:Environment@100] - Client environment:os.version=10.0
2018-11-21 17:34:18,102 [myid:] - INFO [main:Environment@100] - Client environment:user.name=admin
2018-11-21 17:34:18,106 [myid:] - INFO [main:Environment@100] - Client environment:user.home=C:\Users\admin
2018-11-21 17:34:18,107 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=D:\dev\zookeeper\zookeeper-3.4.10\bin
2018-11-21 17:34:18,109 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@277050dc
Welcome to ZooKeeper!
2018-11-21 17:34:18,809 [myid:] - INFO [main-SendThread(0:0:0:0:0:0:0:1:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
2018-11-21 17:34:18,813 [myid:] - INFO [main-SendThread(0:0:0:0:0:0:0:1:2181):ClientCnxn$SendThread@876] - Socket connection established to 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181, initiating session
JLine support is enabled
[zk: localhost:2181(CONNECTING) 0] 2018-11-21 17:34:18,932 [myid:] - INFO [main-SendThread(0:0:0:0:0:0:0:1:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181, sessionid = 0x167359d3d6b0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
1、复制 zoo.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:\\dev\\zookeeper\\data\\d_1
dataLogDir=D:\\dev\\zookeeper\\log
# 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
# 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
2、复制 zoo1.cfg 文件为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:\\dev\\zookeeper\\data\\d_2
dataLogDir=D:\\dev\\zookeeper\\log
# 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
# 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
3、复制 zoo1.cfg 文件为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:\\dev\\zookeeper\\data\\d_3
dataLogDir=D:\\dev\\zookeeper\\log
# 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
# 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
4、在D:\dev\zookeeper\data 新建d_1、d_2及d_3目录
5、复制zkserver.cmd文件为zkServer-1.cmd。部分内容如下:
setlocal
call "%~dp0zkEnv.cmd"
set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
set ZOOCFG=..\conf\zoo1.cfg
echo on
call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*
endlocal
6、复制zkserver-1.cmd文件为zkServer-2.cmd。部分内容如下:
setlocal
call "%~dp0zkEnv.cmd"
set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
set ZOOCFG=..\conf\zoo2.cfg
echo on
call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*
endlocal
7、复制zkserver-1.cmd文件为zkServer-3.cmd。部分内容如下:
setlocal
call "%~dp0zkEnv.cmd"
set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
set ZOOCFG=..\conf\zoo3.cfg
echo on
call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*
endlocal
8、cmd下分别运行zkserver-1.cmd报错如下:
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing ..\conf\zoo1.cfg
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:154)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:101)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Caused by: java.lang.IllegalArgumentException: D:\dev\zookeeper\data\d_1\myid file is missing
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:406)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:150)
... 2 more
Invalid config, exiting abnormally
9、缺少myid 文件在对应位置创建myid 文件,文件内随便写一个数字,重新启动,报如下错误:
2018-11-21 17:47:14,624 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@588] - Cannot open channel to 2 at election address localhost/127.0.0.1:3888
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:562)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:538)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:452)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:433)
at java.lang.Thread.run(Thread.java:745)
2018-11-21 17:47:14,626 [myid:1] - INFO [WorkerSender[myid=1]:QuorumPeer$QuorumServer@167] - Resolved hostname: localhost to address: localhost/127.0.0.1
2018-11-21 17:47:15,629 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@588] - Cannot open channel to 3 at election address localhost/127.0.0.1:3889
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:562)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:538)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:452)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:433)
at java.lang.Thread.run(Thread.java:745)
10、这错是连接另外两个节点失败,启动其他两个节点即可。
11、cmd下netstar-ano查看端口监听情况。
12、cmd下运行zkcli.cmd -server:localhost:2181;zkcli.cmd ;-server:localhost:2182;zkcli.cmd -server:localhost:2183.