zkCli.sh Connecting to localhost:2181 2020-07-25 01:57:14,474 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT 2020-07-25 01:57:14,477 [myid:] - INFO [main:Environment@100] - Client environment:host.name=iZ2zedageorhjtf8gte9kyZ 2020-07-25 01:57:14,477 [myid:] - INFO [main:Environment@100] - Client environment:java.version=14.0.1 2020-07-25 01:57:14,479 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2020-07-25 01:57:14,479 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/java/jdk-14.0.1 2020-07-25 01:57:14,479 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/soft/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/opt/soft/zookeeper-3.4.14/bin/../build/classes:/opt/soft/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/.jar:/opt/soft/zookeeper-3.4.14/bin/../build/lib/.jar:/opt/soft/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/soft/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/opt/soft/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/opt/soft/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/opt/soft/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/opt/soft/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/opt/soft/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/opt/soft/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/soft/zookeeper-3.4.14/bin/../conf:/usr/local/java/jdk-14.0.1/lib/ 2020-07-25 01:57:14,479 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=:/usr/local/lib:/usr/local/rocksdb/lib64/:/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler= 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-1062.18.1.el7.x86_64 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2020-07-25 01:57:14,480 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/soft/zookeeper-3.4.14/zookeeper-server/src/main/java/org/apache/zookeeper 2020-07-25 01:57:14,491 [myid:] - INFO [main:ZooKeeper@442] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@256216b3 Welcome to ZooKeeper! JLine support is enabled 2020-07-25 01:57:14,601 [myid:] - WARN [main-SendThread(localhost:2181):ClientCnxn$SendThread@1164] - Session 0x0 for server localhost/ :2181, unexpected error, closing socket connection and attempting reconnect java.lang.IllegalArgumentException: Unable to canonicalize address localhost/ :2181 because it's not resolvable at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:65) at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:41) at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1001) at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1060)
在配置zookeeper集群后,zkServer.sh查看status状态可以启动成功,但是用zkCli.sh操作时连接不上。 一直提示Session 0x0 for server localhost/ :2181, unexpected error, closing socket connection and attempting reconnect java.lang.IllegalArgumentException: Unable to canonicalize address localhost/ :2181 because it's not resolvable 看了一下源码,好像看起来像是没有获取到服务器列表???????有大神指导一下么
首先希望大家明白一个道理,zookeeper集群搭建在多台机器上,那么是不是只要启动一台电脑上上的zookeeper客户端就行了呢?答案是否定的,zookeeper集群要启动半数以上才可以正常工作,如果没超过半数也会出现java.net.ConnectException: 拒绝连接这个错误。这一点大家切记。
2 确定zoo.cfg中dataDir,dataLogDir两个参数配置正确。首先进入相应的目录
cd /usr/local/zookeeper/conf/
使用vi编辑器编辑相应的参数
vi zoo.cfg
3 将dataDir,dataLogDir两个参数配置正确
dataDir=/usr/local/temp/zookeeper dataLogDir=/usr/local/temp/zookeeper/logs
请注意上面的temp,zookeeper,logs均是小编自己创建的,如果这几个文件夹没有创建也有可能会出现java.net.ConnectException: 拒绝连接这个错误。
4 第三步完成之后,你可以启动半数以上的服务器运行./zkCli.sh,看一下zookeeper客户端是否启动正常,如果出现错误那么往下看
5 修改/etc/hosts文件,将第一行注释掉。然后启动半数以上的服务器运行./zkCli.sh,这次zookeeper客户端应该是可以完美运行。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。