简体   繁体   English

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

[英]Kafka startup fails with zookeeper timeout (remote server), yet the machine can connect to zookeeper directly

WHen I start kafka up, it fails quickly while complaining that it cannot connect to zookeeper.当我启动 kafka 时,它很快失败,同时抱怨它无法连接到 zookeeper。 I am running zookeeper as a standalone cluster/ensemble.我将zookeeper 作为独立的集群/集合运行。 I am confused because there is no Firewall between the servers (as evidenced by the zookeeper-shell.sh test).我很困惑,因为服务器之间没有防火墙(zookeeper-shell.sh 测试证明了这一点)。

from /var/log/kafka/server.log来自/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

However from the /opt/kafka install directory I am able to connect to zookeeper using the esemble connection string - so I really doubt it is network OR firewall.但是,从 /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]

Which is as expected.正如预期的那样。 Does anybody have an angle for me to investigate?有人有角度让我调查吗?

Well - changing the timeout helped.好吧 - 改变超时有帮助。 now i need to chase the network delays down现在我需要追赶网络延迟

cat config/server.properties猫配置/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

In my case, I just found that my command prompt which was running the zookeepers, kind of hung (usually happens in windows).就我而言,我刚刚发现运行动物园管理员的命令提示符有点挂起(通常发生在 Windows 中)。

I just had to randomly press some key and the cmd was active again.我只需要随机按下某个键,cmd 就再次处于活动状态。 And then running the command gave me no errors.然后运行命令没有给我任何错误。

I found this thread while looking for a solution to my specific problem with Kafka not being able to connect to Zookeeper.我在寻找 Kafka 无法连接到 Zookeeper 的特定问题的解决方案时发现了这个线程。 In your case, I think it's only a delay in Zookeeper to start up and get ready to receive connections (listening to the socket).在您的情况下,我认为 Zookeeper 启动并准备接收连接(侦听套接字)只是延迟。 So probably a better solution is to wait before starting Kafka or best have a script that checks Zookeeper nodes are ready to receive connections and then start Kafka.所以可能更好的解决方案是在启动 Kafka 之前等待,或者最好有一个脚本来检查 Zookeeper 节点是否准备好接收连接,然后启动 Kafka。 I don't think it's good to change the configured timeout only for Kafka startup.我认为只为Kafka启动更改配置的超时时间不好。 It should be changed, for example, if you consider your network is too slow (you would need a higher number) or it is fast enough to deal with a shorter timeout.例如,如果您认为您的网络太慢(您需要更高的数字)或者它足够快以处理更短的超时,则应该更改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM