Apache Kafka is a framework for building real-time streaming applications that is available as open source and is distributed in a stream. It is frequently utilized by businesses. It is a platform that is dependable, scalable, and error-tolerant, and it gives you the ability to analyze enormous amounts of data in real time. In this tutorial, we will demonstrate how to install Kafka on Ubuntu 22.04 by walking you through each step.
Video-guid of Installing Apache Kafka on Ubuntu 22.04
Prerequisites: Before we proceed with the installation, you need to have the following:
- A server running Ubuntu 22.04 with a minimum of 2GB RAM and 2 CPUs
- Java 8 or higher version installed on your system
- Terminal access with sudo privileges
Step 1: Update the system
Before we begin, we need to make sure that the system is up to date. Open your terminal and run the following command
sudo apt update sudo apt upgrade
Step 2: Install Java
Kafka requires Java to be installed on the system. Run the following command to install Java
sudo apt install openjdk-8-jdk
Once the installation is complete, verify the Java version by running the following command:
Step 3: Download Kafka
Next, we need to download Kafka from the official website. Run the following command to download the latest version of Kafka
Note: You can check for the latest version of Kafka on the official website and replace the download link in the above command.
Step 4: Extract Kafka
Once the download is complete, we need to extract the Kafka archive using the following command
tar -xzf kafka_2.13-3.0.0.tgz
Step 5: Start Kafka Server
We need to start the Kafka server before we can start using it. Run the following command to start the Kafka server
cd kafka_2.13-3.0.0 bin/zookeeper-server-start.sh config/zookeeper.properties
Open a new terminal and run the following command to start the Kafka server:
Step 6: Create a Kafka Topic
We need to create a Kafka topic before we can start sending messages to it. Run the following command to create a topic
bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092
Step 7: Send Messages to Kafka Topic
We can use the Kafka command-line tool to send messages to the topic. Run the following command to start the console producer
bin/kafka-console-producer.sh --topic test --bootstrap-server localhost:9092
Type in the messages and press Enter to send them to the topic.
Step 8: Receive Messages from Kafka Topic
We can use the Kafka command-line tool to receive messages from the topic. Run the following command to start the console consumer
bin/kafka-console-consumer.sh --topic test --from-beginning --bootstrap-server localhost:9092
You should see the messages that you sent to the topic in the previous step.
In this guide, we have walked you through the steps of installing Kafka on Ubuntu 22.04. We have also shown you how to create a topic, send messages to the topic, and receive messages from the topic. With Kafka, you can process large volumes of data in real-time and build reliable and scalable streaming applications.
I have extensive experience in the field of IT infrastructure security Regularly work on continuous monitoring of the network and infrastructure, preventing any possible security breach; other tasks and issues related to security. In my free time, I enjoy writing a column for this blog, where I share my experience and knowledge.