How to Configure Kafka Broker: Simple Steps and Example
To configure a
Kafka broker, edit the server.properties file to set essential properties like broker.id, listeners, and log.dirs. Then start the broker using the Kafka start script pointing to this configuration file.Syntax
The Kafka broker configuration is done in the server.properties file. Key properties include:
broker.id: Unique ID for the broker.listeners: Network address the broker listens on.log.dirs: Directory to store Kafka logs.zookeeper.connect: Zookeeper connection string.
These settings tell Kafka how to identify, connect, and store data.
properties
broker.id=1 listeners=PLAINTEXT://localhost:9092 log.dirs=/tmp/kafka-logs zookeeper.connect=localhost:2181
Example
This example shows a minimal server.properties configuration for a Kafka broker running locally. It sets the broker ID, listener port, log directory, and Zookeeper connection.
properties
broker.id=1 listeners=PLAINTEXT://localhost:9092 log.dirs=/tmp/kafka-logs zookeeper.connect=localhost:2181
Output
INFO KafkaServer: started (kafka.server.KafkaServer)
Common Pitfalls
Common mistakes when configuring Kafka brokers include:
- Using the same
broker.idfor multiple brokers causes conflicts. - Not setting
listenerscorrectly prevents clients from connecting. - Incorrect
zookeeper.connectstring stops broker from registering. - Not creating or having write permission on
log.dirscauses startup failure.
Always verify these settings before starting the broker.
properties
## Wrong: Duplicate broker.id broker.id=1 ## Right: Unique broker.id broker.id=2
Quick Reference
| Property | Description | Example |
|---|---|---|
| broker.id | Unique broker identifier | broker.id=1 |
| listeners | Broker network address | listeners=PLAINTEXT://localhost:9092 |
| log.dirs | Directory for Kafka logs | log.dirs=/tmp/kafka-logs |
| zookeeper.connect | Zookeeper connection string | zookeeper.connect=localhost:2181 |
Key Takeaways
Set a unique broker.id for each Kafka broker to avoid conflicts.
Configure listeners properly so clients can connect to the broker.
Ensure log.dirs exists and is writable to store Kafka data.
Provide the correct zookeeper.connect string for broker registration.
Edit server.properties and start Kafka with this config to apply settings.