[root@node02 conf]# /export/servers/zookeeper-3.4.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node02 conf]# /export/servers/zookeeper-3.4.9/bin/zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper-3.4.9/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
[root@node02 conf]# jps
10913 Jps

问题:

启动zookpeerer,查看状态显示:Error contacting service. It is probably not running.,查看jps也没有QuorumPeerMain进程。

解决过程:

step1:查因

查看zookeeper.out文件来寻找问题原因:(当前处于哪个目录,执行完zkServer.sh start命令, zookeeper.out就会写在哪个目录)

[root@node02 conf]# ll
total 20
-rw-r--r-- 1 root root  535 Jul 22 17:34 configuration.xsl
-rw-r--r-- 1 root root 2161 Jul 22 17:34 log4j.properties
-rw-r--r-- 1 root root 1225 Jul 22 18:01 zoo.cfg
-rw-r--r-- 1 root root 1387 Jul 22 19:19 zookeeper.out
-rw-r--r-- 1 root root  922 Jul 22 17:34 zoo_sample.cfg
You have new mail in /var/spool/mail/root
[root@node02 conf]# vim zookeeper.out 
2022-07-22 19:19:48,894 [myid:] - INFO  [main:QuorumPeerConfig@124] - Reading configuration from: /export/servers/zookeeper-3.4.9/bin/../conf/zoo.cfg
2022-07-22 19:19:48,922 [myid:] - INFO  [main:QuorumPeer$QuorumServer@149] - Resolved hostname: node03 to address: node03/192.168.202.120
2022-07-22 19:19:48,923 [myid:] - ERROR [main:QuorumPeerMain@85] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /export/servers/zookeeper-3.4.9/bin/../conf/zoo.cfg
        at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:144)
        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.NumberFormatException: For input string: "1 #表示å¤<9a>é<95>¿æ<97>¶é<97>´ï¼<88>å°<8f>æ<97>¶ï¼<89>å<90><88>å¹¶ä¸<80>ä¸<8b>å¿«ç<85>§ç<89><88>æ<9c>¬"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.parseInt(Integer.java:615)
        at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:199)
        at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:140)
        ... 2 more
Invalid config, exiting abnormally

重点看Caused by的第一行(如果你的原因和我不一样,就去找对应的原因即可,应该网上都有)
这里乱码了,我看到"1 #猜测是不是某个地方的注释的原因,果真是,我的配置文件中有两个地方我将注释和命令写在了了同一行,错误示范如下:

[root@node02 conf]# vim 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=/export/servers/zookeeper-3.4.9/zkdatas
dataLogDir=/export/servers/zookeeper-3.4.9/logs

# 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 #表示snapshots快照版本保存几份
# Purge task interval in hours
# Set to "0" to disable auto purge feature
autopurge.purgeInterval=1 #表示多长时间(小时)合并一下快照版本

#给每台机器都分配了唯一的id值,1、2、3
server.1=node01:2888:3888
server.2=node02:2888:3888
server.3=node03:2888:3888

step2:解决

于是我将下面两行的注释单独放在一行
autopurge.snapRetainCount=3 #表示snapshots快照版本保存几份
autopurge.purgeInterval=1 #表示多长时间(小时)合并一下快照版本
修改以后的配置文件:

[root@node02 conf]# vim 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=/export/servers/zookeeper-3.4.9/zkdatas
dataLogDir=/export/servers/zookeeper-3.4.9/logs

# 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
#表示snapshots快照版本保存几份

# Purge task interval in hours
# Set to "0" to disable auto purge feature
autopurge.purgeInterval=1 
#表示多长时间(小时)合并一下快照版本

#给每台机器都分配了唯一的id值,1、2、3
server.1=node01:2888:3888
server.2=node02:2888:3888
server.3=node03:2888:3888

然后再次尝试开启zookeeper服务就成功了

[root@node02 conf]# cd ..
[root@node02 zookeeper-3.4.9]# /export/servers/zookeeper-3.4.9/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node02 zookeeper-3.4.9]# /export/servers/zookeeper-3.4.9/bin/zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader
[root@node02 zookeeper-3.4.9]# jps
11154 QuorumPeerMain
11221 Jps

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐