'Apache Kafka cannot start multiple instances on same local machine

I am trying to set up Apache Kafka on my local machine to try it out following this official guide: https://kafka.apache.org/quickstart.

However, when I tried to start multiple servers, I keep getting the error: "kafka.common.InconsistentBrokerIdException: Configured broker.id 2 doesn't match stored broker.id 0 in meta.properties. If you moved your data, make sure your configured broker.id matches. If you intend to create a new broker, you should remove all data in your data directories (log.dirs)"

I set the parameters exactly following the guide like:

broker.id=1
listeners=PLAINTEXT://:9093
log.dir=/tmp/kafka-logs-1

I don't quite get it why it's incorrect. I have searched on other sites that they mentioned I need to fix something in meta.properties or log.dirs whatever, but none of these files or directories appear to exist on my computer. Please help me out thx!



Solution 1:[1]

I solved the issue by myself by changing those variables in server-1.properties at their original position. Previously I set the three parameters at the beginning of server-1.properties at broker.id section. However the *.properties file is actually very long and log.dir was set in its own section at the end of the file by default to be kafka-logs, which would override my changes at the beginning and cause the errors, because in directory /tmp/kafka-logs the meta.properties has broker.id 0, corresponding to the default server.properties set up. We must have log directory to be kafka-logs-1 so that the meta.properties is also unique for the broker.

By the way, it took me a long time to find out where kafka-logs locates. It locates at root/tmp, rather than inside the folder where kafka library locates. We should type cd /tmp to check it.

Hope this helps!

Solution 2:[2]

The problem is with the Broker.id You set that to 1 but when we add the another server it will increment the id from 0 to 1 directly. so thats why give any other integer number which is not closer to the existing server id

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ray
Solution 2 Aniket Belsare