0
0
KafkaHow-ToBeginner · 3 min read

How to Add Broker to Kafka Cluster: Step-by-Step Guide

To add a broker to a Kafka cluster, install Kafka on the new server, configure its server.properties with a unique broker.id and the existing cluster's zookeeper.connect address, then start the Kafka broker service. The new broker will join the cluster and start handling partitions automatically.
📐

Syntax

Adding a broker involves configuring the server.properties file and starting the Kafka broker process.

  • broker.id: Unique number identifying the broker in the cluster.
  • zookeeper.connect: Address of the ZooKeeper ensemble managing the cluster.
  • log.dirs: Directory path where Kafka stores data logs.

After configuration, start the broker with the Kafka start script.

bash
broker.id=2
zookeeper.connect=zk1:2181,zk2:2181,zk3:2181
log.dirs=/var/lib/kafka-logs

# Start broker command
bin/kafka-server-start.sh config/server.properties
💻

Example

This example shows how to add a new broker with broker.id=2 to an existing Kafka cluster managed by ZooKeeper ensemble at zk1:2181,zk2:2181,zk3:2181.

bash
# Edit config/server.properties on new broker machine
broker.id=2
zookeeper.connect=zk1:2181,zk2:2181,zk3:2181
log.dirs=/var/lib/kafka-logs

# Start the Kafka broker
bin/kafka-server-start.sh config/server.properties
Output
[2024-06-01 10:00:00,000] INFO Kafka start completed (kafka.server.KafkaServer) [2024-06-01 10:00:01,000] INFO Registered broker 2 at path /brokers/ids/2 with ZooKeeper (kafka.zk.KafkaZkClient)
⚠️

Common Pitfalls

Common mistakes when adding a broker include:

  • Using a broker.id that duplicates an existing broker's ID, causing conflicts.
  • Incorrect zookeeper.connect address, preventing the broker from joining the cluster.
  • Not setting proper log.dirs permissions, causing startup failures.
  • Forgetting to open required network ports (default 9092) for broker communication.
bash
# Wrong: Duplicate broker.id
broker.id=1

# Correct: Unique broker.id
broker.id=3
📊

Quick Reference

SettingDescriptionExample
broker.idUnique broker identifierbroker.id=2
zookeeper.connectZooKeeper cluster addresseszookeeper.connect=zk1:2181,zk2:2181,zk3:2181
log.dirsDirectory for Kafka logslog.dirs=/var/lib/kafka-logs
Start commandStart Kafka broker processbin/kafka-server-start.sh config/server.properties

Key Takeaways

Assign a unique broker.id to each new Kafka broker to avoid conflicts.
Configure zookeeper.connect to point to the existing ZooKeeper ensemble managing the cluster.
Set proper log.dirs path with correct permissions for Kafka data storage.
Start the new broker using the kafka-server-start.sh script with the updated configuration.
Verify network connectivity and open required ports for broker communication.