使用./bin/zkServer.sh start启动zookeeper集群,得到以下信息:
[root@StevenRH6 zookeeper-3.4.6]# ./bin/zkServer.sh start JMX enabled by default Using config: /opt/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
而后使用./bin/zkServer.sh status查看集群状态的时候发现了错误:
[root@StevenRH6 zookeeper-3.4.6]# ./bin/zkServer.sh status JMX enabled by default Using config: /opt/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg Error contacting service. It is probably not running.
查看zookeeper启动日志(/opt/zookeeper/zookeeper-3.4.6/bin/zookeeper.out)发现了如下的错误信息:
[root@StevenRH6 ~]# tail -500f /opt/zookeeper/zookeeper-3.4.6/bin/zookeeper.out ......... ......... 2017-06-02 09:52:18,330 [myid:3] - WARN [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@382] - Cannot open channel to 1 at election address RHServer1:3888 java.net.UnknownHostException: RHServer1 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:402) at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:840) at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:762) 2017-06-02 09:52:18,333 [myid:3] - WARN [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@382] - Cannot open channel to 2 at election address RHServer2:3888 java.net.UnknownHostException: RHServer2 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:402) at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:840) at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:762) 2017-06-02 09:52:18,333 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@849] - Notification time out: 60000
这种情况的出现一般是因为主机设置了防火墙,使用下面语句关闭防火墙即可:
[root@StevenRH6 conf]# sudo service iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ]
然后运行如下命令查看zookeeper集群状态:
[root@StevenRH6 zookeeper-3.4.6]# ./bin/zkServer.sh status JMX enabled by default Using config: /opt/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: follower ( 也可能为 leader )