Start with Apache Kafka
Before installing the Apache Kafka, you must have Java installed and have a user account with sudo privileges. In addition, 2GB or more RAM is recommended for Kafka to run properly.
The following steps will guide you through the installation of Apache Kafka.
Java is required to install Kafka. Check if your Ubuntu has Java installed by checking the version with the following command:
If Java is not installed, use the following commands to install Java OpenJDK.
$ sudo suitable To install default-jdk
Creating a User Account
If Java is already installed, create a non-root user account. We have to give him something too sudo Privileges by adding the user to sudo Group with the following command:
$ sudo adduser linuxhint sudo
Sign in to the newly created user account.
You must download the latest one Apache Kafka from the official download page. Load the binaries with the wget Command as shown below:
After the binary is downloaded, extract it with the tar command and move the extracted directory to the /opt/kafka.
Next, create the systemd scripts for the zookeeper and the Kafka Services that help start and stop the services.
Use an editor of your choice to create the systemd scripts and paste the following content. Start with the Zookeeper:
Paste the following:
description=Apache Zookeeper Server
Requires=network.destination remote fs.destination
To=network.destination remote fs.destination
Save the file. Create the systemd file for Kafka and paste the following content:
When pasting, make sure you set the correct path for the Java you have installed on your system.
description=Apache Kafka server
When finished, apply the changes by reloading the systemd daemon:
Next, enable the Zookeeper service and start it with the following commands:
$ sudo start systemctl zookeepe<strong>rightstrong>
You also have to do the same for Kafka:
$ sudo systemctl starts kafka
Once you start the services you can check their status before we create a theme in Kafka.
The good thing about Kafka is that there are several scripts that you can use.
Let’s create a new theme named linuxhint1 Use of kafka-topics.sh Script with one partition and one replication. Use the following command:
Note that our theme is being created. We can see the previous message to verify this.
Alternatively, you can also use to list the available themes -list option in the following command. It should return the topic we created:S
After the Kafka topic is created, you can start writing the Streams data to the Kafka-console-producer.sh and see if it is reflected in yours consumer.sh.
Open your shell and access the theme we created using the producer.sh as shown below:
Next, open another shell and access the Kafka theme using the consumer.sh file.
With the two shells open, you can send messages on the producer console. Whatever you type will appear in the consumer console, confirming that our Apache Kafka is running.
With this guide you now have all the steps to follow to install Apache Kafka in your Ubuntu 22.04. Hope you managed to follow each step and install yours Apache Kafka and create themes to run simple consumer and producer production. You can implement the same in a large production.