第一次尝试自己在Windows上搭建zk的集群,是在搭建单机zk的基础上操作的。
单机时的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:\Software\zookeeper\zk_data\server1 # 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
复制三个节点,增加对应的集群配置
server.1=localhost:2887:3887 server.2=localhost:2888:3888 server.3=localhost:2889:3889
启动
果然报错了……
去掉server1=local...server2...server3...又可以正常启动,仔细检查了那三行配置也没有多余的空格……为此还在sublime中配置了
"draw_white_space": "all"
百思不得其解,突然想起来log文件里应该会有额外的信息吧……
果不其然
2018-03-30 21:38:13,591 [myid:] - ERROR [main:QuorumPeerMain@85] - Invalid config, exiting abnormally org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing D:\Software\zookeeper\zookeeper-3.4.10-1\bin\..\conf\zoo.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:Softwarezookeeperzk_dataserver1\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
快照日志、事务日志根据以下路径是可以正常存储的
dataDir=D:\Software\zookeeper\zk_data\server1
集群查找myid文件就gg了……会把"\"当做是转义符处理,所以路径错误,找不到myid文件从而启动失败,修改该路径后重新启动一切正常 // todo 明天看源码查一查两者处理方式
dataDir=D:\\Software\\zookeeper\\zk_data\\server1 2018-03-30 21:59:15,784 [myid:1] - INFO [main:QuorumPeer@624] - currentEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation 2018-03-30 21:59:15,799 [myid:1] - INFO [main:QuorumPeer@639] - acceptedEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation 2018-03-30 21:59:15,810 [myid:1] - INFO [ListenerThread:QuorumCnxManager$Listener@739] - My election bind port: localhost/127.0.0.1:3887 2018-03-30 21:59:15,817 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@865] - LOOKING 2018-03-30 21:59:15,819 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@818] - New election. My id = 1, proposed zxid=0x0
Ps:zookeeper日志修改需改动log4j.properties的zookeeper.root.logger和zkEnv.cmd中的ZOO_LOG4J_PROP,默认是CONSOLE,我都改成了ROLLINGFILE了
log路径需要修改zkEnv.cmd中的ZOO_LOG_DIR。
log4j.properties中的zookeeper.log.dir=. 表示命令所在的路径 // todo 初步估计zkEnv.cmd中不修改,此处改为绝对路径应该也是可以的,明天验证
明天正常上班~goodnight
刚刚发邮件给博客园注销了一个不用的账号,后台提供支持服务的tx也是蛮辛苦的~
加油!