Kafka 2.11-1.0.0启动报错,连接到zookeeper超时

docker 发表于: 2018-01-02   最后更新时间: 2021-10-18 16:14:23   47,406 游览

server.properties配置

broker.id=0
listeners = PLAINTEXT://127.0.0.1:9092
port=9092
advertised.listeners = PLAINTEXT://127.0.0.1:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=C:\Product-Files\apache\kafkas\kafka_2.11-1.0.0\config\tmp\kafka-logs
num.partitions=4
num.recovery.threads.per.data.dir=1
metadata.broker.list=127.0.0.1:9092
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=127.0.0.1:2181
zookeeer.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0

zk配置信息

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
#数据目录
dataDir=C:\Product-Files\apache\zookeepers\zookeeper-3.4.10\data
#日志目录
dataLogDir=C:\Product-Files\apache\zookeepers\zookeeper-3.4.10\log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
maxClientCnxns=10
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

kafka报错信息

[2018-01-02 11:25:56,190] FATAL Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server '127.0.0.1:2181' with timeout of 6000 ms
        at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:1233)
        at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:157)
        at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:131)
        at kafka.utils.ZkUtils$.createZkClientAndConnection(ZkUtils.scala:115)
        at kafka.utils.ZkUtils$.withMetrics(ZkUtils.scala:92)
        at kafka.server.KafkaServer.initZk(KafkaServer.scala:346)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:194)
        at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
        at kafka.Kafka$.main(Kafka.scala:92)
        at kafka.Kafka.main(Kafka.scala)
[2018-01-02 11:25:56,191] INFO EventThread shut down for session: 0x0 (org.apache.zookeeper.ClientCnxn)
[2018-01-02 11:25:56,200] INFO shutting down (kafka.server.KafkaServer)
[2018-01-02 11:25:56,218] INFO shut down completed (kafka.server.KafkaServer)
[2018-01-02 11:25:56,219] FATAL Exiting Kafka. (kafka.server.KafkaServerStartable)
[2018-01-02 11:25:56,225] INFO shutting down (kafka.server.KafkaServer)

zk console信息

2018-01-02 11:35:39,532 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@373] - Exception causing close of session 0x160b4e45e5c0004 due to java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
2018-01-02 11:35:39,537 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1044] - Closed socket connection for client /127.0.0.1:54579 which had sessionid 0x160b4e45e5c0004
2018-01-02 11:35:46,000 [myid:] - INFO  [SessionTracker:ZooKeeperServer@358] - Expiring session 0x160b4e45e5c0001, timeout of 6000ms exceeded
2018-01-02 11:35:48,994 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@486] - Processed session termination for sessionid: 0x160b4e45e5c0001
2018-01-02 11:36:10,000 [myid:] - INFO  [SessionTracker:ZooKeeperServer@358] - Expiring session 0x160b4e45e5c0004, timeout of 30000ms exceeded
2018-01-02 11:36:10,000 [myid:] - INFO  [SessionTracker:ZooKeeperServer@358] - Expiring session 0x160b4e45e5c0002, timeout of 30000ms exceeded
2018-01-02 11:36:10,000 [myid:] - INFO  [SessionTracker:ZooKeeperServer@358] - Expiring session 0x160b4e45e5c0003, timeout of 30000ms exceeded
2018-01-02 11:36:10,001 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@486] - Processed session termination for sessionid: 0x160b4e45e5c0004
2018-01-02 11:36:10,001 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@486] - Processed session termination for sessionid: 0x160b4e45e5c0002
2018-01-02 11:36:10,001 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@486] - Processed session termination for sessionid: 0x160b4e45e5c0003
发表于 2018-01-02
添加评论

楼主问题时怎么解决的

在kafka的配置中(server.properties) 把连接zookeeper的超时时间改久些就可以了 在server.properties 中加入以下配置 zookeeper.connection.timeout.ms=6000000 如果已经存在这个配置 就直接修改值

检查你的zookeeper的myid和kafka的brokerid,我是虚拟机克隆的忘记改了,报了一样的错误

你要再看看你的生产者和消费者配置文件里的端口号,创建代码是2181  9092 我记得是不一样的,我之前也和你一样

已经解决,办法是请执行一遍,zookeeper的关闭命令:
1、如果是kafka自带的,执行\bin\windows\zookeeper-server-stop.bat
2、如果是自行安装zookeeper,。。。。。(自行网上查查标准的关闭zookeeper命令)

你的zookeeper是在本机吗?

docker -> 半兽人 7年前

在本机的,我用kafka内置的zk就不报错,用自己搭的zk环境就出错

半兽人 -> docker 7年前

telnet通吗?

docker -> 半兽人 7年前

开启zk,无论是外部搭建还是内置zk执行该命令(telnet 127.0.0.1:2181)都出现: 正在连接127.0.0.1:2181...无法打开到主机的连接。 在端口 23: 连接失败

半兽人 -> docker 7年前

telnet 127.0.0.1 2181
要空格的。

docker -> 半兽人 7年前

可以....

半兽人 -> docker 7年前

你配置的没错,我怀疑你zk没起来

docker -> 半兽人 7年前

可能是你说的这个,但是我遇到另外一个问题,就是每次重启zk和kafka时,先启动zk再启动kafka会报:另一个程序正在使用此文件,进程无法访问。

[2018-01-03 09:44:49,013] WARN Found a corrupted index file due to requirement failed: Corrupt index found, index file (C:\Product-Files\apache\kafkas\kafka_2.11-1.0.0\config\tmp\kafka-logs\secondTopic-2\00000000000000000000.index) has non-zero size but the last offset is 0 which is no larger than the base offset 0.}. deleting C:\Product-Files\apache\kafkas\kafka_2.11-1.0.0\config\tmp\kafka-logs\secondTopic-2\00000000000000000000.timeindex, C:\Product-Files\apache\kafkas\kafka_2.11-1.0.0\config\tmp\kafka-logs\secondTopic-2\00000000000000000000.index, and C:\Product-Files\apache\kafkas\kafka_2.11-1.0.0\config\tmp\kafka-logs\secondTopic-2\00000000000000000000.txnindex and rebuilding index... (kafka.log.Log)
[2018-01-03 09:44:49,014] ERROR Error while loading log dir C:\Product-Files\apache\kafkas\kafka_2.11-1.0.0\config\tmp\kafka-logs (kafka.log.LogManager)
java.nio.file.FileSystemException: C:\Product-Files\apache\kafkas\kafka_2.11-1.0.0\config\tmp\kafka-logs\secondTopic-2\00000000000000000000.timeindex: 另一个程序正在使 用此文件,进程无法访问

谷歌翻译:

由于需求失败而发现损坏的索引文件:找到损坏索引,索引文件(C:\ Product-Files \ apache \ kafkas \ kafka_2.11-1.0.0 \ config \ tmp \ kafka-logs \ secondTopic-2 \ 00000000000000000000.index)具有非零大小,但是最后一个偏移量是0,它不大于基本偏移量0.}。删除C:\ Product-Files \ apache \ kafkas \ kafka_2.11-1.0.0 \ config \ tmp \ kafka-logs \ secondTopic-2 \ 00000000000000000000.timeindex,

telnet 127.0.0.1 2181

启动kafka报错

ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING

好坑怎么办

看看zk启动成功了没,telnet一下,网络问题。

启动成功了

好烦啊搞了几天不行,你qq多少,我发截图给你

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

您好,我也是启动kafka报错,说是超时,困扰了好多天了,请问你是怎么解决的,求回复!!!

你这文档写了个锤子,从头到尾说一遍。超时错误咋解决没说啊

你的答案

查看kafka相关的其他问题或提一个您自己的问题