Easy Steps: Install Apache Kafka on Debian 12

|
Last Updated:
|
|

This guide provides a step by step tutorial on how to easily install Apache Kafka on Debian 12. Apache Kafka is open-source distributed event streaming platform designed and developed by the Apache Software Foundation in a publish-subscribe architecture to handle large-scale, real-time data streams efficiently and reliably.

Easy Steps: Installing Apache Kafka on Debian 12

Key Concepts and Components in Kafka Architecture

So, what are the main components and concepts in Kafka?

  • Topics: Kafka organizes data streams into topics. A topic is a category or feed name to which records are published and from which records are consumed.
  • Producers: Producers are responsible for publishing records (messages) to Kafka topics. They write records to specific topics, and the records are then appended to a commit log.
  • Consumers: Consumers subscribe to one or more topics and read records from them. They consume records in the order they were written.
  • Brokers: Kafka clusters consist of one or more servers called brokers. Each broker stores and manages the published records, and it can handle read and write requests from producers and consumers.
  • Partitions: Kafka topics are divided into one or more partitions, which are ordered and immutable sequences of records. Partitions allow for parallelism and distributed processing across multiple brokers.
  • Replication: Kafka provides fault tolerance by replicating partitions across multiple brokers. Each partition has multiple replicas, with one leader responsible for handling read and write requests while followers replicate the data.
  • Streams: Kafka Streams is a stream processing library that enables developers to build real-time streaming applications and microservices. It allows for transformations, aggregations, and joins on data streams.

Read more on Kafka Key Concepts page.

Installing Apache Kafka on Debian 12

Install Java 8+ on Debian 12

In this tutorial, we will be using Java 17;

java --version
openjdk 17.0.7 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Debian-1deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Debian-1deb12u1, mixed mode, sharing)

Learn how to install Java 17 on Debian 12;

Install Java 17 LTS on Debian 12

Download Latest Kafka Release Archive

Navigate to Kafka download’s page and grab the latest Kafka binary release archive.

wget https://downloads.apache.org/kafka/3.5.0/kafka_2.13-3.5.0.tgz

Extract Kafka Binary Archive

Extract the downloaded Kafka release binary archive.

In this guide, we will install Kafka to /opt/kafka directory. Hence;

mkdir /opt/kafka
tar xzf kafka_2.13-3.5.0.tgz -C /opt/kafka --strip-components=1

You should now have Kafka configuration files and directories under /opt/kafka directory.

ls -1 /opt/kafka

bin
config
libs
LICENSE
licenses
NOTICE
site-docs

Running Kafka with Kafta Raft (KRaft)

In this guide, we will configure Kafka with KRaft without Zookeeper.

Beginning from v2.8.0, Kafka now supports and uses KRaft as the new Raft consensus algorithm. KRaft is designed to provide strong consistency and fault-tolerance in distributed systems. It allows Kafka to achieve replication and synchronization of metadata across the Kafka brokers in a reliable and efficient manner without relying on Zookeeper.

As much as Zookeeper is still being supported, it is planned to be completely phased in Kafka v4.0 releases.

Setup KRaft for Kafka Cluster

The KRaft configuration files are under, /opt/kafka/config/kraft/;

ls -1 /opt/kafka/config/kraft/

broker.properties
controller.properties
server.properties

We are using a single-node Kafka cluster in this guide. Thus we will proceed with the most of the settings set to default, except the updates of the logs directory paths below.

Update Logs Directory

By default, Kafka sets /tmp/kraft-combined-logs as the default logs directory. I am gonna change this to /opt/kafka/logs. You can keep it if you want.

mkdir /opt/kafka/logs
sed -i '/^log.dirs/s|/tmp/kraft-combined-logs|/opt/kafka/logs|' \
/opt/kafka/config/kraft/server.properties

Generate Kafka Cluster ID

In KRaft mode, a cluster ID that is used to uniquely identify a cluster is required.

The cluster ID can be generated using the command below;

/opt/kafka/bin/kafka-storage.sh random-uuid

The command prints a random UUID like URaeRekUQAyy8wLMNX2Q-w.

Format Kafka Logs Directory to KRaft Format

Next, using the cluster ID generated above, format log directories. This is so as ensure uniqueness is maintained and each Kafka broker can have a unique directory for storing its log data, especially if you had multi-node cluster.

The logs directory can be formatted using the command below, with the ID generated above;

/opt/kafka/bin/kafka-storage.sh format -t <uuid> -c /opt/kafka/config/kraft/server.properties

Replace the UUID as follows;

/opt/kafka/bin/kafka-storage.sh format -t URaeRekUQAyy8wLMNX2Q-w \
-c /opt/kafka/config/kraft/server.properties

Or you can can simply use one command;

/opt/kafka/bin/kafka-storage.sh format \
-t `/opt/kafka/bin/kafka-storage.sh random-uuid` \
-c /opt/kafka/config/kraft/server.properties

You will such an output as;

Formatting /opt/kafka/logs with metadata.version 3.5-IV2.

Similarly, some configuration files are generated and stored under the logs directory;

ls -1 /opt/kafka/logs/
bootstrap.checkpoint
meta.properties

Configure Kafka Heap Size

To ensure optimal performance and stability of Kafka, you need to configure the heap size appropriately. This refers to the memory allocated to the Java Virtual Machine (JVM) running Kafka.

This is set to 1G by default;

grep KAFKA_HEAP_OPTS= /opt/kafka/bin/kafka-server-start.sh

Sample output;

export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"

Depending on the size of the RAM allocated to your server, update this accordingly. Ensure that the allocated heap size is sufficient to handle the expected message traffic and the size of the data being processed.

One of the other settings, log.retention.hours (default 7 days), that may indirectly affected memory utilization is how long does Kafka store the event data. This will primarily affect the storage.

You can use other parameters such as log.retention.minutes, log.retention.ms, or log.retention.bytes.

As such, you can update the value of this in the broker configuration file, /opt/kafka/config/kraft/server.properties.

vim /opt/kafka/config/kraft/server.properties

Use any of the parameters above to define time or size of logs in bytes.

For example, to keep data for 8 hours, enter the line below in the server.properties.

log.retention.hours=8

Save and exit the file.

For reference, this is how our config is like;

cat /opt/kafka/config/kraft/server.properties

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# This configuration file is intended for use in KRaft mode, where
# Apache ZooKeeper is not present.  See config/kraft/README.md for details.
#

############################# Server Basics #############################

# The role of this server. Setting this puts us in KRaft mode
process.roles=broker,controller

# The node id associated with this instance's roles
node.id=1

# The connect string for the controller quorum
controller.quorum.voters=1@localhost:9093

############################# Socket Server Settings #############################

# The address the socket server listens on.
# Combined nodes (i.e. those with `process.roles=broker,controller`) must list the controller listener here at a minimum.
# If the broker listener is not defined, the default listener will use a host name that is equal to the value of java.net.InetAddress.getCanonicalHostName(),
# with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9092,CONTROLLER://:9093

# Name of listener used for communication between brokers.
inter.broker.listener.name=PLAINTEXT

# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
advertised.listeners=PLAINTEXT://:9092

# A comma-separated list of the names of the listeners used by the controller.
# If no explicit mapping set in `listener.security.protocol.map`, default will be using PLAINTEXT protocol
# This is required if running in KRaft mode.
controller.listener.names=CONTROLLER

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


############################# Log Basics #############################

# A comma separated list of directories under which to store log files
log.dirs=/opt/kafka/logs

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings  #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to excessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion due to age
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

Start Kafka Broker

You can now start your Kafka broker.

Starting Kafka Broker in the Foreground

You can start Kafka broker on command line using the command below. In this method, the broker runs as a foreground process.

/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/kraft/server.properties

Sample output;


[2023-07-14 17:56:02,942] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$)
[2023-07-14 17:56:03,195] INFO Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation (org.apache.zookeeper.common.X509Util)
[2023-07-14 17:56:03,321] INFO Registered signal handlers for TERM, INT, HUP (org.apache.kafka.common.utils.LoggingSignalHandler)
[2023-07-14 17:56:03,323] INFO [ControllerServer id=1] Starting controller (kafka.server.ControllerServer)
[2023-07-14 17:56:03,662] INFO Updated connection-accept-rate max connection creation rate to 2147483647 (kafka.network.ConnectionQuotas)
[2023-07-14 17:56:03,697] INFO [SocketServer listenerType=CONTROLLER, nodeId=1] Created data-plane acceptor and processors for endpoint : ListenerName(CONTROLLER) (kafka.network.SocketServer)
[2023-07-14 17:56:03,699] INFO [SharedServer id=1] Starting SharedServer (kafka.server.SharedServer)
[2023-07-14 17:56:03,799] INFO [LogLoader partition=__cluster_metadata-0, dir=/opt/kafka/logs] Loading producer state till offset 0 with message format version 2 (kafka.log.UnifiedLog$)
[2023-07-14 17:56:03,801] INFO [LogLoader partition=__cluster_metadata-0, dir=/opt/kafka/logs] Reloading from producer snapshot and rebuilding producer state from offset 0 (kafka.log.UnifiedLog$)
[2023-07-14 17:56:03,801] INFO [LogLoader partition=__cluster_metadata-0, dir=/opt/kafka/logs] Producer state recovery took 0ms for snapshot load and 0ms for segment recovery from offset 0 (kafka.log.UnifiedLog$)
[2023-07-14 17:56:03,836] INFO Initialized snapshots with IDs SortedSet() from /opt/kafka/logs/__cluster_metadata-0 (kafka.raft.KafkaMetadataLog$)
[2023-07-14 17:56:03,858] INFO [raft-expiration-reaper]: Starting (kafka.raft.TimingWheelExpirationService$ExpiredOperationReaper)
[2023-07-14 17:56:03,984] INFO [RaftManager id=1] Completed transition to Unattached(epoch=0, voters=[1], electionTimeoutMs=1000) from null (org.apache.kafka.raft.QuorumState)
[2023-07-14 17:56:04,001] INFO [RaftManager id=1] Completed transition to CandidateState(localId=1, epoch=1, retries=1, voteStates={1=GRANTED}, highWatermark=Optional.empty, electionTimeoutMs=1569) from Unattached(epoch=0, voters=[1], electionTimeoutMs=1000) (org.apache.kafka.raft.QuorumState)
[2023-07-14 17:56:04,015] INFO [RaftManager id=1] Completed transition to Leader(localId=1, epoch=1, epochStartOffset=0, highWatermark=Optional.empty, voterStates={1=ReplicaState(nodeId=1, endOffset=Optional.empty, lastFetchTimestamp=-1, lastCaughtUpTimestamp=-1, hasAcknowledgedLeader=true)}) from CandidateState(localId=1, epoch=1, retries=1, voteStates={1=GRANTED}, highWatermark=Optional.empty, electionTimeoutMs=1569) (org.apache.kafka.raft.QuorumState)
[2023-07-14 17:56:04,054] INFO [kafka-1-raft-outbound-request-thread]: Starting (kafka.raft.RaftSendThread)
[2023-07-14 17:56:04,057] INFO [kafka-1-raft-io-thread]: Starting (kafka.raft.KafkaRaftManager$RaftIoThread)
[2023-07-14 17:56:04,067] INFO [ControllerServer id=1] Waiting for controller quorum voters future (kafka.server.ControllerServer)
[2023-07-14 17:56:04,067] INFO [ControllerServer id=1] Finished waiting for controller quorum voters future (kafka.server.ControllerServer)
[2023-07-14 17:56:04,072] INFO [MetadataLoader id=1] initializeNewPublishers: the loader is still catching up because we still don't know the high water mark yet. (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,098] INFO [RaftManager id=1] High watermark set to LogOffsetMetadata(offset=1, metadata=Optional[(segmentBaseOffset=0,relativePositionInSegment=91)]) for the first time for epoch 1 based on indexOfHw 0 and voters [ReplicaState(nodeId=1, endOffset=Optional[LogOffsetMetadata(offset=1, metadata=Optional[(segmentBaseOffset=0,relativePositionInSegment=91)])], lastFetchTimestamp=-1, lastCaughtUpTimestamp=-1, hasAcknowledgedLeader=true)] (org.apache.kafka.raft.LeaderState)
[2023-07-14 17:56:04,115] INFO [controller-1-ThrottledChannelReaper-Fetch]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,118] INFO [controller-1-ThrottledChannelReaper-Produce]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,119] INFO [RaftManager id=1] Registered the listener org.apache.kafka.image.loader.MetadataLoader@1406781066 (org.apache.kafka.raft.KafkaRaftClient)
[2023-07-14 17:56:04,119] INFO [RaftManager id=1] Registered the listener org.apache.kafka.controller.QuorumController$QuorumMetaLogListener@429592426 (org.apache.kafka.raft.KafkaRaftClient)
[2023-07-14 17:56:04,122] INFO [controller-1-ThrottledChannelReaper-ControllerMutation]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,126] INFO [controller-1-ThrottledChannelReaper-Request]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,131] INFO [MetadataLoader id=1] handleCommit: The loader is still catching up because we have loaded up to offset -1, but the high water mark is 1 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,152] INFO [ExpirationReaper-1-AlterAcls]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,161] INFO [SocketServer listenerType=CONTROLLER, nodeId=1] Enabling request processing. (kafka.network.SocketServer)
[2023-07-14 17:56:04,164] INFO Awaiting socket connections on 0.0.0.0:9093. (kafka.network.DataPlaneAcceptor)
[2023-07-14 17:56:04,168] INFO [MetadataLoader id=1] handleCommit: The loader finished catching up to the current high water mark of 3 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,175] INFO [MetadataLoader id=1] InitializeNewPublishers: initializing SnapshotGenerator with a snapshot at offset 2 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,183] INFO [ControllerServer id=1] Waiting for all of the authorizer futures to be completed (kafka.server.ControllerServer)
[2023-07-14 17:56:04,183] INFO [ControllerServer id=1] Finished waiting for all of the authorizer futures to be completed (kafka.server.ControllerServer)
[2023-07-14 17:56:04,183] INFO [ControllerServer id=1] Waiting for all of the SocketServer Acceptors to be started (kafka.server.ControllerServer)
[2023-07-14 17:56:04,183] INFO [ControllerServer id=1] Finished waiting for all of the SocketServer Acceptors to be started (kafka.server.ControllerServer)
[2023-07-14 17:56:04,187] INFO [MetadataLoader id=1] InitializeNewPublishers: initializing DynamicConfigPublisher controller id=1 with a snapshot at offset 2 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,188] INFO [MetadataLoader id=1] InitializeNewPublishers: initializing DynamicClientQuotaPublisher controller id=1 with a snapshot at offset 2 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,189] INFO [MetadataLoader id=1] InitializeNewPublishers: initializing ScramPublisher controller id=1 with a snapshot at offset 2 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,190] INFO [MetadataLoader id=1] InitializeNewPublishers: initializing ControllerMetadataMetricsPublisher with a snapshot at offset 2 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,191] INFO [ControllerServer id=1] Waiting for the controller metadata publishers to be installed (kafka.server.ControllerServer)
[2023-07-14 17:56:04,191] INFO [ControllerServer id=1] Finished waiting for the controller metadata publishers to be installed (kafka.server.ControllerServer)
[2023-07-14 17:56:04,192] INFO [BrokerServer id=1] Transition from SHUTDOWN to STARTING (kafka.server.BrokerServer)
[2023-07-14 17:56:04,192] INFO [BrokerServer id=1] Starting broker (kafka.server.BrokerServer)
[2023-07-14 17:56:04,220] INFO [broker-1-ThrottledChannelReaper-Fetch]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,221] INFO [broker-1-ThrottledChannelReaper-Produce]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,221] INFO [broker-1-ThrottledChannelReaper-Request]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,229] INFO [broker-1-ThrottledChannelReaper-ControllerMutation]: Starting (kafka.server.ClientQuotaManager$ThrottledChannelReaper)
[2023-07-14 17:56:04,242] INFO [BrokerServer id=1] Waiting for controller quorum voters future (kafka.server.BrokerServer)
[2023-07-14 17:56:04,243] INFO [BrokerServer id=1] Finished waiting for controller quorum voters future (kafka.server.BrokerServer)
[2023-07-14 17:56:04,269] INFO [broker-1-to-controller-forwarding-channel-manager]: Starting (kafka.server.BrokerToControllerRequestThread)
[2023-07-14 17:56:04,278] INFO [broker-1-to-controller-forwarding-channel-manager]: Recorded new controller, from now on will use node localhost:9093 (id: 1 rack: null) (kafka.server.BrokerToControllerRequestThread)
[2023-07-14 17:56:04,324] INFO Updated connection-accept-rate max connection creation rate to 2147483647 (kafka.network.ConnectionQuotas)
[2023-07-14 17:56:04,336] INFO [SocketServer listenerType=BROKER, nodeId=1] Created data-plane acceptor and processors for endpoint : ListenerName(PLAINTEXT) (kafka.network.SocketServer)
[2023-07-14 17:56:04,349] INFO [broker-1-to-controller-alter-partition-channel-manager]: Starting (kafka.server.BrokerToControllerRequestThread)
[2023-07-14 17:56:04,350] INFO [broker-1-to-controller-alter-partition-channel-manager]: Recorded new controller, from now on will use node localhost:9093 (id: 1 rack: null) (kafka.server.BrokerToControllerRequestThread)
[2023-07-14 17:56:04,356] INFO [ExpirationReaper-1-Produce]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,358] INFO [ExpirationReaper-1-Fetch]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,363] INFO [ExpirationReaper-1-DeleteRecords]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,370] INFO [ExpirationReaper-1-ElectLeader]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,391] INFO [ExpirationReaper-1-Heartbeat]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,393] INFO [ExpirationReaper-1-Rebalance]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,424] INFO [broker-1-to-controller-heartbeat-channel-manager]: Starting (kafka.server.BrokerToControllerRequestThread)
[2023-07-14 17:56:04,424] INFO [broker-1-to-controller-heartbeat-channel-manager]: Recorded new controller, from now on will use node localhost:9093 (id: 1 rack: null) (kafka.server.BrokerToControllerRequestThread)
[2023-07-14 17:56:04,426] INFO [BrokerLifecycleManager id=1] Incarnation TQ2qRl0eQ_iLD0w_Cq9TkA of broker 1 in cluster URaeRekUQAyy8wLMNX2Q-w is now STARTING. (kafka.server.BrokerLifecycleManager)
[2023-07-14 17:56:04,490] INFO [ExpirationReaper-1-AlterAcls]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2023-07-14 17:56:04,572] INFO [BrokerServer id=1] Waiting for the broker metadata publishers to be installed (kafka.server.BrokerServer)
[2023-07-14 17:56:04,572] INFO [MetadataLoader id=1] InitializeNewPublishers: initializing BrokerMetadataPublisher with a snapshot at offset 2 (org.apache.kafka.image.loader.MetadataLoader)
[2023-07-14 17:56:04,577] INFO [BrokerMetadataPublisher id=1] Publishing initial metadata at offset OffsetAndEpoch(offset=2, epoch=1) with metadata.version 3.5-IV2. (kafka.server.metadata.BrokerMetadataPublisher)
[2023-07-14 17:56:04,578] INFO Loading logs from log dirs ArraySeq(/opt/kafka/logs) (kafka.log.LogManager)
[2023-07-14 17:56:04,582] INFO No logs found to be loaded in /opt/kafka/logs (kafka.log.LogManager)
[2023-07-14 17:56:04,588] INFO Loaded 0 logs in 10ms (kafka.log.LogManager)
[2023-07-14 17:56:04,590] INFO [BrokerServer id=1] Finished waiting for the broker metadata publishers to be installed (kafka.server.BrokerServer)
[2023-07-14 17:56:04,591] INFO [BrokerServer id=1] Waiting for the controller to acknowledge that we are caught up (kafka.server.BrokerServer)
[2023-07-14 17:56:04,592] INFO [BrokerLifecycleManager id=1] Successfully registered broker 1 with broker epoch 3 (kafka.server.BrokerLifecycleManager)
[2023-07-14 17:56:04,599] INFO Starting log cleanup with a period of 300000 ms. (kafka.log.LogManager)
[2023-07-14 17:56:04,600] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
[2023-07-14 17:56:04,704] INFO [kafka-log-cleaner-thread-0]: Starting (kafka.log.LogCleaner$CleanerThread)
[2023-07-14 17:56:04,717] INFO [LogDirFailureHandler]: Starting (kafka.server.ReplicaManager$LogDirFailureHandler)
[2023-07-14 17:56:04,717] INFO [GroupCoordinator 1]: Starting up. (kafka.coordinator.group.GroupCoordinator)
[2023-07-14 17:56:04,720] INFO [GroupCoordinator 1]: Startup complete. (kafka.coordinator.group.GroupCoordinator)
[2023-07-14 17:56:04,721] INFO [TransactionCoordinator id=1] Starting up. (kafka.coordinator.transaction.TransactionCoordinator)
[2023-07-14 17:56:04,724] INFO [TxnMarkerSenderThread-1]: Starting (kafka.coordinator.transaction.TransactionMarkerChannelManager)
[2023-07-14 17:56:04,724] INFO [TransactionCoordinator id=1] Startup complete. (kafka.coordinator.transaction.TransactionCoordinator)
[2023-07-14 17:56:04,725] INFO [BrokerMetadataPublisher id=1] Updating metadata.version to 11 at offset OffsetAndEpoch(offset=2, epoch=1). (kafka.server.metadata.BrokerMetadataPublisher)
[2023-07-14 17:56:04,749] INFO [BrokerLifecycleManager id=1] The broker has caught up. Transitioning from STARTING to RECOVERY. (kafka.server.BrokerLifecycleManager)
[2023-07-14 17:56:04,750] INFO [BrokerServer id=1] Finished waiting for the controller to acknowledge that we are caught up (kafka.server.BrokerServer)
[2023-07-14 17:56:04,750] INFO [BrokerServer id=1] Waiting for the initial broker metadata update to be published (kafka.server.BrokerServer)
[2023-07-14 17:56:04,750] INFO [BrokerServer id=1] Finished waiting for the initial broker metadata update to be published (kafka.server.BrokerServer)
[2023-07-14 17:56:04,752] INFO KafkaConfig values: 
	advertised.listeners = PLAINTEXT://localhost:9092
	alter.config.policy.class.name = null
	alter.log.dirs.replication.quota.window.num = 11
	alter.log.dirs.replication.quota.window.size.seconds = 1
	authorizer.class.name = 
	auto.create.topics.enable = true
	auto.include.jmx.reporter = true
	auto.leader.rebalance.enable = true
	background.threads = 10
	broker.heartbeat.interval.ms = 2000
	broker.id = 1
	broker.id.generation.enable = true
	broker.rack = null
	broker.session.timeout.ms = 9000
	client.quota.callback.class = null
	compression.type = producer
	connection.failed.authentication.delay.ms = 100
	connections.max.idle.ms = 600000
	connections.max.reauth.ms = 0
	control.plane.listener.name = null
	controlled.shutdown.enable = true
	controlled.shutdown.max.retries = 3
	controlled.shutdown.retry.backoff.ms = 5000
	controller.listener.names = CONTROLLER
	controller.quorum.append.linger.ms = 25
	controller.quorum.election.backoff.max.ms = 1000
	controller.quorum.election.timeout.ms = 1000
	controller.quorum.fetch.timeout.ms = 2000
	controller.quorum.request.timeout.ms = 2000
	controller.quorum.retry.backoff.ms = 20
	controller.quorum.voters = [1@localhost:9093]
	controller.quota.window.num = 11
	controller.quota.window.size.seconds = 1
	controller.socket.timeout.ms = 30000
	create.topic.policy.class.name = null
	default.replication.factor = 1
	delegation.token.expiry.check.interval.ms = 3600000
	delegation.token.expiry.time.ms = 86400000
	delegation.token.master.key = null
	delegation.token.max.lifetime.ms = 604800000
	delegation.token.secret.key = null
	delete.records.purgatory.purge.interval.requests = 1
	delete.topic.enable = true
	early.start.listeners = null
	fetch.max.bytes = 57671680
	fetch.purgatory.purge.interval.requests = 1000
	group.consumer.assignors = []
	group.consumer.heartbeat.interval.ms = 5000
	group.consumer.max.heartbeat.interval.ms = 15000
	group.consumer.max.session.timeout.ms = 60000
	group.consumer.max.size = 2147483647
	group.consumer.min.heartbeat.interval.ms = 5000
	group.consumer.min.session.timeout.ms = 45000
	group.consumer.session.timeout.ms = 45000
	group.coordinator.new.enable = false
	group.coordinator.threads = 1
	group.initial.rebalance.delay.ms = 3000
	group.max.session.timeout.ms = 1800000
	group.max.size = 2147483647
	group.min.session.timeout.ms = 6000
	initial.broker.registration.timeout.ms = 60000
	inter.broker.listener.name = PLAINTEXT
	inter.broker.protocol.version = 3.5-IV2
	kafka.metrics.polling.interval.secs = 10
	kafka.metrics.reporters = []
	leader.imbalance.check.interval.seconds = 300
	leader.imbalance.per.broker.percentage = 10
	listener.security.protocol.map = CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
	listeners = PLAINTEXT://:9092,CONTROLLER://:9093
	log.cleaner.backoff.ms = 15000
	log.cleaner.dedupe.buffer.size = 134217728
	log.cleaner.delete.retention.ms = 86400000
	log.cleaner.enable = true
	log.cleaner.io.buffer.load.factor = 0.9
	log.cleaner.io.buffer.size = 524288
	log.cleaner.io.max.bytes.per.second = 1.7976931348623157E308
	log.cleaner.max.compaction.lag.ms = 9223372036854775807
	log.cleaner.min.cleanable.ratio = 0.5
	log.cleaner.min.compaction.lag.ms = 0
	log.cleaner.threads = 1
	log.cleanup.policy = [delete]
	log.dir = /tmp/kafka-logs
	log.dirs = /opt/kafka/logs
	log.flush.interval.messages = 9223372036854775807
	log.flush.interval.ms = null
	log.flush.offset.checkpoint.interval.ms = 60000
	log.flush.scheduler.interval.ms = 9223372036854775807
	log.flush.start.offset.checkpoint.interval.ms = 60000
	log.index.interval.bytes = 4096
	log.index.size.max.bytes = 10485760
	log.message.downconversion.enable = true
	log.message.format.version = 3.0-IV1
	log.message.timestamp.difference.max.ms = 9223372036854775807
	log.message.timestamp.type = CreateTime
	log.preallocate = false
	log.retention.bytes = -1
	log.retention.check.interval.ms = 300000
	log.retention.hours = 168
	log.retention.minutes = null
	log.retention.ms = null
	log.roll.hours = 168
	log.roll.jitter.hours = 0
	log.roll.jitter.ms = null
	log.roll.ms = null
	log.segment.bytes = 1073741824
	log.segment.delete.delay.ms = 60000
	max.connection.creation.rate = 2147483647
	max.connections = 2147483647
	max.connections.per.ip = 2147483647
	max.connections.per.ip.overrides = 
	max.incremental.fetch.session.cache.slots = 1000
	message.max.bytes = 1048588
	metadata.log.dir = null
	metadata.log.max.record.bytes.between.snapshots = 20971520
	metadata.log.max.snapshot.interval.ms = 3600000
	metadata.log.segment.bytes = 1073741824
	metadata.log.segment.min.bytes = 8388608
	metadata.log.segment.ms = 604800000
	metadata.max.idle.interval.ms = 500
	metadata.max.retention.bytes = 104857600
	metadata.max.retention.ms = 604800000
	metric.reporters = []
	metrics.num.samples = 2
	metrics.recording.level = INFO
	metrics.sample.window.ms = 30000
	min.insync.replicas = 1
	node.id = 1
	num.io.threads = 8
	num.network.threads = 3
	num.partitions = 1
	num.recovery.threads.per.data.dir = 1
	num.replica.alter.log.dirs.threads = null
	num.replica.fetchers = 1
	offset.metadata.max.bytes = 4096
	offsets.commit.required.acks = -1
	offsets.commit.timeout.ms = 5000
	offsets.load.buffer.size = 5242880
	offsets.retention.check.interval.ms = 600000
	offsets.retention.minutes = 10080
	offsets.topic.compression.codec = 0
	offsets.topic.num.partitions = 50
	offsets.topic.replication.factor = 1
	offsets.topic.segment.bytes = 104857600
	password.encoder.cipher.algorithm = AES/CBC/PKCS5Padding
	password.encoder.iterations = 4096
	password.encoder.key.length = 128
	password.encoder.keyfactory.algorithm = null
	password.encoder.old.secret = null
	password.encoder.secret = null
	principal.builder.class = class org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder
	process.roles = [broker, controller]
	producer.id.expiration.check.interval.ms = 600000
	producer.id.expiration.ms = 86400000
	producer.purgatory.purge.interval.requests = 1000
	queued.max.request.bytes = -1
	queued.max.requests = 500
	quota.window.num = 11
	quota.window.size.seconds = 1
	remote.log.index.file.cache.total.size.bytes = 1073741824
	remote.log.manager.task.interval.ms = 30000
	remote.log.manager.task.retry.backoff.max.ms = 30000
	remote.log.manager.task.retry.backoff.ms = 500
	remote.log.manager.task.retry.jitter = 0.2
	remote.log.manager.thread.pool.size = 10
	remote.log.metadata.manager.class.name = null
	remote.log.metadata.manager.class.path = null
	remote.log.metadata.manager.impl.prefix = null
	remote.log.metadata.manager.listener.name = null
	remote.log.reader.max.pending.tasks = 100
	remote.log.reader.threads = 10
	remote.log.storage.manager.class.name = null
	remote.log.storage.manager.class.path = null
	remote.log.storage.manager.impl.prefix = null
	remote.log.storage.system.enable = false
	replica.fetch.backoff.ms = 1000
	replica.fetch.max.bytes = 1048576
	replica.fetch.min.bytes = 1
	replica.fetch.response.max.bytes = 10485760
	replica.fetch.wait.max.ms = 500
	replica.high.watermark.checkpoint.interval.ms = 5000
	replica.lag.time.max.ms = 30000
	replica.selector.class = null
	replica.socket.receive.buffer.bytes = 65536
	replica.socket.timeout.ms = 30000
	replication.quota.window.num = 11
	replication.quota.window.size.seconds = 1
	request.timeout.ms = 30000
	reserved.broker.max.id = 1000
	sasl.client.callback.handler.class = null
	sasl.enabled.mechanisms = [GSSAPI]
	sasl.jaas.config = null
	sasl.kerberos.kinit.cmd = /usr/bin/kinit
	sasl.kerberos.min.time.before.relogin = 60000
	sasl.kerberos.principal.to.local.rules = [DEFAULT]
	sasl.kerberos.service.name = null
	sasl.kerberos.ticket.renew.jitter = 0.05
	sasl.kerberos.ticket.renew.window.factor = 0.8
	sasl.login.callback.handler.class = null
	sasl.login.class = null
	sasl.login.connect.timeout.ms = null
	sasl.login.read.timeout.ms = null
	sasl.login.refresh.buffer.seconds = 300
	sasl.login.refresh.min.period.seconds = 60
	sasl.login.refresh.window.factor = 0.8
	sasl.login.refresh.window.jitter = 0.05
	sasl.login.retry.backoff.max.ms = 10000
	sasl.login.retry.backoff.ms = 100
	sasl.mechanism.controller.protocol = GSSAPI
	sasl.mechanism.inter.broker.protocol = GSSAPI
	sasl.oauthbearer.clock.skew.seconds = 30
	sasl.oauthbearer.expected.audience = null
	sasl.oauthbearer.expected.issuer = null
	sasl.oauthbearer.jwks.endpoint.refresh.ms = 3600000
	sasl.oauthbearer.jwks.endpoint.retry.backoff.max.ms = 10000
	sasl.oauthbearer.jwks.endpoint.retry.backoff.ms = 100
	sasl.oauthbearer.jwks.endpoint.url = null
	sasl.oauthbearer.scope.claim.name = scope
	sasl.oauthbearer.sub.claim.name = sub
	sasl.oauthbearer.token.endpoint.url = null
	sasl.server.callback.handler.class = null
	sasl.server.max.receive.size = 524288
	security.inter.broker.protocol = PLAINTEXT
	security.providers = null
	server.max.startup.time.ms = 9223372036854775807
	socket.connection.setup.timeout.max.ms = 30000
	socket.connection.setup.timeout.ms = 10000
	socket.listen.backlog.size = 50
	socket.receive.buffer.bytes = 102400
	socket.request.max.bytes = 104857600
	socket.send.buffer.bytes = 102400
	ssl.cipher.suites = []
	ssl.client.auth = none
	ssl.enabled.protocols = [TLSv1.2, TLSv1.3]
	ssl.endpoint.identification.algorithm = https
	ssl.engine.factory.class = null
	ssl.key.password = null
	ssl.keymanager.algorithm = SunX509
	ssl.keystore.certificate.chain = null
	ssl.keystore.key = null
	ssl.keystore.location = null
	ssl.keystore.password = null
	ssl.keystore.type = JKS
	ssl.principal.mapping.rules = DEFAULT
	ssl.protocol = TLSv1.3
	ssl.provider = null
	ssl.secure.random.implementation = null
	ssl.trustmanager.algorithm = PKIX
	ssl.truststore.certificates = null
	ssl.truststore.location = null
	ssl.truststore.password = null
	ssl.truststore.type = JKS
	transaction.abort.timed.out.transaction.cleanup.interval.ms = 10000
	transaction.max.timeout.ms = 900000
	transaction.remove.expired.transaction.cleanup.interval.ms = 3600000
	transaction.state.log.load.buffer.size = 5242880
	transaction.state.log.min.isr = 1
	transaction.state.log.num.partitions = 50
	transaction.state.log.replication.factor = 1
	transaction.state.log.segment.bytes = 104857600
	transactional.id.expiration.ms = 604800000
	unclean.leader.election.enable = false
	unstable.api.versions.enable = false
	zookeeper.clientCnxnSocket = null
	zookeeper.connect = null
	zookeeper.connection.timeout.ms = null
	zookeeper.max.in.flight.requests = 10
	zookeeper.metadata.migration.enable = false
	zookeeper.session.timeout.ms = 18000
	zookeeper.set.acl = false
	zookeeper.ssl.cipher.suites = null
	zookeeper.ssl.client.enable = false
	zookeeper.ssl.crl.enable = false
	zookeeper.ssl.enabled.protocols = null
	zookeeper.ssl.endpoint.identification.algorithm = HTTPS
	zookeeper.ssl.keystore.location = null
	zookeeper.ssl.keystore.password = null
	zookeeper.ssl.keystore.type = null
	zookeeper.ssl.ocsp.enable = false
	zookeeper.ssl.protocol = TLSv1.2
	zookeeper.ssl.truststore.location = null
	zookeeper.ssl.truststore.password = null
	zookeeper.ssl.truststore.type = null
 (kafka.server.KafkaConfig)
[2023-07-14 17:56:04,757] INFO [BrokerServer id=1] Waiting for the broker to be unfenced (kafka.server.BrokerServer)
[2023-07-14 17:56:04,791] INFO [BrokerLifecycleManager id=1] The broker has been unfenced. Transitioning from RECOVERY to RUNNING. (kafka.server.BrokerLifecycleManager)
[2023-07-14 17:56:04,792] INFO [BrokerServer id=1] Finished waiting for the broker to be unfenced (kafka.server.BrokerServer)
[2023-07-14 17:56:04,792] INFO [SocketServer listenerType=BROKER, nodeId=1] Enabling request processing. (kafka.network.SocketServer)
[2023-07-14 17:56:04,792] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.DataPlaneAcceptor)
[2023-07-14 17:56:04,793] INFO [BrokerServer id=1] Waiting for all of the authorizer futures to be completed (kafka.server.BrokerServer)
[2023-07-14 17:56:04,793] INFO [BrokerServer id=1] Finished waiting for all of the authorizer futures to be completed (kafka.server.BrokerServer)
[2023-07-14 17:56:04,793] INFO [BrokerServer id=1] Waiting for all of the SocketServer Acceptors to be started (kafka.server.BrokerServer)
[2023-07-14 17:56:04,794] INFO [BrokerServer id=1] Finished waiting for all of the SocketServer Acceptors to be started (kafka.server.BrokerServer)
[2023-07-14 17:56:04,794] INFO [BrokerServer id=1] Transition from STARTING to STARTED (kafka.server.BrokerServer)
[2023-07-14 17:56:04,794] INFO Kafka version: 3.5.0 (org.apache.kafka.common.utils.AppInfoParser)
[2023-07-14 17:56:04,795] INFO Kafka commitId: c97b88d5db4de28d (org.apache.kafka.common.utils.AppInfoParser)
[2023-07-14 17:56:04,795] INFO Kafka startTimeMs: 1689371764794 (org.apache.kafka.common.utils.AppInfoParser)
[2023-07-14 17:56:04,796] INFO [KafkaRaftServer nodeId=1] Kafka Server started (kafka.server.KafkaRaftServer)

You can open another terminal and check the ports for Kafka control plane (9093/tcp) and client (9092/tcp).

ss -altnp | grep :90

LISTEN 0      50                 *:9092             *:*    users:(("java",pid=5127,fd=151))                                                                                                                             
LISTEN 0      50                 *:9093             *:*    users:(("java",pid=5127,fd=131))

Press Ctrl+c to stop the foreground process or simply execute this command on a seperate terminal;

/opt/kafka/bin/kafka-server-stop.sh /opt/kafka/config/kraft/server.properties

Or just;

/opt/kafka/bin/kafka-server-stop.sh

Running Kafka Broker as systemd Service

You can create Kafka broker systemd service to easily manage the process.

vim /etc/systemd/system/kafka.service

[Unit]
Description=Apache Kafka
Requires=network.target
After=network.target

[Service]
Type=simple
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/kraft/server.properties
ExecStop=/opt/kafka/bin/kafka-server-stop.sh
Restart=on-failure

[Install]
WantedBy=default.target

Save and exit the file.

Reload systemd;

systemctl daemon-reload

Start Kafka broker service;

systemctl start kafka

● kafka.service - Apache Kafka
     Loaded: loaded (/etc/systemd/system/kafka.service; disabled; preset: enabled)
     Active: active (running) since Fri 2023-07-14 18:20:10 EDT; 5s ago
   Main PID: 7812 (java)
      Tasks: 90 (limit: 4642)
     Memory: 324.1M
        CPU: 4.520s
     CGroup: /system.slice/kafka.service
             └─7812 java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -XX:MaxInlineLevel=15 -Djava.awt.headless=true "-Xlog:g>

Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,083] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.DataPlaneAcceptor)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Waiting for all of the authorizer futures to be completed (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Finished waiting for all of the authorizer futures to be completed (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Waiting for all of the SocketServer Acceptors to be started (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Finished waiting for all of the SocketServer Acceptors to be started (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Transition from STARTING to STARTED (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO Kafka version: 3.5.0 (org.apache.kafka.common.utils.AppInfoParser)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,094] INFO Kafka commitId: c97b88d5db4de28d (org.apache.kafka.common.utils.AppInfoParser)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,094] INFO Kafka startTimeMs: 1689373213093 (org.apache.kafka.common.utils.AppInfoParser)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,094] INFO [KafkaRaftServer nodeId=1] Kafka Server started (kafka.server.KafkaRaftServer)

Enable Kafka broker service to run on system boot;

systemctl enable kafka

You can view logs using systemd journald journalctl command;

journalctl -f -u kafka

Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,083] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.DataPlaneAcceptor)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Waiting for all of the authorizer futures to be completed (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Finished waiting for all of the authorizer futures to be completed (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Waiting for all of the SocketServer Acceptors to be started (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Finished waiting for all of the SocketServer Acceptors to be started (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO [BrokerServer id=1] Transition from STARTING to STARTED (kafka.server.BrokerServer)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,093] INFO Kafka version: 3.5.0 (org.apache.kafka.common.utils.AppInfoParser)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,094] INFO Kafka commitId: c97b88d5db4de28d (org.apache.kafka.common.utils.AppInfoParser)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,094] INFO Kafka startTimeMs: 1689373213093 (org.apache.kafka.common.utils.AppInfoParser)
Jul 14 18:20:13 debian kafka-server-start.sh[7812]: [2023-07-14 18:20:13,094] INFO [KafkaRaftServer nodeId=1] Kafka Server started (kafka.server.KafkaRaftServer)

Create topics, Send and Receive messages on Kafka Topic

You can now configure your producers to publish records (messages) to Kafka topics and consumers to subscribe to one or more topics and read records from them.

Manually Create a Topic

For example, let’s create a test topic on the Kafka server/broker;

/opt/kafka/bin/kafka-topics.sh --create --topic kafka-topic-test --bootstrap-server localhost:9092

List Kafka Topics

You can list topics using the command;

/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092

Example output;

kafka-topic-test

Manually write (Produce) and read (Consume) data to the topic on Kafka server

To verify that you can write and read data from Kafka topics, let’s write/produce to out test topic above;

/opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 \
--topic kafka-topic-test

When it runs, you will get such a prompt;

>

Type your message and press ENTER;

>Hello Kafka, this is a test message
>

You can cancel the command by using ctrl+c and consume/read data from this topic.

You can consume message in realtime if the topic is being written actively;

/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka-topic-test

But you can also read all the messages from those that have already written to those currently being written;

/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 \
--topic kafka-topic-test --from-beginning

You should see our message above;

/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka-topic-test --from-beginning
Hello Kafka, this is a test message

Delete Kafka Topics

So, how does on delete Kafka topics?

To delete one by one;

/opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic <name-of-topic>

To delete all Kafka topics;

for i in `/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092`;do /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic $i; done

Setup Three Node Cluster

You can setup a cluster by following the guide below;

Setup a Three-Node Kafka KRaft Cluster for Scalable Data Streaming

Manage Kafka Cluster from UI

You can manager your cluster using Kadeck;

Install Kadeck Apache Kafka UI Tool on Debian/Ubuntu

That closes our guide on how to install Apache Kafka on Debian 12

Read more on the documentation page.

More Tutorials

Install Logstash 8 on Ubuntu/Debian

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment