How to install Apache Kafka on Ubuntu 20.04?
Overview
Apache Kafka is an open-source distributed event streaming platform that is widely used for real-time data processing and analysis. Kafka is designed to handle large volumes of real-time data from multiple sources and distribute them to various applications and systems. It is a distributed system, meaning that it can run on a cluster of servers, allowing for increased scalability, fault tolerance, high throughput and low latency. In this tutorial, we'll walk you through the process of how to install Apache Kafka on Ubuntu 20.04.
Prerequisites
There are certain prerequisites that need to be met before you begin:
Server running Ubuntu 20.04
Access to SSH-connected text editor
User account with root or sudo access
Internet connection
Key
· Red box- Input
· Green box- Output
Get Started
Step 1: Update your System
· Before installing Kafka, it is recommended to update your system to ensure that all the necessary packages are up to date. You can do this by running the following command:
Step 2: Install Stable Java Version
· To run Kafka, you'll need to install Java on your system. Fortunately, you can easily install the open-source implementation of Java, called OpenJDK, by running the following command:
· Verify the installed java version, with the following command:
Note: If the above command throws you the following error:
You may try executing the following command:
Step 3: Download latest Apache Kafka
Next, you need to download Kafka. You can do this by visiting the Kafka downloads page on the Apache website and selecting the latest stable release. At the time of writing, the latest version is 3.4.0. Copy the download link for the binary tarball file.
Step 4: Extract Kafka
After downloading the archive file, create a new directory and then extract its contents, by the following commands:
Now, move the extracted files to the /usr/local/kafka directory, by executing the following command:
Step 5: Configure Zookeeper
Zookeeper is a distributed coordination service that is often used with Kafka to manage various aspects of the Kafka cluster.
Create systemd files, for controlling the startup and management of system services, daemons, for both Zookeeper and Kafka separately, with the following command:
Add the following lines in the Zookeeper systemd file to setup the configuration:
Save and exit by entering Ctrl+ O and Ctrl + X.
Step 5: Configure Kafka
Let's now create a systemd file for Kafka service, using the following command:
Mention the following lines of code in the Kafka systemd file, while ensuring that you have set the correct JAVA_HOME path that matches the version of Java installed on your system:
Save and exit by entering Ctrl+ O and Ctrl + X.
To apply the new changes, reload the systemd daemon, with the following command:
This will cause all the systemd files in the system environment to be reloaded.
Step 6: Start Zookeeper and Kafka service
Kafka uses ZooKeeper to manage and coordinate its brokers.
You can start and enable the ZooKeeper service using the following command:
Then, start and enable the Kafka service by running the following command in a separate terminal window:
Verify the running status of both Zookeeper and Apache Kafka services, by the following command:
Conclusion
You now have Kafka installed and running on your Ubuntu 20.04 system.
Last updated