今天在启动zookeeper的时候,突然无法成功启动zookeeper,总是报Will not attempt to authenticate using SASL (unknown error)错误,这就很困扰
网上找了很多帖子,有说映射有问题的还有其他的,但每个人的问题或许都不再同一个根源上,因此我就附上我个人的解决方法以及网上其他人的一些解决方法
2019-07-05 06:38:33,719 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) 2019-07-05 06:38:33,720 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session 2019-07-05 06:38:33,727 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1158] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2019-07-05 06:38:33,927 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 2019-07-05 06:38:33,927 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2019-07-05 06:38:33,930 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1158] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2019-07-05 06:38:35,677 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) 2019-07-05 06:38:35,678 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session 2019-07-05 06:38:35,685 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1158] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2019-07-05 06:38:36,533 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 2019-07-05 06:38:36,534 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2019-07-05 06:38:36,538 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1158] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2019-07-05 06:38:38,106 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) 2019-07-05 06:38:38,107 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session 2019-07-05 06:38:38,112 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1158] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2019-07-05 06:38:38,881 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 2019-07-05 06:38:38,882 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2019-07-05 06:38:38,889 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1158] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2019-07-05 06:38:40,065 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
首先说说我的解决方法
1.我的本地hosts映射是没问题的 zk的ip和服务器名如下
192.168.4.111 bigdata111
但还是一起报错,接下来我们就可以先检查第二步
2.zookeeper正常启动运行是需要3个以上并且最好是奇数的节点的,所以要检查自己的节点是否开启够数了,接下来就看第三步了
3.要先开启zk服务端,之后再开启客户端
[root@bigdata111 ~]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/software/zookeeper-3.4.10/bin/../conf/zoo.cfg Error contacting service. It is probably not running. [root@bigdata111 ~]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/software/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: follower
当出现下面的代码的时候说明你的zookeeper已经正常开启了
[root@bigdata111 ~]# zkCli.sh Connecting to localhost:2181 2019-07-05 06:42:32,356 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT 2019-07-05 06:42:32,359 [myid:] - INFO [main:Environment@100] - Client environment:host.name=bigdata111 2019-07-05 06:42:32,359 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_144 2019-07-05 06:42:32,367 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2019-07-05 06:42:32,367 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/opt/software/jdk1.8.0_144/jre 2019-07-05 06:42:32,368 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/software/zookeeper-3.4.10/bin/../build/classes:/opt/software/zookeeper-3.4.10/bin/../build/lib/*.jar:/opt/software/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/software/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/opt/software/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/opt/software/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/opt/software/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/opt/software/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/opt/software/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/opt/software/zookeeper-3.4.10/bin/../conf: 2019-07-05 06:42:32,368 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2019-07-05 06:42:32,368 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2019-07-05 06:42:32,368 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler= 2019-07-05 06:42:32,369 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2019-07-05 06:42:32,369 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2019-07-05 06:42:32,369 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-327.el7.x86_64 2019-07-05 06:42:32,369 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2019-07-05 06:42:32,370 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2019-07-05 06:42:32,370 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/root 2019-07-05 06:42:32,372 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@1a86f2f1 2019-07-05 06:42:32,399 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) Welcome to ZooKeeper! JLine support is enabled 2019-07-05 06:42:32,507 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2019-07-05 06:42:32,535 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x16bbf26c41d0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
以上的我的解决方法,下面附带一些其他人的解决方法,每个人的解决方法成功与否因人而异,自己看看哪个方法能解决自己的问题
2016-10-09 02:23:27,292 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=1.1.1.2:2181 sessionTimeout=60000 watcher=org.I0Itec.zkclient.ZkClient@3f74cc4e 2016-10-09 02:23:27,307 INFO [org.I0Itec.zkclient.ZkClient] - Waiting for keeper state SyncConnected 2016-10-09 02:23:32,308 INFO [org.I0Itec.zkclient.ZkEventThread] - Terminate ZkClient event thread. 2016-10-09 02:23:36,665 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server 1.1.1.2/1.1.1.2:2181. Will not attempt to authenticate using SASL (unknown error) 2016-10-09 02:23:36,667 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to 1.1.1.2/1.1.1.2:2181, initiating session 2016-10-09 02:23:36,690 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server 1.1.1.2/1.1.1.2:2181, sessionid = 0x57a5203af30018, negotiated timeout = 40000 2016-10-09 02:23:36,699 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x57a5203af30018 closed 2016-10-09 02:23:36,702 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down 2016-10-09 02:23:36,703 WARN [org.springframework.context.support.ClassPathXmlApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysUserService' defined in file [D:\linux_shared\myjavaproject\system_interchange\bhz-sys-service\target\classes\bhz\sys\service\SysUserService.class]: Initialization of bean failed; nested exception is org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 5000 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
最后发现是尝试,在我自己程序运行端(也就是java程序跑的所在机器,我自己的笔记本电脑上,加入了zk服务器的ip和服务器名映射关系,没想到竟然解决了,我只能说操蛋啊,查了几个小时,因为是spring或者是程序配置问题,主要引起我注意的是Will not attempt to authenticate using SASL (unknown error)那句。。。)
1.这里1.1.1.2是zk的服务器端IP地址,我在服务器上也配置了1.1.1.2和服务器本机的IP地址映射关系,不然也可以出问题
2.在 C:\Windows\System32\drivers\etc\hosts 里加入 1.1.1.2 ubuntu16这句话,问题就解决了。。。
3.补充一下,发现zk服务器端不配置映射关系似乎也可以用,但是zk客户端,是一定要配置的
看东西要仔细一点,如果你的zk客户端运行的是在windows上,那么就按照博客里倒数第二句话的来做就行了,把1.1.1.2 这个IP替换成为你ZK服务器的IP,ubuntu16这个服务器名字替换为你zk服务器的实际名字就行了.如果是linux的话,你搜一下linux配置主机名,步骤都差不多