0
0
KafkaHow-ToBeginner · 4 min read

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.id for multiple brokers causes conflicts.
  • Not setting listeners correctly prevents clients from connecting.
  • Incorrect zookeeper.connect string stops broker from registering.
  • Not creating or having write permission on log.dirs causes 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

PropertyDescriptionExample
broker.idUnique broker identifierbroker.id=1
listenersBroker network addresslisteners=PLAINTEXT://localhost:9092
log.dirsDirectory for Kafka logslog.dirs=/tmp/kafka-logs
zookeeper.connectZookeeper connection stringzookeeper.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.