A single Kafka broker is the smallest unit you can run for application teams that need an ordered, replayable event log. This article is the install we run for a non-production baseline: KRaft mode (no ZooKeeper), a pinned JVM, a dedicated kafka user, log directories on their own volume, systemd as the supervisor, and a first topic created with sensible defaults. Production gets three or more brokers — covered in the KRaft vs ZooKeeper article — but the single-node install is the bedrock everyone starts from.
How to verify
Before installing, check the box has the prerequisites and nothing is squatting Kafka’s ports:
ss -ltnp | grep -E ':(9092|9093|9094)\b'
java -version 2>&1 || echo "no jvm yet"
free -m | awk '/^Mem:/ {print "mem_mb="$2}'
df -h / /var
id kafka 2>/dev/null || echo "no kafka user"
Kafka uses 9092 for client/broker traffic, 9093 for the KRaft controller, and 9094 commonly for inter-broker TLS. Java 17 is the supported minimum for current Kafka releases.
What’s happening
Apache Kafka is a distributed commit log. A broker accepts produces (writes) and serves consumes (reads) against partitioned topics. Each partition is an ordered, append-only segment file on disk, replicated across N brokers based on the topic’s replication factor. Consumers track their own offset; the broker does not.
KRaft (Kafka Raft) is the metadata replication system that replaced ZooKeeper as the controller plane. In KRaft mode, a quorum of controller nodes (3 or 5 in production, 1 for dev) holds cluster metadata — topic definitions, partition leaders, broker membership — in a Raft log. The broker process can be a controller, a broker, or both (combined mode, suitable only for dev). No external ZooKeeper ensemble to operate, no zookeeper.connect config setting, no version-skew dance between Kafka and ZK.
For this single-node install, we run combined mode: one process is both the broker and the sole controller. Production splits these roles across separate hosts.
Storage layout matters. Topics live under log.dirs (yes, the property is plural — Kafka supports JBOD across multiple log dirs). Each partition is a directory with segment files (.log), indexes (.index, .timeindex), and metadata. Disk pressure is the most common cause of broker outages; size accordingly and put log.dirs on a dedicated volume.
The procedure
-
Install Java 17. Kafka does not ship a JRE; use the Temurin or Adoptium build, or the Ubuntu archive’s
openjdk-17-jre-headless:sudo apt update sudo apt install -y openjdk-17-jre-headless java -version -
Create the service user and directories:
sudo useradd --system --shell /usr/sbin/nologin --home /var/lib/kafka kafka sudo mkdir -p /opt/kafka /var/lib/kafka/logs /var/log/kafka /etc/kafka sudo chown -R kafka:kafka /var/lib/kafka /var/log/kafka/var/lib/kafka/logsis the data directory (topic partitions);/var/log/kafkais for the JVM’s own log4j output. Two completely different things — never put them on the same path. -
Install Kafka. Pin a specific version; the archive download is a Scala-versioned tarball:
KAFKA_VER=3.7.0 SCALA_VER=2.13 curl -fsSL "https://downloads.apache.org/kafka/${KAFKA_VER}/kafka_${SCALA_VER}-${KAFKA_VER}.tgz" \ | sudo tar -xz -C /opt sudo mv /opt/kafka_${SCALA_VER}-${KAFKA_VER}/* /opt/kafka/ sudo chown -R kafka:kafka /opt/kafka -
Write the KRaft config at
/etc/kafka/server.properties:# combined mode — broker AND controller in one process process.roles=broker,controller node.id=1 controller.quorum.voters=1@127.0.0.1:9093 listeners=PLAINTEXT://0.0.0.0:9092,CONTROLLER://127.0.0.1:9093 advertised.listeners=PLAINTEXT://kafka-01.example.net:9092 controller.listener.names=CONTROLLER inter.broker.listener.name=PLAINTEXT log.dirs=/var/lib/kafka/logs num.partitions=3 default.replication.factor=1 min.insync.replicas=1 offsets.topic.replication.factor=1 transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 auto.create.topics.enable=false delete.topic.enable=true log.retention.hours=168 log.segment.bytes=1073741824For single-node, replication.factor=1 is forced — there is no other broker to replicate to. The
min.insync.replicas=1is the matching weakness; on a cluster, this rises to 2. -
Format the storage directory. KRaft needs a one-time format with a cluster ID:
sudo -u kafka /opt/kafka/bin/kafka-storage.sh format \ -t "$(/opt/kafka/bin/kafka-storage.sh random-uuid)" \ -c /etc/kafka/server.propertiesThe cluster ID is persisted under
log.dirs/meta.properties; if you ever rebuild the broker, you reuse this ID. -
Write the systemd unit at
/etc/systemd/system/kafka.service:[Unit] Description=Apache Kafka (KRaft) After=network-online.target Wants=network-online.target [Service] Type=simple User=kafka Group=kafka Environment="KAFKA_HEAP_OPTS=-Xms2G -Xmx2G" Environment="LOG_DIR=/var/log/kafka" ExecStart=/opt/kafka/bin/kafka-server-start.sh /etc/kafka/server.properties ExecStop=/opt/kafka/bin/kafka-server-stop.sh Restart=on-failure RestartSec=10s LimitNOFILE=131072 [Install] WantedBy=multi-user.targetHeap size: Kafka itself uses heap for connection state and indexes; off-heap is for page cache. 2-6 GiB heap is the sane range; let the OS use the rest of RAM for page cache.
-
Start and verify:
sudo systemctl daemon-reload sudo systemctl enable --now kafka sudo systemctl status kafka --no-pager sudo journalctl -u kafka -n 50 --no-pager /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list -
Create the first topic and round-trip a message:
/opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 \ --create --topic events --partitions 3 --replication-factor 1 /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 \ --topic events > hello kafka > ^D /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 \ --topic events --from-beginning --max-messages 1The consumer prints
hello kafkaand exits. If the broker is healthy and the topic exists, this round-trip takes milliseconds.
Common pitfalls
auto.create.topics.enable=trueis the default in older configs but a foot-gun in production; a typo in a client config silently creates a new topic with default partition count. We disable it.- The
log.dirsand the JVMLOG_DIRare different concepts; mixing them puts log4j output into the data directory and confuses operators six months later. - Heap-size tuning is not “more is better” — Kafka over 6 GiB of heap spends measurable time in GC; raise page-cache headroom instead by leaving more RAM unallocated.
- The single-node install has
min.insync.replicas=1, which means any partial disk failure or filesystem corruption can lose data. Treat single-node Kafka as a dev tool only. - Forgetting to format the storage with
kafka-storage.sh formatbefore first start results in a startup error about missing metadata — straightforward once you know the error message, baffling otherwise.
Stack Harbor stands up Kafka brokers as the event-log tier for clients running event-sourced or analytics-feeding architectures — single-node for staging, three- or five-node KRaft clusters for production, brokers under config management, partition counts sized to consumer parallelism, and lag dashboards that page before downstream services notice the backpressure. This is the work covered by our Managed Operations practice.