This page covers common configuration steps for Apache Kafka deployments with KRaft mode (Kafka 4.0+).
| File | Purpose | Location |
|---|---|---|
server.properties |
Main broker configuration | /opt/kafka/config/ |
producer.properties |
Producer client config | /opt/kafka/config/ |
consumer.properties |
Consumer client config | /opt/kafka/config/ |
# Node identification
node.id=1
# Process roles (broker, controller, or both)
process.roles=broker,controller
# Controller quorum voters (format: nodeId@host:port)
controller.quorum.voters=1@localhost:9093
# Listener configuration
listeners=PLAINTEXT://:9092,CONTROLLER://:9093
advertised.listeners=PLAINTEXT://localhost:9092
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
controller.listener.names=CONTROLLER
inter.broker.listener.name=PLAINTEXT
# Number of partitions for auto-created topics
num.partitions=3
# Default replication factor
default.replication.factor=3
# Minimum in-sync replicas
min.insync.replicas=2
# Enable auto topic creation
auto.create.topics.enable=true
# Log directory
log.dirs=/var/lib/kafka/data
# Log retention (hours)
log.retention.hours=168
# Log segment size (bytes)
log.segment.bytes=1073741824
# Log retention check interval (ms)
log.retention.check.interval.ms=300000
# Number of threads for network handling
num.network.threads=8
num.io.threads=16
# Socket buffer sizes
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
# Message size limits
message.max.bytes=1000012
replica.fetch.max.bytes=1048576
Restart Kafka after configuration changes:
sudo systemctl restart kafka
# Check broker status
/opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:9092
# List topics
/opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
# Create a test topic
/opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 \
--create --topic test-topic --partitions 3 --replication-factor 1
# Produce a message
/opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test-topic
# Consume messages
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 \
--topic test-topic --from-beginning --timeout-ms 5000