apt install default-jdk
Download Kafka from here.
wget https://downloads.apache.org/kafka/3.6.1/kafka-3.6.1-src.tgz
Extract the archive file then move it
tar xzf kafka-3.6.1-src.tgz
mv kafka-3.6.1-src /usr/local/kafka
Move into the new installation directory and build the project.
I only discovered this step after Zookeeper failed to run and informed me to build the project using the following command.
cd /usr/local/kafka
./gradlew jar -PscalaVersion=2.13.11
Create a service file for Zookeeper
bash -c "cat > /etc/systemd/system/zookeeper.service" <<EOF
[Unit]
Description=Apache Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
EOF
Create a service file for Kafka
bash -c "cat > /etc/systemd/system/kafka.service" <<EOF
[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service
[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
[Install]
WantedBy=multi-user.target
EOF
Reload systemd to apply the new service files
systemctl daemon-reload
Enable and Start the services
systemctl enable zookeeper.service kafka.service
systemctl start zookeeper.service kafka.service
systemctl status zookeeper.service kafka.service