报错背景:
zookeeper安装完成之后,启动之后正常,但是查看log文件zookeeper.log时发现报错。
报错现象:
-- ::, [myid:] - INFO [WorkerSender[myid=]:QuorumPeer$QuorumServer@] - Resolved hostname: 192.168.52.27 to address: /192.168.52.27
-- ::, [myid:] - INFO [WorkerReceiver[myid=]:FastLeaderElection@] - Notification: (message format version), (n.leader), 0x1000000b2 (n.zxid), 0x1 (n.round), LOOKING (n.state), (n.sid), 0x6 (n.peerEpoch) LOOKING (my state)
-- ::, [myid:] - WARN [WorkerSender[myid=]:QuorumCnxManager@] - Cannot open channel to at election address /192.168.52.27:
java.net.ConnectException: 拒绝连接 (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:)
at java.net.Socket.connect(Socket.java:)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:)
at java.lang.Thread.run(Thread.java:)
-- ::, [myid:] - INFO [WorkerSender[myid=]:QuorumPeer$QuorumServer@] - Resolved hostname: 192.168.52.27 to address: /192.168.52.27
-- ::, [myid:] - INFO [/192.168.52.28::QuorumCnxManager$Listener@] - Received connection request /192.168.52.27:
-- ::, [myid:] - INFO [WorkerReceiver[myid=]:FastLeaderElection@] - Notification: (message format version), (n.leader), 0x1000000b2 (n.zxid), 0x1 (n.round), LOOKING (n.state), (n.sid), 0x6 (n.peerEpoch) LOOKING (my state)
-- ::, [myid:] - INFO [WorkerReceiver[myid=]:FastLeaderElection@] - Notification: (message format version), (n.leader), 0x1000000b2 (n.zxid), 0x1 (n.round), LOOKING (n.state), (n.sid), 0x6 (n.peerEpoch) LOOKING (my state)
报错原因:
如果是刚启动zookeeper报出这个错误,然后不再不错,那就是正常现象。是由于有的节点启动,而有的节点还没有启动,这段时间已经启动的节点就会去努力寻找没有启动的节点,就会报出这样的错误。这是一种正常现象,无需多虑。
如果启动很长时间之后还在报错,可以尝试下面的饿解决方案。
报错解决:
修改每个节点的zoo.cfg文件中的相对应的server.x=0.0.0.0:2888:3888
修改完成后重启zookeeper,报错消失。