一 问题出现情形
1 集群启动后异常关闭,重启出错
2 集群未正常启动
二 查看zookeeper.out分析原因
cat zookeeper.out
1. java.net.NoRouteToHostException: 没有到主机的路由 (Host unreachable)
2. at java.net.PlainSocketImpl.socketConnect(Native Method)
3. at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
4. at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
5. at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
6. at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
7. at java.net.Socket.connect(Socket.java:589)
8. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:558)
9. at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:610)
10. at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:838)
11. at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:957)
解决步骤:问题排查 7 ->[2、6] ->重启集群
2 初次启动。
解决步骤:问题排查1-->2-->3-->4-->5-->7-->重启集群
备注:初次启动 个个环节都有可能有问题 如果有报错信息可以针对性解决
3 重新启动。
解决步骤:暂停集群-->2-->6-->7-->重启集群
备注:重新启动主要是,节点配置信息问题以及防火墙问题。需要按顺序,暂停zookeeper,kill进程,删除节点信息,关闭防火墙,再次启动集群
三 问题排查
1 java环境
java -version
2 排查端口占用(我就这里的问题)
netstat -apn | grep 2181 #默认2181端口为服务端提供端口
2020-08-14 13:45:39,162 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@813] - New election. My id = 1, proposed zxid=0x100000000
2020-08-14 13:45:39,162 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@595] - Notification: 1 (message format version), 1 (n.leader), 0x100000000 (n.zxid), 0x3 (n.round), LOOKING (n.state), 1 (n.sid), 0x2 (n.peerEpoch) LOOKING (my state)
2020-08-14 13:45:39,162 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@595] - Notification: 1 (message format version), 2 (n.leader), 0x200000000 (n.zxid), 0x3 (n.round), LOOKING (n.state), 2 (n.sid), 0x2 (n.peerEpoch) LOOKING (my state)
2020-08-14 13:45:39,162 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@584] - Cannot open channel to 3 at election address /10.3.3.138:3888
java.net.ConnectException: 拒绝连接 (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
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:558)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:534)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:454)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:435)
at java.lang.Thread.run(Thread.java:748)
2020-08-14 13:45:39,163 [myid:1] - INFO [WorkerSender[myid=1]:QuorumPeer$QuorumServer@184] - Resolved hostname: 10.3.3.138 to address: /10.3.3.138
2020-08-14 13:45:39,163 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@595] - Notification: 1 (message format version), 2 (n.leader), 0x200000000 (n.zxid), 0x3 (n.round), LOOKING (n.state), 1 (n.sid), 0x2 (n.peerEpoch) LOOKING (my state)
2020-08-14 13:45:39,163 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@584] - Cannot open channel to 3 at election address /10.3.3.138:3888
java.net.ConnectException: 拒绝连接 (Connection refused)
备注:若集群未启动 则不应该有端口占用
kill -9 pid #pid为占用端口的进程id号
3 排除网卡问题
ip addr
备注:如果为物理地址则 重启网卡
service network restart
4 排除网络问题
ping ip #ping其他节点主机 若zoo.cfg 使用域名则用域名
备注:无ping命令则安装 yum install iputils-ping 若有问题则 host映射问题
5 排查节点配置信息
dataDir 是否存在 myid文件内容与 service.x 中x对应
例如:zk01 其对应service.x 则该目录下myid内容为1
6 删除节点残留信息
rm -rf version-2/ zookeeper_server.pid
7 防火墙拦截端口
systemctl status firewalld.service
systemctl stop firewalld.service #关闭防火墙
systemctl disable firewalld.service #禁止启动防火墙
本来以为是三台主机没有配置好,重装了好几次,最后总结了4个问题。
1:如果用阿里云服务器,链接,服务器没有防火墙,只有安全组,需要自己开放端口。(这次悲剧这里)
2:在本地进行连接的话 127.0.0.1配置注销了(很多博主都写了,我也不知道为啥)
3:记着设置为静态路由,动态的,修改比较麻烦。
4:zookeeper的原子广播协议(选举算法),将集群分为leader(有且只有一个),和follower,这些是从众多结点中随机选出,需要每一个结点的zookeeper都要开启,不然也会造成链接失败。(注:有的时候选举的特别慢,要耐心等候
下面几点需要注意的:
1、确认在每个$zookeeper_home/data/myid中有对应数字
2、是否关闭防火墙:systemctl stop firewalld,systemctl disable firewalld
3、zoo.cfg中的server需要写成以下形式的: