启动集群时失败

启动集群报如下错:

1
2
3
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START

这个报错没有参考价值。

查看日志文件(cat $ZOOKEEPER_HOME/logs/zookeeper-hadoop103-server-hadoop103.out,就是logs下的.out文件,你的路径可能和我不一样哦):

如果报错内容类似:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Address unresolved: hadoop105:3888
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.initializeWithAddressString(QuorumPeer.java:358)
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:279)
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:274)
at org.apache.zookeeper.server.quorum.flexible.QuorumMaj.<init>(QuorumMaj.java:92)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.createQuorumVerifier(QuorumPeerConfig.java:658)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseDynamicConfig(QuorumPeerConfig.java:689)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.setupQuorumPeerConfig(QuorumPeerConfig.java:663)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:491)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:194)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:125)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:91)
Invalid config, exiting abnormally
2023-01-30 04:20:57,810 [myid:] - INFO [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.
2023-01-30 04:20:57,811 [myid:] - ERROR [main:ServiceUtils@48] - Exiting JVM with code 2

即表示可能是zoo.cfg配置文件出错了。

需要把后面的空格都删除掉,我是多加了空格。

1
2
3
4
####################### cluster ########################## 
server.3=hadoop103:2888:3888
server.4=hadoop104:2888:3888
server.5=hadoop105:2888:3888

就是这一步。

修改完配置文件,单独分发配置文件:

1
xsync $ZOOKEEPER_HOME/conf/zoo.cfg

如果日志文件类似:

1
2
3
4
5
6
7
8
9
10
11
12
13
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /usr/local/zookeeper/bin/../conf/zoo.cfg
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:198)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:125)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:91)
Caused by: java.lang.IllegalArgumentException: myid file is missing
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.checkValidity(QuorumPeerConfig.java:796)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.setupQuorumPeerConfig(QuorumPeerConfig.java:667)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:491)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:194)
... 2 more
Invalid config, exiting abnormally
2023-01-30 07:49:35,165 [myid:] - INFO [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.
2023-01-30 07:49:35,166 [myid:] - ERROR [main:ServiceUtils@48] - Exiting JVM with code 2

可知是找不到myid。请前找一下$ZOOKEEPER_HOME/zkData下是否有myid文件.如果没有则创建,如果有也有可能是没有内容。

如果有内容还是会报错,那就是zoo.cfg中单dataDir配置的路径有问题,请去修改。

修改完配置文件,单独分发配置文件:

1
xsync $ZOOKEEPER_HOME/conf/zoo.cfg

如果是:

1
Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain

那么可能是端口冲突,请考虑你的zookeeper的版本。

如果版本>=3.5.0可能是端口冲突引起的。在zoo.cfg中添加(或修改):

1
2
# admin port
admin.serverPort=8081

如果都试过了,且版本>=3.5.5,则请降低版本。或者重新下载。因为版本>=3.5.5时,官网首页会提供两个安装路径:

安装包

一定要选择第一个,标准版的,不要下载源码版。