Installing Kafka on Debian Latest
Kafka is a distributed message broker that is used to handle large amounts of data in real-time. In this tutorial, we will show you how to install Kafka on Debian latest.
Prerequisites
Before we begin, ensure that your system meets the following requirements:
- A machine running Debian latest
- A non-root user with sudo privileges
- Java version 8 or higher
Step 1: Install Java
You must have Java installed on your system to run Kafka. You can check if Java is already installed by running the following command:
java -version
If Java is not installed, you can install OpenJDK 8 with the following command:
sudo apt-get update
sudo apt-get install openjdk-8-jdk
Verify that Java is installed by running the java -version command again.
Step 2: Download Kafka
Next, download the latest version of Kafka from the Kafka official website by running the following command:
wget https://downloads.apache.org/kafka/2.8.1/kafka_2.12-2.8.1.tgz
Step 3: Extract Kafka
Once the download is complete, you need to extract the tar file with the following command:
tar -xzf kafka_2.12-2.8.1.tgz
Step 4: Start the Kafka Server
You can start the Kafka server by navigating to the extracted Kafka directory and starting the server using the following command:
cd kafka_2.12-2.8.1
./bin/kafka-server-start.sh config/server.properties
This will start the Kafka server on the default port 9092.
Step 5: Create a Kafka Topic
To create a new topic, open a new terminal window and navigate to the Kafka directory. Use the following command to create a new topic:
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test-topic
This will create a new topic named test-topic.
Step 6: Produce and Consume Messages
Now that you have created a Kafka topic, you can start producing and consuming messages. In a new terminal window, use the following command to start producing messages:
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test-topic
In another terminal window, use the following command to start consuming messages:
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning
This will start printing the messages that have been produced in the previous terminal window.
Conclusion
By following the above steps, you have successfully installed and configured a Kafka server on Debian Latest. You can now create and manage Kafka topics and produce and consume messages.