Kafka启动失败,因为zookeeper超时(远程服务器),但机器可以直接连接到zookeeper

时间:2016-02-24 21:19:50

标签: apache-kafka apache-zookeeper

当我启动kafka时,它很快失败,同时抱怨它无法连接到zookeeper。我正在运行zookeeper作为独立的集群/集合。我很困惑,因为服务器之间没有防火墙(如zookeeper-shell.sh测试所证明的那样)。

来自/var/log/kafka/server.log

2016-02-24 16:07:12,101 INFO kafka.server.KafkaServer: [Kafka Server 1], Connecting to zookeeper on 10.7.20.100:2181,10.7.20.101:2181,10.7.20.102:2181
2016-02-24 16:07:20,291 FATAL kafka.server.KafkaServerStartable: Fatal error during KafkaServerStable startup. Prepare to shutdown
org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 6000
    at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:880)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:98)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:84)
    at kafka.server.KafkaServer.initZk(KafkaServer.scala:113)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:69)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:34)
    at kafka.Kafka$.main(Kafka.scala:46)
    at kafka.Kafka.main(Kafka.scala)
2016-02-24 16:07:20,294 INFO kafka.server.KafkaServer: [Kafka Server 1], shutting down
2016-02-24 16:07:20,312 INFO kafka.server.KafkaServer: [Kafka Server 1], shut down completed
2016-02-24 16:07:20,317 INFO kafka.server.KafkaServer: [Kafka Server 1], shutting down

但是从/ opt / kafka安装目录我可以使用esemble连接字符串连接到zookeeper - 所以我真的怀疑它是网络还是防火墙。

[me@dckafka01 kafka]$ cd /opt/kafka
[me@dckafka01 kafka]$ bin/zookeeper-shell.sh 10.7.20.100:2181,10.7.20.101:2181,10.7.20.102:2181

Connecting to 10.7.20.100:2181,10.7.20.101:2181,10.7.20.102:2181
Welcome to ZooKeeper!
JLine support is disabled
WATCHER::WatchedEvent state:SyncConnected type:None path:null

get /blah
null
cZxid = 0x400000009
ctime = Tue Feb 16 09:00:28 EST 2016
mZxid = 0x400000009
mtime = Tue Feb 16 09:00:28 EST 2016
pZxid = 0x40000017e
cversion = 2
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 2

ls /blah
[applications, registry]

这是预期的。有没有人对我进行调查?

3 个答案:

答案 0 :(得分:5)

改变超时有助于。现在我需要追逐网络延迟

cat config / server.properties

# coding: UTF-8 
# This file created by Chef from template. Do not hand edit this file

log.dirs=/var/kafka
port=9092
num.partitions=4
default.replication.factor=3
log.flush.interval.messages=1
log.retention.minutes=43200
log.retention.check.interval.ms=3600000
num.replica.fetchers=4
replica.fetch.wait.max.ms=5000
replica.lag.max.messages=10000
auto.leader.rebalance.enable=true
num.network.threads=8
advertised.host.name=10.7.20.71
zookeeper.connection.timeout.ms=16000
broker.id=1
zookeeper.connect=10.7.20.100:2181,10.7.20.101:2181,10.7.20.102:2181

答案 1 :(得分:0)

我在寻找解决我的Kafka无法连接到Zookeeper的特定问题的解决方案时找到了该线程。就您而言,我认为这只是Zookeeper启动和准备好接收连接(侦听套接字)的一个延迟。因此,可能更好的解决方案是在启动Kafka之前等待,或者最好拥有一个脚本来检查Zookeeper节点是否准备好接收连接,然后启动Kafka。我认为仅针对Kafka启动更改已配置的超时不是很好。例如,如果您认为您的网络太慢(您需要一个更大的数字),或者它的速度足以应付较短的超时时间,则应进行更改。

答案 2 :(得分:0)

以我为例,我只是发现正在运行动物园管理员的命令提示符有点挂(通常发生)。

我只需要随机按一些键,然后该cmd再次处于活动状态。然后运行命令没有给我任何错误。