Kafka - Installation


1. Introduction to Kafka Installation

Installing Apache Kafka involves setting up a Kafka broker along with Zookeeper, which manages the cluster metadata and coordinates broker actions. This guide provides step-by-step instructions for installing Kafka on a Linux-based system, along with necessary configurations to start a Kafka server.


2. Prerequisites for Kafka Installation

Before installing Kafka, ensure that your system meets the following prerequisites:


3. Step-by-Step Kafka Installation


3.1. Install Java Development Kit (JDK)

Ensure that Java is installed on your system. You can check your Java installation by running the following command:

java -version

If Java is not installed, use the following command to install it:

sudo apt-get install default-jdk

3.2. Download and Extract Kafka

Download the latest Kafka binary package from the official Apache Kafka website. Once downloaded, extract the package using the following command:

tar -xzf kafka_2.13-2.8.0.tgz

Navigate to the Kafka directory:

cd kafka_2.13-2.8.0

3.3. Start Zookeeper Server

Kafka requires Zookeeper to be running. Start the Zookeeper server using the following command:

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

3.4. Start Kafka Server

Open a new terminal window and start the Kafka server using the following command:

bin/kafka-server-start.sh config/server.properties

4. Verifying Kafka Installation


4.1. Create a Kafka Topic

Create a new Kafka topic to verify that Kafka is functioning correctly. Use the following command to create a topic named "test-topic":

bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1

4.2. List Kafka Topics

Verify the creation of the topic by listing all topics. Use the following command:

bin/kafka-topics.sh --list --bootstrap-server localhost:9092

4.3. Produce Messages

Start a Kafka producer to send messages to the "test-topic" using the following command:

bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092

Type messages and press Enter to send them.


4.4. Consume Messages

Open a new terminal window and start a Kafka consumer to read messages from the "test-topic" using the following command:

bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:9092

The messages sent by the producer should appear in the consumer's terminal.


5. Notes and Considerations

After verifying the installation, you can start building applications that use Kafka for messaging. Ensure to secure and optimize your Kafka setup for production use, including configuring log retention, tuning performance, and implementing security measures.


6. Additional Resources and References