Deployment guide

Apache Kafka 4.2 on Ubuntu 24.04

Videos

Overview: Apache Kafka 4.2 Ubuntu 24.04 on Azure: overview (watch on YouTube)

Launch and log in: Apache Kafka 4.2 Ubuntu 24.04 on Azure: launch and log in (watch on YouTube)

Deep Dive: Apache Kafka 4.2 Ubuntu 24.04 on Azure: deep dive (watch on YouTube)

Overview

Apache Kafka is a leading open source distributed event streaming platform. It offers high-throughput producers and consumers, exactly-once semantics, KRaft consensus (no ZooKeeper), and queues for Kafka (KIP-932, now generally available).

This SecureAnyCloud image installs Kafka 4.2.0 (Scala 2.13 binary) from the official Apache CDN with SHA-512 verification, alongside OpenJDK 17. The broker runs in single-VM KRaft mode (combined broker and controller) with SASL/SCRAM-SHA-256 authentication. First boot provisions a per-VM SecureAnyCloud admin user with Kafka 4's native kafka-storage.sh format --add-scram flag. The image also bundles AKHQ 0.26.0, an Apache 2.0 web UI, so operators get a Kafka admin console out of the box.

What you get:

  • Apache Kafka 4.2.0 (Scala 2.13) at /opt/kafka
  • OpenJDK 17 JRE headless from Ubuntu 24.04 noble main
  • A single-VM KRaft cluster, with kafka.service running the broker and controller in the same JVM
  • A SASL/SCRAM-SHA-256 listener on TCP 9092 for clients, protected by the SecureAnyCloud admin credentials
  • The AKHQ 0.26.0 web UI on TCP 80 with HTTP basic auth, behind an nginx reverse proxy that fronts AKHQ on 127.0.0.1:8080
  • A pre-created SecureAnyCloud topic (1 partition, replication 1)
  • A per-VM SecureAnyCloud password (32 hex characters) used for both Kafka SCRAM and AKHQ basic auth
  • Credentials at /stage/scripts/kafka-credentials.log
  • 24/7 SecureAnyCloud support

Prerequisites

You need an active Azure subscription, an SSH key, and a VNet with a subnet.

Standard_B2s (4 GB RAM) is suitable for development, test, single-tenant production streaming, edge and IoT brokers, and proof-of-concept workloads. For production, raise the size to D4s or D8s and tune KAFKA_HEAP_OPTS in /etc/default/kafka.

Configure the NSG to allow inbound 22/tcp from your management CIDR, 9092/tcp from your client CIDR (Kafka SASL/SCRAM clients), and 80/tcp from your operator CIDR (AKHQ web UI).

Step 1-3: Deploy + SSH (standard pattern)

ssh azureuser@<vm-ip>
4

Service Status + Version

sudo systemctl is-active kafka.service akhq.service nginx.service ls /opt/kafka/libs/ | grep -E '^kafka-clients-' | head -1
5

Read Per-VM Credentials

sudo cat /stage/scripts/kafka-credentials.log

Note the values of KAFKA_BOOTSTRAP, KAFKA_ADMIN_USER and KAFKA_ADMIN_PASSWORD. The same password is used for the AKHQ web UI basic auth.

6

Auth Wall + Broker API Versions

PASS=$(sudo grep '^KAFKA_ADMIN_PASSWORD=' /stage/scripts/kafka-credentials.log | cut -d= -f2-)
cat > /tmp/sac.properties <<EOF security.protocol=SASL_PLAINTEXT sasl.mechanism=SCRAM-SHA-256 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="sac" password="${PASS}"; EOF /opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties | head -3

Without --command-config, the first call fails. With the SecureAnyCloud SCRAM credentials, it returns the broker API matrix.

7

AKHQ Web UI: Topic List

Browse to http://<vm-ip>/ and sign in as SecureAnyCloud with the password from Step 5. The Topics tab lists every topic, including the pre-created SecureAnyCloud topic.

8

AKHQ: Cluster Brokers

The Nodes tab shows the single broker with id 1 and host 127.0.0.1:9092, and it shows the controller leader.

9

AKHQ: Consumer Groups

The Consumer Groups tab shows consumer groups and their lag once you have consumers running. On a fresh deployment, the list is empty until you produce and consume a message.

10

Produce + Consume from the CLI

PASS=$(sudo grep '^KAFKA_ADMIN_PASSWORD=' /stage/scripts/kafka-credentials.log | cut -d= -f2-)
cat > /tmp/sac.properties <<EOF security.protocol=SASL_PLAINTEXT sasl.mechanism=SCRAM-SHA-256 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="sac" password="${PASS}"; EOF echo "hello sac $(date +%s)" | /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --topic sac /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --topic sac --from-beginning --max-messages 1 --timeout-ms 10000

The producer sends a single message through a pipe. The consumer reads it back from offset 0.

11

Create a New Topic

Replace <topic-name> with your topic name, and replace <partitions> and <replication> with the numbers you want. Replication cannot exceed the number of brokers, so keep it at 1 for a single VM:

/opt/kafka/bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --create --topic <topic-name> --partitions 1 --replication-factor 1
12

Tune Heap

Edit /etc/default/kafka and restart:

sudo systemctl restart kafka.service

The defaults on Standard_B2s are:

  • KAFKA_HEAP_OPTS: -Xms512m -Xmx1024m
  • G1GC tuning enabled
  • Log directory: /var/lib/kafka/data/logs
  • Metadata directory: /var/lib/kafka/data/metadata

For production, raise -Xmx to 4096m or higher on D4s or D8s instances.

13

Add a Second AKHQ User

Replace <new-password> with the operator's chosen password:

sudo htpasswd -bB /etc/nginx/akhq.htpasswd alice <new-password>
sudo systemctl reload nginx

Each operator signs in with their own basic-auth credential. The underlying Kafka cluster credentials remain the SecureAnyCloud SCRAM admin defined in /etc/akhq/application.yml.

14

Add a Second Kafka SCRAM User

/opt/kafka/bin/kafka-configs.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --alter --add-config 'SCRAM-SHA-256=[password=<new-password>]' --entity-type users --entity-name <new-username>
15

Backups

Kafka data lives at /var/lib/kafka/data/logs. To take a consistent backup, stop the broker, copy the directory and restart the broker:

sudo systemctl stop kafka.service
sudo tar czf /var/backups/kafka-$(date +%F).tgz -C /var/lib/kafka data
sudo systemctl start kafka.service

Copy /var/backups to Azure Blob Storage (az storage blob upload-batch) periodically for off-VM retention. For zero-downtime backups, add a second broker and use kafka-mirror-maker.sh.

16

Logs and Troubleshooting

sudo journalctl -u kafka.service --no-pager -n 80
sudo journalctl -u akhq.service --no-pager -n 30
sudo journalctl -u nginx.service --no-pager -n 30
sudo ls /var/log/kafka/

Kafka writes its main log to /var/log/kafka/server.log and its controller log to /var/log/kafka/controller.log. AKHQ's stdout goes to the systemd journal. The nginx access log is at /var/log/nginx/access.log, and the nginx error log is at /var/log/nginx/error.log.

Security

  • SASL/SCRAM-SHA-256 is enforced on the broker listener, so no anonymous client connections are accepted.
  • The AKHQ web UI is bound to 127.0.0.1:8080, so it cannot be reached directly from the network.
  • The nginx auth wall on :80 enforces HTTP basic authentication.
  • One per-VM SecureAnyCloud password is used for both Kafka SCRAM and AKHQ basic auth, so you rotate a single credential.
  • Restrict NSG inbound on :9092 and :80 to the IP ranges that need them.
  • Terminate TLS at an upstream Application Gateway or Front Door, or enable Kafka's own SASL_SSL listener through server.properties and a JKS keystore.
  • The controller listener is bound to 127.0.0.1:9093 (loopback only) and is not exposed to the network.

Support

SecureAnyCloud provides 24/7/365 expert technical support. Guaranteed response within 24 hours, one hour average for critical issues. Contact sales@secureanycloud.com.

Deploy on Azure

Launch Apache Kafka 4.2 on Ubuntu 24.04 LTS on Azure with 24/7 support from SecureAnyCloud.

View on Marketplace

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com

Deploy on Azure