Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching multiple Kafka brokers fails

Tags:

apache-kafka

While trying to launch multiple Kafka brokers with different brokerId's. One being the default server.properties and the other being serverTest.properties with 2 lines changed, those being broker.id=1 and listeners=PLAINTEXT://localhost:6000. The rest is the same default setting. I first start zookeeper, then the default kafka server.properties then while launching serverTest.properties I get the following exception: kafka.common.InconsistentBrokerIdException: Configured brokerId 1 doesn't match stored brokerId 0 in meta.properties. My understanding is that the following above should actually launch multiple nodes, as I've seen others do in tutorials. I'm using Kafka 9.0.

like image 371
TheM00s3 Avatar asked Jun 28 '16 01:06

TheM00s3


People also ask

Can Kafka have multiple brokers?

This section describes the creation of a multi-broker Kafka cluster with brokers located on different hosts. In this scenario: One server hosts the Zookeeper server and a Kafka broker. The second server hosts a a second Kafka broker.

What happens when a Kafka broker fails?

If any broker fails, data should not be lost. For fault-tolerance purposes, the partition is replicated and stored in different brokers. If leader brokers fail, then the controller will elects one of the replicas as the leader.

How many brokers can Kafka have?

A Kafka cluster has exactly one broker that acts as the Controller.

Why we need multiple brokers in Kafka?

So the same message is stored multiple times. This ensures durability as the same message is located on different brokers. In case of a broker failure, Kafka can switch the leader and provide the replicated message to its clients.


6 Answers

Edit config/serverTest.properties and replace the existing config values as follows:

broker.id=2
listeners=PLAINTEXT://9093
log.dirs=/tmp/kafka-logs-2

If you want a third broker:

cp config/server.properties config/server3.properties

Edit config/server3.properties and replace the existing config values as follows:

broker.id=3
listeners=PLAINTEXT://:9094
log.dirs=/tmp/kafka-logs-3

if you run on different machines you must change

advertised.listeners=PLAINTEXT://192.168.x.x:<port>

else if you run in the same vmware machine, for example you should only change the port and log.dir as described above

like image 113
Panagiotis Drakatos Avatar answered Oct 19 '22 20:10

Panagiotis Drakatos


Speaking from experience, don't forget to edit the broker.id entries in the kafka-logs-*/meta.properties files to match your changes (or delete the files and let kafka regenerate them).

like image 26
Adrian Redgers Avatar answered Oct 19 '22 19:10

Adrian Redgers


This is old question, still this answer should help others. The problem is when you create new server.properties from existing server.properties, below line will get copied:

# A comma separated list of directories under which to store log files
log.dirs=/tmp/kafka-logs

So, even new broker tries to use the same log dir and hence it uses the meta.properties of kafka-logs which is created by broker 0 and has broker id as 0.

So, go to /tmp and delete all kafka-logs* files and then comment log.dirs=/tmp/kafka-logs and then add the lines as you have added :)

like image 40
Bikas Katwal Avatar answered Oct 19 '22 21:10

Bikas Katwal


The answers are perfect but it took me a while to figure it out to get it work. I would like to share my mistake and hope others can avoid it.

I followed the official tutorial with kafka here:

https://kafka.apache.org/quickstart#quickstart_multibroker.

and make a file copy as suggested in the guide:

cp config/server.properties config/server-1.properties

I open the file using vim. I do a search for broker.id and replace with the following(mistake by assuming there is no existing listeners and log.dirs) as below


# config/server-1.properties:
broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/tmp/kafka-logs-1

I started a new broker with

 >  bin/kafka-server-start.sh config/server-1.properties

crashed!!!. This is how I debug:

I went /tmp and checked the dir kafka-logs-1 did not appear. I realized that there should be something wrong with my log.dir in config. I double checked it in the config/server-1.propeties. I found that there were two lines of log.dirs.

#copy from the tutorial
log.dirs=/tmp/kafka-logs-1


# default one
log.dirs=/tmp/kafka-logs

Of course the last one overridden the first one thus making the new broker point to the first broker with id=0.

After removing the last log.dirs and keep only one log.dirs ( log.dirs=/tmp/kafka-logs-1 ) works like a charm.

like image 29
channa ly Avatar answered Oct 19 '22 19:10

channa ly


Make sure in your server.properties and serverTest.properties you have different log.dirs

If you had to make any log.dirs changes don't forget to remove previous folders stored on your PC

like image 26
techkuz Avatar answered Oct 19 '22 20:10

techkuz


Make sure the log directories, broker id and ports (with listeners) are different for each node/broker.

Sample configuration (server.properties):

Broker 1

broker.id=1
listeners=PLAINTEXT://:9092
log.dirs=/tmp/kafka-1-logs

Broker 2

broker.id=2
listeners=PLAINTEXT://:9093
log.dirs=/tmp/kafka-2-logs

Broker 3

broker.id=3
listeners=PLAINTEXT://:9094
log.dirs=/tmp/kafka-3-logs

Hope this will help. Happy hacking!!

like image 43
Ankur Mahajan Avatar answered Oct 19 '22 20:10

Ankur Mahajan