error while starting kafka broker

2019-04-24 11:01发布

I was able to successfully set up zookeeper and one kafka broker yesterday. Everything worked as expected. I shut down kafka (ctrl + c) and then zookeeper.

Today I started zookeeper and when I started kafka (bin/kafka-server-start.sh config/server0.properties), I get the following error. I tried various remedies suggested (removing completely my kafka installation and doing it again from scratch). Still I get same error.

[2016-09-28 16:15:55,895] FATAL Fatal error during KafkaServerStartable startup. Prepare to shutdown (kafka.server.KafkaServerStartable)
java.lang.RuntimeException: A broker is already registered on the path /brokers/ids/0. This probably indicates that you either have configured a brokerid that is already in use, or else you have shutdown this broker and restarted it faster than the zookeeper timeout so it appears to be re-registering.
        at kafka.utils.ZkUtils.registerBrokerInZk(ZkUtils.scala:305)
        at kafka.utils.ZkUtils.registerBrokerInZk(ZkUtils.scala:291)
        at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:70)
        at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:51)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:244)
        at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:37)
        at kafka.Kafka$.main(Kafka.scala:67)
        at kafka.Kafka.main(Kafka.scala)
[2016-09-28 16:15:55,896] INFO [Kafka Server 0], shutting down (kafka.server.KafkaServer)

All set up in mac

7条回答
走好不送
2楼-- · 2019-04-24 11:24

I found similar issue in my AWS server. The problem was zookeeper was running. So I killed the process first and tried again and it worked. $ ps aux | grep zookeeper $kill -9 <zookeeper.properties process>

查看更多
相关推荐>>
3楼-- · 2019-04-24 11:24

I had similar issue in with docker container containing zookeeper and kafka (it isn't best practise to put two services in one container, but it was for testing purpose).

this was the error

[2018-11-21 12:54:24,434] INFO [ThrottledChannelReaper-Fetch]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2018-11-21 12:54:24,434] INFO [ThrottledChannelReaper-Produce]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2018-11-21 12:54:24,435] INFO [ThrottledChannelReaper-Request]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2018-11-21 12:54:24,453] INFO Loading logs. (kafka.log.LogManager)
[2018-11-21 12:54:24,457] INFO Logs loading complete in 4 ms. (kafka.log.LogManager)
[2018-11-21 12:54:24,468] INFO Starting log cleanup with a period of 300000 ms. (kafka.log.LogManager)
[2018-11-21 12:54:24,469] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
[2018-11-21 12:54:24,694] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
[2018-11-21 12:54:24,728] INFO [SocketServer brokerId=0] Started 1 acceptor threads (kafka.network.SocketServer)
[2018-11-21 12:54:24,741] INFO [ExpirationReaper-0-Produce]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-11-21 12:54:24,741] INFO [ExpirationReaper-0-DeleteRecords]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-11-21 12:54:24,741] INFO [ExpirationReaper-0-Fetch]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2018-11-21 12:54:24,750] INFO [LogDirFailureHandler]: Starting (kafka.server.ReplicaManager$LogDirFailureHandler)
[2018-11-21 12:54:24,790] INFO Creating /brokers/ids/0 (is it secure? false) (kafka.zk.KafkaZkClient)
[2018-11-21 12:54:24,802] ERROR Error while creating ephemeral at /brokers/ids/0, node already exists and owner '72057672936325120' does not match current session '72057674644258816' (kafka.zk.KafkaZkClient$CheckedEphemeral)
[2018-11-21 12:54:24,803] INFO Result of znode creation at /brokers/ids/0 is: NODEEXISTS (kafka.zk.KafkaZkClient)
[2018-11-21 12:54:24,808] ERROR [KafkaServer id=0] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
org.apache.zookeeper.KeeperException$NodeExistsException: KeeperErrorCode = NodeExists
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:122)
    at kafka.zk.KafkaZkClient.checkedEphemeralCreate(KafkaZkClient.scala:1525)
    at kafka.zk.KafkaZkClient.registerBrokerInZk(KafkaZkClient.scala:84)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:257)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
    at kafka.Kafka$.main(Kafka.scala:75)
    at kafka.Kafka.main(Kafka.scala)

Quickfix for me was to start kafka-server a few seconds later;

bin/zookeeper-server-start.sh -daemon config/zookeeper.properties && (bin/kafka-server-start.sh config/server.properties || echo "kafka start failed. restarting ... " && sleep 3 && bin/kafka-server-start.sh config/server.properties)
查看更多
在下西门庆
4楼-- · 2019-04-24 11:31

I have faced the same issue while setting up the kafka and zookeeper multinode cluster. The cause of the issue is : As zookeeper ensemble takes some time to setup So when we start kafka brokers, all zookeeper nodes might not joined ensemble yet. So may be One kafka node connected to a zookeeper which is not yet in the ensemble. Another reason can be kafka broker is killed instead of stopped. When you kill your kafka process or it crashes, and it does not close its zookeeper connection correctly

To avoid this situation make sure your zookeeper ensemble is up and running before starting kafka brokers. Add proper waits between zookeeper and kafka broker services start and stop.

查看更多
爷、活的狠高调
5楼-- · 2019-04-24 11:31

Make sure the kafka server shut down correctly by checking the default prot 9092 is already in use or not. Kill the process on 9092, and restart kafka server.

If not works, might be the existing kafka server (with broker id 0) is already in use. Give it a try to change broker.id to 1 instead of 0 in "server0.properties" (btw, why it was called server0, did you change any config here? by default, it should be server.properties),

查看更多
欢心
6楼-- · 2019-04-24 11:35

Below approach worked for me.

Change the broker ID to a different value. By default it is 0. Change it to 1 and test things again.

查看更多
Ridiculous、
7楼-- · 2019-04-24 11:36

You just have to execute the zookeeper-server-stop.[sh|bat] script.

查看更多
登录 后发表回答