前言

    上次启动zookeeper 集群的时候遇到“Connection refused”的问题,小编动手搭集群的机会也是很少,下面来记录下解决错误的过程。

正文

错误信息

[root@VM_110_4_centos bin]# ./zkCli.sh -server 192.168.36.4:2181,192.168.36.5:2181,192.168.36.2:2181
Connecting to 192.168.36.4:2181,192.168.36.5:2181,192.168.36.2:2181
2018-12-27 18:20:44,179 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 04:05 GMT
2018-12-27 18:20:44,181 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=zk1
2018-12-27 18:20:44,181 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_191
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/usr/lib/zookeeper-3.4.13/bin/../build/classes:/usr/lib/zookeeper-3.4.13/bin/../build/lib/*.jar:/usr/lib/zookeeper-3.4.13/bin/../lib/slf4j-log4j12-1.7.25.jar:/usr/lib/zookeeper-3.4.13/bin/../lib/slf4j-api-1.7.25.jar:/usr/lib/zookeeper-3.4.13/bin/../lib/netty-3.10.6.Final.jar:/usr/lib/zookeeper-3.4.13/bin/../lib/log4j-1.2.17.jar:/usr/lib/zookeeper-3.4.13/bin/../lib/jline-0.9.94.jar:/usr/lib/zookeeper-3.4.13/bin/../lib/audience-annotations-0.5.0.jar:/usr/lib/zookeeper-3.4.13/bin/../zookeeper-3.4.13.jar:/usr/lib/zookeeper-3.4.13/bin/../src/java/lib/*.jar:/usr/lib/zookeeper-3.4.13/bin/../conf:
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2018-12-27 18:20:44,183 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-862.el7.x86_64
2018-12-27 18:20:44,184 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2018-12-27 18:20:44,184 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2018-12-27 18:20:44,184 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/usr/lib/zookeeper-3.4.13/bin
2018-12-27 18:20:44,184 [myid:] - INFO  [main:ZooKeeper@442] - Initiating client connection, connectString=192.168.36.4:2181,192.168.36.5:2181,192.168.36.2:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5ce65a89
Welcome to ZooKeeper!
JLine support is enabled
2018-12-27 18:20:44,205 [myid:] - INFO  [main-SendThread(192.168.36.2:2181):ClientCnxn$SendThread@1029] - Opening socket connection to server 192.168.36.2/192.168.36.2:2181. Will not attempt to authenticate using SASL (unknown error)
2018-12-27 18:20:44,255 [myid:] - INFO  [main-SendThread(192.168.36.2:2181):ClientCnxn$SendThread@1166] - Socket error occurred: 192.168.36.2/192.168.36.2:2181: Connection refused
[zk: 192.168.36.4:2181,192.168.36.5:2181,192.168.36.2:2181(CONNECTING) 0] 2018-12-27 18:20:44,357 [myid:] - INFO  [main-SendThread(zk1:2181):ClientCnxn$SendThread@1029] - Opening socket connection to server zk1/192.168.36.4:2181. Will not attempt to authenticate using SASL (unknown error)
2018-12-27 18:20:44,357 [myid:] - INFO  [main-SendThread(zk1:2181):ClientCnxn$SendThread@1166] - Socket error occurred: zk1/192.168.36.4:2181: Connection refused
2018-12-27 18:20:44,460 [myid:] - INFO  [main-SendThread(192.168.36.5:2181):ClientCnxn$SendThread@1029] - Opening socket connection to server 192.168.36.5/192.168.36.5:2181. Will not attempt to authenticate using SASL (unknown error)
2018-12-27 18:20:44,463 [myid:] - INFO  [main-SendThread(192.168.36.5:2181):ClientCnxn$SendThread@879] - Socket connection established to 192.168.36.5/192.168.36.5:2181, initiating session
2018-12-27 18:20:44,467 [myid:] - INFO  [main-SendThread(192.168.36.5:2181):ClientCnxn$SendThread@1162] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
2018-12-27 18:20:46,132 [myid:] - INFO  [main-SendThread(192.168.36.2:2181):ClientCnxn$SendThread@1029] - Opening socket connection to server 192.168.36.2/192.168.36.2:2181. Will not attempt to authenticate using SASL (unknown error)
2018-12-27 18:20:46,135 [myid:] - INFO  [main-SendThread(192.168.36.2:2181):ClientCnxn$SendThread@1166] - Socket error occurred: 192.168.36.2/192.168.36.2:2181: Connection refused
2018-12-27 18:20:46,420 [myid:] - INFO  [main-SendThread(zk1:2181):ClientCnxn$SendThread@1029] - Opening socket connection to server zk1/192.168.36.4:2181. Will not attempt to authenticate using SASL (unknown error)
2018-12-27 18:20:46,420 [myid:] - INFO  [main-SendThread(zk1:2181):ClientCnxn$SendThread@1166] - Socket error occurred: zk1/192.168.36.4:2181: Connection refused
2018-12-27 18:20:47,180 [myid:] - INFO  [main-SendThread(192.168.36.5:2181):ClientCnxn$SendThread@1029] - Opening socket connection to server 192.168.36.5/192.168.36.5:2181. Will not attempt to authenticate using SASL (unknown error)
2018-12-27 18:20:47,184 [myid:] - INFO  [main-SendThread(192.168.36.5:2181):ClientCnxn$SendThread@879] - Socket connection established to 192.168.36.5/192.168.36.5:2181, initiating session
2018-12-27 18:20:47,185 [myid:] - INFO  [main-SendThread(192.168.36.5:2181):ClientCnxn$SendThread@1162] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect

    看到上面的报错信息,表示头大有木有?? 信息就是告诉你:连接拒绝,具体怎么拒绝为什么拒绝,这个怎么知道呢?
下面要来看下 日志 ,日志绝对是个好东西!

解决:看Zookeeper的日志

    Zookeeper的日志文件叫做zookeeper.out ,zookeeper的启动信息都会记录到日志文件中,好吧,快把zookeeper.out给各位看官呈上来!
在这里插入图片描述
    看到这个日志信息恍然大悟,jdk的环境变量不对着呢,之前改过jdk的位置,环境变量没有及时更新, 而zookeeper 启动需要Java环境的支持(因为zookeeper使用java写的,它运行在jvm,所以需要jdk)。
    修改环境变量中jdk的位置,再次启动zookeeper ,成功!

总结

     遇到问题没有头绪的时候,学会看日志,自己在编程过程中也要合理利用日志,善假于物!

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐