成功解决zookeeper启动后立即退出的问题、客户端连接zookeeper拒绝的问题(Socket error occurred: localhost/127.0.0.1:2181: Connection refused)

遇到的问题:

我在本地的虚拟机起了三个zookeeper(伪集群),启动的时候zkServer还没启动一会就停止服务了,用kafka连接、zkClient连接都被拒绝。

 2020-11-05 20:21:37,259 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1112] - Opening socket connection to server localhost/192.168.205.128:2181. Will not attempt to authenticate using SASL (unknown error)
2020-11-05 20:21:37,260 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1244] - Socket error occurred: localhost/192.168.205.128:2181: Connection refused
解决方法
  1. 首先把/tmp/zookeeper里面的zookeeper_server.pid删掉
[root@dingy zookeeper]# ls
zookeeper_server.pid
[root@dingy zookeeper]# ls
zookeeper_server.pid
[root@dingy zookeeper]# cat zookeeper_server.pid 
5513[root@dingy zookeeper]# cd co
-bash: cd: co: No such file or directory
[root@dingy zookeeper]# ls
zookeeper_server.pid
[root@dingy zookeeper]# rm -rf zookeeper_server.pid 
[root@dingy zookeeper]# cd ..
[root@dingy tmp]# ls
hsperfdata_root                                                          vmware-root_676-2731021186  vmware-root_690-2697074069  zookeeper-1
systemd-private-2e40606fd5474a4187c563106e45a043-chronyd.service-kC7VlS  vmware-root_678-2722697728  vmware-root_694-2688619536  zookeeper-2
vmware-root_671-3988556280                                               vmware-root_684-2697598348  zookeeper
[root@dingy tmp]# cd zookeeper-1
[root@dingy zookeeper-1]# ls
zookeeper_server.pid
[root@dingy zookeeper-1]# rm -rf zookeeper_server.pid 
[root@dingy zookeeper-1]# cd ..
[root@dingy tmp]# cd zookeeper-2
[root@dingy zookeeper-2]# ls
zookeeper_server.pid
[root@dingy zookeeper-2]# rm -rf zookeeper_server.pid 
[root@dingy zookeeper-2]# cd ../zookeeper

删除命令为

rm -rf zookeeper_server.pid
  1. 然后再看看各自的/tmp/zookeeper里面有没有各自的myid文件(这个如果你是配置的伪集群需要检查一下,如果只是单节点就不需要了,直接做完上一步后启动zookeeper即可)
[root@dingy zookeeper]# ls
zookeeper_server.pid
[root@dingy zookeeper]# rm -rf zookeeper_server.pid
[root@dingy zookeeper]# vim myid
[root@dingy zookeeper]# ls
myid
[root@dingy zookeeper]# cd ..
[root@dingy tmp]# cd zookeeper-1
[root@dingy zookeeper-1]# ls
zookeeper_server.pid
[root@dingy zookeeper-1]# rm -rf zookeeper_server.pid
[root@dingy zookeeper-1]# vim myid
[root@dingy zookeeper-1]# ls
myid
[root@dingy zookeeper-1]# cd ../zookeeper-2
[root@dingy zookeeper-2]# ls
zookeeper_server.pid
[root@dingy zookeeper-2]# rm -rf zookeeper_server.pid
[root@dingy zookeeper-2]# ls
[root@dingy zookeeper-2]# vi myid
[root@dingy zookeeper-2]# ls
myid
  1. 启动zookeeper,然后jps看下启动成功没有
[root@dingy zookeeper-2]# jps
6016 QuorumPeerMain
5985 QuorumPeerMain
5954 QuorumPeerMain
6211 Kafka
6184 ZooKeeperMain
6639 Jps
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐