Apache Kafka Installation on Ubuntu 20

Apache Kafka is an event streaming platform that is very scalable and reliable. Kafka is developed using Java, so for running Kafka you need java runtime/ JDK on your PC.

In this post, I will tell you to step by step guide to install and run Kafka for learning and development purposes on Ubuntu 20.

If Java is not already installed then you need to install it first. You can check java installation by below command.

~$ java -version

If Java is not installed then you will get following output

Command 'java' not found, but can be installed with:

sudo apt install openjdk-11-jre-headless  # version 11.0.10+9-0ubuntu1~20.04, or
sudo apt install default-jre              # version 2:1.11-72
sudo apt install openjdk-8-jre-headless   # version 8u282-b08-0ubuntu1~20.04
sudo apt install openjdk-13-jre-headless  # version 13.0.4+8-1~20.04
sudo apt install openjdk-14-jre-headless  # version 14.0.2+12-1~20.04

You can install Java of your choice by using the above commands or open JDK 8 by following command

~$ sudo apt-get install openjdk-8-jdk

The above command will install Open JDK 8 on your ubuntu instance. You can verify installation as below

~$ java -version

OpenJDK version “1.8.0_282”
OpenJDK Runtime Environment (build 1.8.0_282-8u282-b08-0ubuntu1~20.04-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)

Install Kafka on Ubuntu 20

Kafka can be run in various ways like docker container, and Linux service, etc. In this post, I will tell you how to run manually for development purposes. I will run only one instnace.

First, you need to download the latest Kafka package. You can download using wget command

~$ wget https://mirrors.estointernet.in/apache/kafka/2.7.0/kafka_2.13-2.7.0.tgz

Now expand compressed Kafka binary package

~$ tar -xzf kafka_2.13-2.7.0.tgz
~$ cd kafka_2.13-2.7.0/

Running Kafka on Linux

To run Kafka you need to first Run Apache ZooKeeper in a separate terminal, By default, it is required for Kafka. Read more about apache zookeeper.

~$ bin/zookeeper-server-start.sh config/zookeeper.properties

Now you need to configure Kafka IP, Broker ID, and other configs of the server. You can do this by editing the config/server.properties file.

Add “listeners=PLAINTEXT://” in kafka-server.config file. You can use the IP and port of your server and choice. Then run the below commands.

~$ bin/kafka-server-start.sh config/server.properties
~$ sudo ufw allow 9092/tcp

Now Kafka server is running, you can start to create topics and producing and consuming messages.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.