记一次docker安装kafka,zookeeper拒绝连接的问题

在使用Docker安装Kafka时,由于KAFKA_ZOOKEEPER_CONNECT设置为localhost:2181导致连接被拒绝。问题解决方法是将localhost替换为ZooKeeper容器的IP地址。同时,ZooKeeper的日志显示缺少log4j.properties配置文件,需确保该文件存在于容器的/conf目录下,以正确初始化日志系统。
摘要由CSDN通过智能技术生成

第一次玩kafka,在使用docker安装kafka时,出现了如下问题
kafka的启动参数KAFKA_ZOOKEEPER_CONNECT不能是localhost:2181,因为不是在一个容器中,localhost改为ip地址就可以了

[2023-06-20 01:37:30,009] INFO Socket error occurred: localhost/127.0.0.1:2181: Connection refused (org.apache.zookeeper.ClientCnxn)
[2023-06-20 01:37:31,111] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2023-06-20 01:37:31,112] INFO Socket error occurred: localhost/127.0.0.1:2181: Connection refused (org.apache.zookeeper.ClientCnxn)
[2023-06-20 01:37:31,453] INFO [ZooKeeperClient Kafka server] Closing. (kafka.zookeeper.ZooKeeperClient)
[2023-06-20 01:37:32,213] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2023-06-20 01:37:32,323] INFO Session: 0x0 closed (org.apache.zookeeper.ZooKeeper)
[2023-06-20 01:37:32,328] INFO EventThread shut down for session: 0x0 (org.apache.zookeeper.ClientCnxn)
[2023-06-20 01:37:32,330] INFO [ZooKeeperClient Kafka server] Closed. (kafka.zookeeper.ZooKeeperClient)
[2023-06-20 01:37:32,340] 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:271)
        at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:125)
        at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1948)
        at kafka.server.KafkaServer.createZkClient$1(KafkaServer.scala:431)
        at kafka.server.KafkaServer.initZkClient(KafkaServer.scala:456)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:191)
        at kafka.Kafka$.main(Kafka.scala:109)
        at kafka.Kafka.main(Kafka.scala)
[2023-06-20 01:37:32,349] INFO shutting down (kafka.server.KafkaServer)
[2023-06-20 01:37:32,368] INFO App info kafka.server for 0 unregistered (org.apache.kafka.common.utils.AppInfoParser)
[2023-06-20 01:37:32,369] INFO shut down completed (kafka.server.KafkaServer)
[2023-06-20 01:37:32,369] ERROR Exiting Kafka. (kafka.Kafka$)
[2023-06-20 01:37:32,372] INFO shutting down (kafka.server.KafkaServer)

nc 命令连接到 localhost:2181,确保ZooKeeper 服务器正在监听该地址,并且可以通过网络进行访问

nc -vz localhost 2181

定位的过程中还遇到了其他问题,同做记录:
zookeeper日志问题

[root@hn conf]# docker logs zookeeper
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.server.quorum.QuorumPeerConfig).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

确保 ZooKeeper 容器中的 /conf 目录中存在 log4j.properties 配置文件。可以使用以下命令进入容器的 shell:

docker exec -it zookeeper bash

然后检查 /conf 目录中是否存在 log4j.properties 文件。

如果 log4j.properties 文件不存在,可以在宿主机上创建一个,并将其复制到容器中。

以下是一个示例 log4j.properties 配置文件的内容:

log4j.rootLogger=INFO, console

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值