Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
注册配置 MSE Nacos/ZooKeeper,118元/月
日志服务 SLS,月写入数据量 50GB 1个月
简介: Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)

1d90c10e9a4e45058012c73af45f578a.png文章目录


个人简介

一、业务场景:报错kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING

二、错误日志:Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)

三、解决方案

总结

一键三连

给读者大大的话

博客封面

面试资料

200套PPT模板

提问的智慧

Java开发学习路线


个人简介

我是廖志伟,一名Java开发工程师,CSDN博客专家,Java领域优质创作者,《幕后大佬》社区创始人,《南北踏尘》微信公众号创始人。多年一线研发经验,曾就职多家互联网公司,参与并主导多个百万级并发的互联网产品研发与系统架构搭建,对大型分布式,高并发及微服务架构,缓存框架有非常深入的研究,对于中间件底层,架构搭建,系统调优颇多经验。


博主:java_wxid

社区:幕后大佬



本文的大概内容:


一、业务场景:报错


kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING

我通过docker命令启动kafka,进入kafka容器之后,过一二秒没做操作,就出现退出容器的情况,通过zookeeper客户端连接kafka配置的zookeeper发现可以连接的上,但是查看kafka日志却报错kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING


二、错误日志:Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)


7ccca8b4fb9941908bd893d464315c25.png


[2021-11-16 13:39:02,215] INFO Client environment:os.memory.max=1024MB (org.apache.zookeeper.ZooKeeper)
[2021-11-16 13:39:02,215] INFO Client environment:os.memory.total=1024MB (org.apache.zookeeper.ZooKeeper)
[2021-11-16 13:39:02,219] INFO Initiating client connection, connectString=106.14.132.94:2181 sessionTimeout=18000 watcher=kafka.zookeeper.ZooKeeperClient$ZooKeeperClientWatcher$@4466af20 (org.apache.zookeeper.ZooKeeper)
[2021-11-16 13:39:02,241] INFO jute.maxbuffer value is 4194304 Bytes (org.apache.zookeeper.ClientCnxnSocket)
[2021-11-16 13:39:02,248] INFO zookeeper.request.timeout value is 0. feature enabled= (org.apache.zookeeper.ClientCnxn)
[2021-11-16 13:39:02,256] INFO [ZooKeeperClient Kafka server] Waiting until connected. (kafka.zookeeper.ZooKeeperClient)
[2021-11-16 13:39:12,261] INFO Opening socket connection to server 106.14.132.94/106.14.132.94:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2021-11-16 13:39:12,268] INFO Socket error occurred: 106.14.132.94/106.14.132.94:2181: Host is unreachable (org.apache.zookeeper.ClientCnxn)
[2021-11-16 13:39:20,258] INFO [ZooKeeperClient Kafka server] Closing. (kafka.zookeeper.ZooKeeperClient)
[2021-11-16 13:39:23,377] INFO Opening socket connection to server 106.14.132.94/106.14.132.94:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2021-11-16 13:39:23,482] INFO Session: 0x0 closed (org.apache.zookeeper.ZooKeeper)
[2021-11-16 13:39:23,483] INFO EventThread shut down for session: 0x0 (org.apache.zookeeper.ClientCnxn)
[2021-11-16 13:39:23,485] INFO [ZooKeeperClient Kafka server] Closed. (kafka.zookeeper.ZooKeeperClient)
[2021-11-16 13:39:23,492] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
  at kafka.zookeeper.ZooKeeperClient.waitUntilConnected(ZooKeeperClient.scala:262)
  at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:119)
  at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1881)
  at kafka.server.KafkaServer.createZkClient$1(KafkaServer.scala:441)
  at kafka.server.KafkaServer.initZkClient(KafkaServer.scala:466)
  at kafka.server.KafkaServer.startup(KafkaServer.scala:233)
  at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:44)
  at kafka.Kafka$.main(Kafka.scala:82)
  at kafka.Kafka.main(Kafka.scala)
[2021-11-16 13:39:23,496] INFO shutting down (kafka.server.KafkaServer)
[2021-11-16 13:39:23,502] INFO App info kafka.server for 0 unregistered (org.apache.kafka.common.utils.AppInfoParser)
[2021-11-16 13:39:23,503] INFO shut down completed (kafka.server.KafkaServer)
[2021-11-16 13:39:23,503] ERROR Exiting Kafka. (kafka.server.KafkaServerStartable)
[2021-11-16 13:39:23,506] INFO shutting down (kafka.server.KafkaServer)


由于kafka运行是通过docker镜像的方式运行的,而且zookeeper外部的客户端也可以连接上zookeeper就排除了,zookeeper的异常情况,那么剩下的只可能是kafka运行的命令出问题了,我之前的运行命令如下:


docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=106.14.132.94:2181 \
-e KAFKA_ADVERTISED_HOST_NAME=106.14.132.94 \
-e KAFKA_ADVERTISED_PORT=9092 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://106.14.132.94:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
-v /etc/localtime:/etc/localtime \
-t wurstmeister/kafka


把监听的0.0.0.0改成服务器ip地址

docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=106.14.132.94:2181 \
-e KAFKA_ADVERTISED_HOST_NAME=106.14.132.94 \
-e KAFKA_ADVERTISED_PORT=9092 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://106.14.132.94:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://106.14.132.94:9092 \
-v /etc/localtime:/etc/localtime \
-t wurstmeister/kafka


但是还是有出错的情况:

Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)

Host is unreachable (org.apache.zookeeper.ClientCnxn)


bccd090cb40545cebd0f487196a70af4.png


[2021-11-16 15:20:11,821] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:os.version=5.10.60-9.al8.x86_64 (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:user.dir=/ (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:os.memory.free=973MB (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:os.memory.max=1024MB (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,821] INFO Client environment:os.memory.total=1024MB (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,838] INFO Initiating client connection, connectString=106.14.132.94:2181 sessionTimeout=18000 watcher=kafka.zookeeper.ZooKeeperClient$ZooKeeperClientWatcher$@4466af20 (org.apache.zookeeper.ZooKeeper)
[2021-11-16 15:20:11,857] INFO jute.maxbuffer value is 4194304 Bytes (org.apache.zookeeper.ClientCnxnSocket)
[2021-11-16 15:20:11,864] INFO zookeeper.request.timeout value is 0. feature enabled= (org.apache.zookeeper.ClientCnxn)
[2021-11-16 15:20:11,871] INFO [ZooKeeperClient Kafka server] Waiting until connected. (kafka.zookeeper.ZooKeeperClient)
[2021-11-16 15:20:21,879] INFO Opening socket connection to server 106.14.132.94/106.14.132.94:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2021-11-16 15:20:21,885] INFO Socket error occurred: 106.14.132.94/106.14.132.94:2181: Host is unreachable (org.apache.zookeeper.ClientCnxn)


奇怪的是zookeeper的节点有kafka相关的数据了


5d8b83f176a3487c91d7e23e277be8f2.png

SASL全称Simple Authentication and Security Layer,是一种用来扩充C/S模式验证能力的机制。


三、解决方案


网上百度了一堆没用的,我一一列举出来

第一个说是通过官网发现,在zookeeper 3.4.5之前,sasl认证是没有办法规避的,在3.4.6版本后修复了这个bug,因为不停的去检测认证虽然对功能没有什么影响,但是比较耗费服务器性能,比较占用容器资源。zk升级到3.4.6+的版本,可我的版本是zookeeper-3.4.13,肯定是符合的,无效。

第二个说是让zookeeper绕过sasl安全机制,禁用sasl认证,直接向系统获取资源。在conf目录下的zoo.cfg文件添加配置,zookeeper.sasl.client=false,然后重启zookeeper,亲身试过,无效。

第三个说是端口开放的问题,防火墙啊,入口和出口规则限制啊,这些符合,因为我可以通过客户端工具连接zookeeper,所以不存在端口问题,无效。

第四个说是给zookeeper做安全配置,但是我的初衷是对Kafka客户端使用SASL身份验证,但不要求kafka对Zookeeper进行SASL身份验证,我不关心kafka < - > zookeeper之间的安全校验问题,我就想单纯的通过docker进行运行kafka,可以让我进到容器内部进行测试发送消息。所以我还在寻找绕开sasl认证的办法,通过在apache bug管理官网:https://issues.apache.org/jira/browse/ZOOKEEPER-1657,我大致看了看还是和上面类似的解决方案。


51b89d42d1b0412b830f5f97de895b16.png

大致的意思就跟第一个说的差不多,不停的去检测认证虽然对功能没有什么影响,但是比较耗费服务器性能,比较占用容器资源。

下面的解决方案也如出一辙。


fec8992070f84f8ba827d19b142531ef.png

除此之外,还发现了一篇帖子的解决方案也大体相同

8b08ce5d2cc64f8a9d55b8bff184655b.png

只不过我都尝试过,发现都不起效果。

然后我去查看有关SASL配置项

X509AuthenticationProvider.superUser:Java系统属性:zookeeper.X509AuthenticationProvider.superUser)支持SSL的方法,使ZooKeeper集合管理员能够以“超级”用户身份访问znode层次结构。当此参数设置为X500主体名称时,只有具有该主体的经过身份验证的客户端才能绕过ACL检查并拥有所有znode的完全权限。

zookeeper.superUser:Java系统属性:zookeeper.superUser)与zookeeper.X509AuthenticationProvider.superUser类似,但对于基于SASL的登录是通用的。它存储可以作为“超级”用户访问znode层次结构的用户的名称。


看了这些配置,发现并没什么作用。到这里我基本放弃了绕开sasl认证的办法了,网上也找不到更多有用的消息,还不如老老实实的配置安全认证,这里我参考了二篇博文,第一篇是集群模式的:https://blog.csdn.net/sdksdk0/article/details/95336382,第二篇是https://www.orchome.com/553。又熬到快十二点半了,熬不动了,睡觉睡觉,希望有大神可以帮忙解决这个绕开sasl认证的问题,至于权限认证的问题,等也时间再慢慢实现。这里我提供kafka和zookeeper的启动命令给大神作参考。

具体实现可参考:https://liaozhiwei.blog.csdn.net/article/details/120716913


早上起床接着排查

第五个说的是zookeeper客户端 和服务器连接时版本问题,不过我并没有用程序连接,无效


492f32c894774508b27e8d4e8d8ebd69.png


第六个说的是zookeeper服务器主动断开与客户端的连接问题,修改配置,无效


6c1a412930254b2b8b7d480bd75200f4.png


这个时候我去看了看zookeeper的日志信息,发现也报错了


a0e47550f60a4693bd27872efbc4bf3b.png


这个时候,我将之前改过的配置都还原,把原有的镜像都删除,重新启动docker运行镜像

kafka

docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=106.14.132.94:2181 \
-e KAFKA_ADVERTISED_HOST_NAME=106.14.132.94 \
-e KAFKA_ADVERTISED_PORT=9092 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://106.14.132.94:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://106.14.132.94:9092 \
-v /etc/localtime:/etc/localtime \
-t wurstmeister/kafka


zookeeper

docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2  --name zookeeper \
-p 2181:2181 \
-v /etc/localtime:/etc/localtime \
-t wurstmeister/zookeeper


然后发现zookeeper的错误信息日志


b7f3ea712f1f40998c0701e5ca5150b9.png


2021-11-18 00:11:05,537 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@922] - Refusing session request for client /114.87.234.228:57390 as it has seen zxid 0x7 our last zxid is 0x0 client must try another server
2021-11-18 00:11:05,537 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57390 (no session established for client)
2021-11-18 00:11:07,162 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57843
2021-11-18 00:11:07,162 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@922] - Refusing session request for client /114.87.234.228:57843 as it has seen zxid 0x7 our last zxid is 0x0 client must try another server
2021-11-18 00:11:07,163 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57843 (no session established for client)
2021-11-18 00:11:09,310 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57534
2021-11-18 00:11:09,318 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@922] - Refusing session request for client /114.87.234.228:57534 as it has seen zxid 0x7 our last zxid is 0x0 client must try another server
2021-11-18 00:11:09,318 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57534 (no session established for client)
2021-11-18 00:11:10,942 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57699
2021-11-18 00:11:10,943 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@922] - Refusing session request for client /114.87.234.228:57699 as it has seen zxid 0x7 our last zxid is 0x0 client must try another server
2021-11-18 00:11:10,943 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57699 (no session established for client)
2021-11-18 00:11:12,684 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57568
2021-11-18 00:11:12,695 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@922] - Refusing session request for client /114.87.234.228:57568 as it has seen zxid 0x7 our last zxid is 0x0 client must try another server
2021-11-18 00:11:12,696 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57568 (no session established for client)
2021-11-18 00:11:14,703 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57601
2021-11-18 00:11:14,743 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@922] - Refusing session request for client /114.87.234.228:57601 as it has seen zxid 0x7 our last zxid is 0x0 client must try another server
2021-11-18 00:11:14,743 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57601 (no session established for client)
2021-11-18 00:11:15,412 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57800
2021-11-18 00:11:15,414 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@949] - Client attempting to establish new session at /114.87.234.228:57800
2021-11-18 00:11:15,416 [myid:] - INFO  [SyncThread:0:FileTxnLog@213] - Creating new log file: log.1
2021-11-18 00:11:15,427 [myid:] - INFO  [SyncThread:0:ZooKeeperServer@694] - Established session 0x100137139d30000 with negotiated timeout 5000 for client /114.87.234.228:57800
2021-11-18 00:11:16,843 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@487] - Processed session termination for sessionid: 0x100137139d30000
2021-11-18 00:11:16,845 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57800 which had sessionid 0x100137139d30000
2021-11-18 00:11:17,354 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57488
2021-11-18 00:11:17,354 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@949] - Client attempting to establish new session at /114.87.234.228:57488
2021-11-18 00:11:17,356 [myid:] - INFO  [SyncThread:0:ZooKeeperServer@694] - Established session 0x100137139d30001 with negotiated timeout 5000 for client /114.87.234.228:57488
2021-11-18 00:11:18,817 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@487] - Processed session termination for sessionid: 0x100137139d30001
2021-11-18 00:11:18,819 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57488 which had sessionid 0x100137139d30001
2021-11-18 00:11:19,344 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57417
2021-11-18 00:11:19,355 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@949] - Client attempting to establish new session at /114.87.234.228:57417
2021-11-18 00:11:19,357 [myid:] - INFO  [SyncThread:0:ZooKeeperServer@694] - Established session 0x100137139d30002 with negotiated timeout 5000 for client /114.87.234.228:57417
2021-11-18 00:14:25,024 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@487] - Processed session termination for sessionid: 0x100137139d30002
2021-11-18 00:14:25,026 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /114.87.234.228:57417 which had sessionid 0x100137139d30002
2021-11-18 00:14:25,730 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /114.87.234.228:57403
2021-11-18 00:14:25,731 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@949] - Client attempting to establish new session at /114.87.234.228:57403
2021-11-18 00:14:25,733 [myid:] - INFO  [SyncThread:0:ZooKeeperServer@694] - Established session 0x100137139d30003 with negotiated timeout 5000 for client /114.87.234.228:57403


zookeeper客户端连接的截图


2382ced14a3a42a7bcac8d3c7d9844e4.png


kafka的日志


60657ddf90d44d6ab5d9f17318cbea21.png


[2021-11-18 00:18:27,177] INFO Client environment:java.library.path=/usr/lib/jvm/zulu8-ca/jre/lib/amd64/server:/usr/lib/jvm/zulu8-ca/jre/lib/amd64:/usr/lib/jvm/zulu8-ca/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,177] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:os.version=5.10.60-9.al8.x86_64 (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:user.dir=/ (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:os.memory.free=973MB (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:os.memory.max=1024MB (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,178] INFO Client environment:os.memory.total=1024MB (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,182] INFO Initiating client connection, connectString=106.14.132.94:2181 sessionTimeout=18000 watcher=kafka.zookeeper.ZooKeeperClient$ZooKeeperClientWatcher$@4466af20 (org.apache.zookeeper.ZooKeeper)
[2021-11-18 00:18:27,215] INFO jute.maxbuffer value is 4194304 Bytes (org.apache.zookeeper.ClientCnxnSocket)
[2021-11-18 00:18:27,223] INFO zookeeper.request.timeout value is 0. feature enabled= (org.apache.zookeeper.ClientCnxn)
[2021-11-18 00:18:27,226] INFO [ZooKeeperClient Kafka server] Waiting until connected. (kafka.zookeeper.ZooKeeperClient)


进入容器内部发送消息


`bash-5.1# ./kafka-console-producer.sh --broker-list 106.14.132.94:9092 --topic sun


[2021-11-18 00:17:06,318] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:06,319] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:06,413] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:06,414] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:06,514] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:06,514] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:06,715] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:06,716] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:08,276] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:08,276] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:09,031] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:09,031] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:11,092] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:11,092] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:13,012] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:13,012] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:14,017] WARN [Producer clientId=console-producer] Connection to node -1 (/106.14.132.94:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

[2021-11-18 00:17:14,017] WARN [Producer clientId=console-producer] Bootstrap broker 106.14.132.94:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)

`


又找了找,还是没什么用


f27399f610db4d399fda10633d85ff91.png


用netstat查看网络连接状态

netstat -antp | grep 2181


用tcpdump抓包和wireshark分析

tcpdump -vv host 106.14.132.94 and port 2181 -w 2181.cap
tcpdump -r 2181.cap


a6757825911c4981b353598485acb9af.png


f3ebb3db440041479ff225b5840d3e42.png


没有发现什么有用信息,这个时候原来的sasl认证的错误信息没有了,出现了新的问题。

zookeeper还是老样子,可以连接上


3879fca6309548538d103faf99181f55.png


后续发现将命令绑定的ip替换成内网ip就好了,因为不用内网会出现以下的这种情况


3faa8b800b454ef0ab9a95ef77594afc.png


这个时候删除重来,命令如下:

docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
firewall-cmd --add-port=8010/tcp --permanent
firewall-cmd --add-port=8011/tcp --permanent
firewall-cmd --reload
systemctl restart docker
firewall-cmd --query-port=2181/tcp
firewall-cmd --query-port=9092/tcp
docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2  --name zookeeper \
-p 2181:2181 \
-v /etc/localtime:/etc/localtime \
-t wurstmeister/zookeeper
docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=172.21.17.47:2181 \
-e KAFKA_ADVERTISED_HOST_NAME=172.21.17.47 \
-e KAFKA_ADVERTISED_PORT=9092 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.21.17.47:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://172.21.17.47:9092 \
-v /etc/localtime:/etc/localtime \
-t wurstmeister/kafka


然后又出现下面的这种情况了:Opening socket connection to server 172.21.17.47/172.21.17.47:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)


ce353934014e451588ebac3b910f66f7.png


又回到一开始的问题了,Will not attempt to authenticate using SASL 但是发现截图好像是多了一个ip地址:

104858de51b445e9a9af5f961e8b7aa8.png


后面发现我的启动kafka的命令中配置错了,kafka的启动命令多加了二行配置

-e KAFKA_ADVERTISED_HOST_NAME=172.21.17.47 \
-e KAFKA_ADVERTISED_PORT=9092 \


调整后的整套启动命令

docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
firewall-cmd --add-port=2181/tcp --permanent
firewall-cmd --add-port=9092/tcp --permanent
firewall-cmd --reload
systemctl restart docker
firewall-cmd --query-port=2181/tcp
firewall-cmd --query-port=9092/tcp
docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2  --name zookeeper \
-p 2181:2181 \
-v /etc/localtime:/etc/localtime \
-t wurstmeister/zookeeper
docker run -dit --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=172.21.17.47:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.21.17.47:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka


然后进入kafka容器进行校验

cd /opt/kafka_2.13-2.7.1
bin/kafka-topics.sh --create --zookeeper 106.14.132.94:2181 --replication-factor 1 --partitions 1 --topic mymytest
bin/kafka-topics.sh --list --zookeeper 106.14.132.94:2181
bin/kafka-console-producer.sh --broker-list 106.14.132.94:9092 --topic mytest 
bin/kafka-console-consumer.sh --bootstrap-server 106.14.132.94:9092--topic mytest
bin/kafka-console-consumer.sh --bootstrap-server 106.14.132.94:9092 --from-beginning --topic mytest


1d90c10e9a4e45058012c73af45f578a.png

到此,这个问题彻底解决了,这个错误提示真的很误导人,同时也没有出现需要绕开zookeeper的sasl认证机制的错误了,一切都是细节。


总结

以上就是今天要讲的内容,还希望各位读者大大能够在评论区积极参与讨论,给文章提出一些宝贵的意见或者建议,合理的内容,我会采纳更新博文,重新分享给大家。


一键三连

感谢大家的支持,用心写博文分享给大家,你的支持(点赞、收藏、关注)是对我创作的最大帮助。

微信公众号:南北踏尘

主页地址:https://blog.csdn.net/java_wxid

社区地址:https://bbs.csdn.net/forums/liaozhiwei


给读者大大的话

我本身是一个很普通的程序员,放在人堆里,除了与生俱来的盛世美颜、所剩不多的发量,就剩下180的大高个了。就是我这样的一个人,默默坚持写博文也有好多年了,有句老话说的好,牛逼之前都是傻逼式的坚持。希望自己可以通过大量的作品,时间的积累,个人魅力、运气和时机,可以打造属于自己的技术影响力。


提示:以下都是资源分享,求个一键三连。

博客封面

首先我要说声抱歉,作为一个学习的平台,博客封面太诱人,这样做是不好滴,但是为了让你点进来这篇博客,看到了我用心编写的博文内容,就博文质量而已,没有任何灌水的情况,也未出现与技术不相干的内容,咱们看博客,不就是看博文内容嘛,所以个人觉得还是值得的。有不少同学惦记着我博客的封面,这里也分享出来给大家,我就求个一键三连,拜托了,这对我真的很重要。

链接:https://pan.baidu.com/s/1Res9qVUKRCAqgqwTIfdM2g

提取码:2021


面试资料

福利大放送,我就求个一键三连,拜托了,这对我真的很重要。

链接:https://pan.baidu.com/s/1FycGBqVQ1xbgSpU1MBAYNQ

提取码:2021


200套PPT模板

福利大放送,我就求个一键三连,拜托了,这对我真的很重要。

链接:https://pan.baidu.com/s/16o6dtRebtBJYfb68BYaIbw

提取码:2021


提问的智慧

福利大放送,我就求个一键三连,拜托了,这对我真的很重要。

链接:https://pan.baidu.com/s/1OWTWYNpajosALT3yIH-eMQ

提取码:2021

相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
相关文章
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.
|
4月前
|
消息中间件 前端开发 Kafka
【Azure 事件中心】使用Apache Flink 连接 Event Hubs 出错 Kafka error: No resolvable bootstrap urls
【Azure 事件中心】使用Apache Flink 连接 Event Hubs 出错 Kafka error: No resolvable bootstrap urls
|
7月前
|
Java 数据库连接 mybatis
解决Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found
解决Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found
337 1
|
6月前
|
Oracle 关系型数据库 Shell
实时计算 Flink版操作报错合集之遇到报错:Error: Could not find or load main class org.apache.flink.cdc.cli.CliFrontend,是什么导致的
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
210 0
|
Java
【Java异常】Error:(30, 62) java: 程序包com.sun.org.apache.xerces.internal.impl.dv.util不存在
【Java异常】Error:(30, 62) java: 程序包com.sun.org.apache.xerces.internal.impl.dv.util不存在
1342 0
|
7月前
|
SQL 分布式计算 资源调度
[已解决]FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask. Unable to
[已解决]FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask. Unable to
345 0
|
7月前
|
SQL 分布式计算 Hadoop
【已解决[ERROR] Could not execute SQL statement. Reason:java.lang.ClassNotFoundException: org.apache.had
【已解决[ERROR] Could not execute SQL statement. Reason:java.lang.ClassNotFoundException: org.apache.had
364 0
|
XML Java 数据库连接
MyBatis参数映射问题解决教程: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 wit
MyBatis参数映射问题解决教程: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 wit
985 1
|
缓存 Java 编译器
【Java异常】Error:(19, 21) java: 无法访问org.apache.poi.xwpf.usermodel.ParagraphAlignment 找不到org.apache.po
【Java异常】Error:(19, 21) java: 无法访问org.apache.poi.xwpf.usermodel.ParagraphAlignment 找不到org.apache.po
382 0
|
Java 数据库连接 数据库
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.问题的解决
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.问题的解决
258 0

热门文章

最新文章

推荐镜像

更多