记一次docker安装kafka,zookeeper拒绝连接的问题
kafka的启动参数KAFKA_ZOOKEEPER_CONNECT不能是localhost:2181,因为不是在一个容器中,localhost改为ip地址就可以了。确保 ZooKeeper 容器中的 /conf 目录中存在 log4j.properties 配置文件。nc 命令连接到 localhost:2181,确保ZooKeeper 服务器正在监听该地址,并且可以通过网络进行访问。如果 log
·
第一次玩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条内容
所有评论(0)