Log inSign up

Install Kafka without ZooKeeper using KRaft

Install a Java 17 or 21 runtime, unpack the Kafka 4 binary release into /opt/kafka, format the log directory with kafka-storage.sh format --standalone and start it under systemd. Keep the plain listener on 127.0.0.1 and give remote clients a SASL_SSL listener with SCRAM users.

Topic: Queues and messaging · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

What changed with KRaft in Kafka 4?

Kafka 4 runs only in KRaft mode: the cluster metadata lives in an internal Raft log managed by controller processes, and ZooKeeper support has been removed. A small deployment runs one process that is both broker and controller, which is what this guide sets up first.

Kafka keeps its own page cache warm and the JVM heap modest, so memory beyond the heap still helps. A single development node is happy on 2 GB with a 512 MB heap; for real traffic choose 4 GB or more and fast NVMe storage, because every message is written to disk before it is acknowledged. Work as a sudo user (see creating a sudo user).

How do you install Java and Kafka?

Install a headless JRE from the distribution, create a system user and unpack the release from the Apache download site. Check the downloads page for the newest 4.x number and set it in the variable.

sudo apt update
# Ubuntu 24.04, Ubuntu 22.04 and Debian 13
sudo apt install -y openjdk-21-jre-headless curl
# Debian 12
sudo apt install -y openjdk-17-jre-headless curl
java -version

KV=4.1.1
curl -fLO "https://downloads.apache.org/kafka/$KV/kafka_2.13-$KV.tgz"
curl -fLO "https://downloads.apache.org/kafka/$KV/kafka_2.13-$KV.tgz.sha512"
cat kafka_2.13-$KV.tgz.sha512
sha512sum kafka_2.13-$KV.tgz
sudo useradd --system --home /opt/kafka --shell /usr/sbin/nologin kafka
sudo mkdir -p /opt/kafka /var/lib/kafka
sudo tar -xzf kafka_2.13-$KV.tgz -C /opt/kafka --strip-components=1
sudo chown -R kafka:kafka /opt/kafka /var/lib/kafka
/opt/kafka/bin/kafka-topics.sh --version

Compare the two checksum outputs by eye before continuing. If the version you want has left downloads.apache.org, the same path exists under archive.apache.org/dist/kafka/.

How do you format storage and start a single node?

Point log.dirs at the data directory, generate a cluster ID and format the directory once as a standalone controller.

sudo sed -i 's|^log.dirs=.*|log.dirs=/var/lib/kafka|' /opt/kafka/config/server.properties
grep -E '^(process.roles|node.id|listeners|controller)' /opt/kafka/config/server.properties
CID=$(/opt/kafka/bin/kafka-storage.sh random-uuid)
sudo -u kafka /opt/kafka/bin/kafka-storage.sh format --standalone -t "$CID" -c /opt/kafka/config/server.properties

Then describe the service to systemd. The heap setting keeps the JVM small enough for a modest plan; raise it on bigger servers.

sudo tee /etc/systemd/system/kafka.service >/dev/null <<'EOF'
[Unit]
Description=Apache Kafka (KRaft)
After=network-online.target
Wants=network-online.target

[Service]
User=kafka
Group=kafka
Environment="KAFKA_HEAP_OPTS=-Xms512m -Xmx512m"
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
ExecStop=/opt/kafka/bin/kafka-server-stop.sh
Restart=on-failure
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now kafka
sudo ss -ltnp | grep java

How do you prove the node works?

Create a topic, write two records with the console producer and read them back. The metadata quorum tool confirms the controller side is healthy.

cd /opt/kafka
bin/kafka-metadata-quorum.sh --bootstrap-server localhost:9092 describe --status
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3 --replication-factor 1
printf 'first\nsecond\n' | bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginning --timeout-ms 5000

Both lines should appear, possibly in a different order because they landed in different partitions. Kafka guarantees order inside a partition, not across a topic.

How do you open Kafka to remote clients with TLS and SCRAM?

Add a third listener that requires SASL over TLS, keep PLAINTEXT on the loopback address and create one SCRAM user per application. First package a certificate for kafka.example.net as PKCS12 (issue it as in the Certbot guide):

sudo mkdir -p /opt/kafka/tls
sudo openssl pkcs12 -export -in /etc/letsencrypt/live/kafka.example.net/fullchain.pem -inkey /etc/letsencrypt/live/kafka.example.net/privkey.pem -name kafka -out /opt/kafka/tls/kafka.p12 -passout pass:StorePass-Change-Me
sudo chown -R kafka:kafka /opt/kafka/tls && sudo chmod 600 /opt/kafka/tls/kafka.p12

Replace the listener lines in server.properties with these:

listeners=PLAINTEXT://127.0.0.1:9092,CONTROLLER://127.0.0.1:9093,SASL_SSL://0.0.0.0:9094
advertised.listeners=PLAINTEXT://127.0.0.1:9092,CONTROLLER://127.0.0.1:9093,SASL_SSL://kafka.example.net:9094
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SASL_SSL:SASL_SSL
sasl.enabled.mechanisms=SCRAM-SHA-512
listener.name.sasl_ssl.scram-sha-512.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required;
ssl.keystore.type=PKCS12
ssl.keystore.location=/opt/kafka/tls/kafka.p12
ssl.keystore.password=StorePass-Change-Me

Restart, add the user and open the port:

sudo systemctl restart kafka
/opt/kafka/bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter --entity-type users --entity-name orders_app --add-config 'SCRAM-SHA-512=[iterations=8192,password=App-Secret-Here]'
/opt/kafka/bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type users
sudo ufw allow 22/tcp
sudo ufw allow 9094/tcp
sudo ufw enable

A client then sets security.protocol=SASL_SSL, sasl.mechanism=SCRAM-SHA-512 and a matching JAAS line with its username and password. To restrict which topics each user may touch, enable the StandardAuthorizer and grant ACLs with kafka-acls.sh; do it after you have created an admin user listed in super.users.

How do you build a three-node quorum across servers?

Run three combined nodes with distinct node.id values, list all three controllers in controller.quorum.bootstrap.servers and format each one with the same cluster ID. Because our servers reach each other over public IPs, the controller and replication listeners must not be open to the world: allow ports 9093 and 9094 only from the peer addresses, and either use SASL_SSL between brokers or route the traffic through a WireGuard tunnel.

# server.properties on node 1 (198.51.100.24); change node.id and addresses on the others
process.roles=broker,controller
node.id=1
controller.quorum.bootstrap.servers=198.51.100.24:9093,198.51.100.25:9093,198.51.100.26:9093
listeners=SASL_SSL://0.0.0.0:9094,CONTROLLER://0.0.0.0:9093,PLAINTEXT://127.0.0.1:9092
inter.broker.listener.name=SASL_SSL
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-512

# peer firewall, repeat for each other node
sudo ufw allow proto tcp from 198.51.100.25 to any port 9093
sudo ufw allow proto tcp from 198.51.100.26 to any port 9093

Format node 1 with --initial-controllers listing all three voters (the format is id@host:port:directory-id, documented in the KRaft operations page) or start node 1 standalone and add the others with kafka-metadata-quorum.sh add-controller. Set default.replication.factor=3 and min.insync.replicas=2 once three brokers are up. The controller listener in this sketch is plain text, so keep port 9093 limited to the peers or inside the tunnel.

How do you upgrade and look after Kafka?

Upgrade one node at a time: unpack the new release next to the old one, copy server.properties, swap the directory and restart, waiting for kafka-topics.sh --describe --under-replicated-partitions to print nothing before moving on. When every node runs the new binaries, raise the feature level with kafka-features.sh --bootstrap-server localhost:9092 upgrade --release-version followed by the new version, as the upgrade notes describe.

Retention decides disk use: log.retention.hours and log.retention.bytes trim old segments, and a topic setting overrides both. Watch free space with df -h /var/lib/kafka and the tips in the disk usage guide. A broker that exits at start with an InconsistentClusterIdException was formatted with a different ID; one that refuses clients from outside is usually advertising the wrong host name in advertised.listeners. Logs live in /opt/kafka/logs/server.log and journalctl -u kafka.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A2-4single KRaft node for development2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months
F4-16production broker on NVMe4 vCPU, 16 GB RAM, 384 GB NVMe$57.60/mo$57.60 for 1 month
A8-16heavy topics with long retention8 vCPU, 16 GB RAM, 350 GB NVMe$57.60/mo$57.60 for 1 month

Questions about Apache Kafka (KRaft)

Do I still need ZooKeeper?

No. Kafka 4 dropped ZooKeeper completely. Clusters still on ZooKeeper must migrate to KRaft on a 3.x bridge release before moving to 4.

How much heap should Kafka get?

Between 1 and 6 GB is common. Leave the rest of the RAM to the operating system page cache, which Kafka relies on for fast reads of recent data.

Can I run Kafka in Docker instead?

Yes, the project publishes an apache/kafka image that starts a KRaft node with sensible defaults. See Docker Compose for a stack layout, and mount /var/lib/kafka/data on a volume.

Which port do clients connect to?

Local programs use localhost:9092. Remote programs use the SASL_SSL listener, kafka.example.net:9094 in this guide.

Is a Kafka-compatible alternative lighter on memory?

Redpanda speaks the Kafka protocol in a single C++ binary; the Redpanda guide shows how to run it if you prefer that model.