测试zookeeper集群搭建时,虽然启动结果显示了 STARTED,但是实际上zookeeper服务并没有启动,如下:
[root@db-7-52 bin]# sh /usr/local/zookeeper/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/zkCluster/zk1/conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zkCluster/zk1/conf/zoo.cfg
Starting zookeeper ... STARTED
虽然配置了日志目录,但是日志目录并没有输出任何日志。在网上查很多说在 zkServer.sh脚本的status
选项的 nc
命令后加上-q 1
参数可以输出,但是我的源码里并没有 nc
命令。
# zookeeper版本 3.4.14
status)
# -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output
clientPortAddress=`$GREP "^[[:space:]]*clientPortAddress[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'`
if ! [ $clientPortAddress ]
then
clientPortAddress="localhost"
fi
clientPort=`$GREP "^[[:space:]]*clientPort[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'`
STAT=`"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
-cp "$CLASSPATH" $JVMFLAGS org.apache.zookeeper.client.FourLetterWordMain \
$clientPortAddress $clientPort srvr 2> /dev/null \
| $GREP Mode`
if [ "x$STAT" = "x" ]
then
echo "Error contacting service. It is probably not running."
exit 1
else
echo $STAT
exit 0
fi
;;
偶然看到一篇文章,可以通过 start-foreground
选项启动时输出日志。
[root@db-7-52 bin]# sh /usr/local/zookeeper/zookeeper/bin/zkServer.sh start-foreground /usr/local/zookeeper/zkCluster/zk1/conf/zoo.cfg start-foreground
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zkCluster/zk1/conf/zoo.cfg
2022-07-12 19:54:10,736 [myid:] - INFO [main:QuorumPeerConfig@136] - Reading configuration from: /usr/local/zookeeper/zkCluster/zk1/conf/zoo.cfg
2022-07-12 19:54:10,763 [myid:] - INFO [main:QuorumPeer$QuorumServer@185] - Resolved hostname: 127.0.0.1 to address: /127.0.0.1
2022-07-12 19:54:10,763 [myid:] - INFO [main:QuorumPeer$QuorumServer@185] - Resolved hostname: 127.0.0.1 to address: /127.0.0.1
2022-07-12 19:54:10,764 [myid:] - INFO [main:QuorumPeer$QuorumServer@185] - Resolved hostname: 127.0.0.1 to address: /127.0.0.1
2022-07-12 19:54:10,765 [myid:] - ERROR [main:QuorumPeerMain@88] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /usr/local/zookeeper/zkCluster/zk1/conf/zoo.cfg
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:156)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:104)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:81)
Caused by: java.lang.IllegalArgumentException: initLimit is not set
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:357)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:152)
... 2 more
Invalid config, exiting abnormally
从输出可以看出是因为 initLimit is not set
导致的无法正常启动,在配置文件中配置好即可启动。
参考:https://blog.csdn.net/u011328843/article/details/84190285