淘先锋技术网

首页 1 2 3 4 5 6 7

第一次尝试自己在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
View Code

==========2018/3/31 22:27修正=========

此处并非是正常启动,DataDir的值其实为:D:Softwarezookeeperzk_dataserver1,并非期望的目录。

而对于D:Softwarezookeeperzk_dataserver1而言,"D:"相当于切换盘符,如果命令是在C盘执行,则切换到了D盘根目录,如果本身就在D盘执行,则就在命令所在目录,而“Softwarezookeeperzk_dataserver1”不是以“C:\\”“D:\\”等开头的,故认为是相对路径,所以导致设置的目录为“D:\Software\zookeeper\zookeeper-3.4.10-1\bin\Softwarezookeeperzk_dataserver1”

====================================

复制三个节点,增加对应的集群配置

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文件从而启动失败,修改该路径后重新启动一切正常

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中不修改,此处改为绝对路径应该也是可以的,明天验证

验证:zkEnv.cmd中的配置是必须修改的,只修改log4j.properties是不生效的

可参考:

https://stackoverflow.com/questions/26612908/why-does-zookeeper-not-use-my-log4j-properties-file-log-directory

 

明天正常上班~goodnight

刚刚发邮件给博客园注销了一个不用的账号,后台提供支持服务的tx也是蛮辛苦的~

加油!

 

转载于:https://www.cnblogs.com/mkcoding/p/8679244.html