Apache Kafka is a powerful distributed event streaming platform used for real-time data processing, messaging, and logging. In this guide, we’ll walk through the step-by-step process of installing and setting up Kafka on Ubuntu 24.04.
1. Prerequisites
Before installing Kafka, ensure you have:
✅ A system running Ubuntu 24.04
✅ Java 17+ installed
✅ Root or sudo privileges
2. Install Java (OpenJDK 17)
Kafka requires Java to run. Install it with:
sudo apt update
sudo apt install openjdk-17-jdk -y
Verify Java installation:
java -version
Expected output (version may vary):
openjdk version "17.0.9" 2024-01-15
3. Download Apache Kafka
Visit the official Kafka download page and copy the latest binary version’s link. Then, download and extract it:
wget https://downloads.apache.org/kafka/3.6.0/kafka-3.9.0-src.tgz
tar -xvzf kafka-3.9.0-src.tgz
sudo mv kafka-3.9.0-src.tgz /opt/kafka
Navigate to Kafka’s directory:
cd /opt/kafka
4. Start Zookeeper
Kafka requires Zookeeper to manage broker nodes. Start Zookeeper with:
bash bin/zookeeper-server-start.sh config/zookeeper.properties
Leave this terminal open while running Kafka.
5. Start Kafka Broker
Open a new terminal and start the Kafka broker:
bin/kafka-server-start.sh config/server.properties
Leave this terminal open while using Kafka.
6. Create a Kafka Topic
Once Kafka is running, open a new terminal and create a test topic named test-topic
:
/opt/kafka/bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
Verify the topic list:
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092
7. Send and Consume Messages
Send a Message (Producer)
/opt/kafka/bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092
Type a message and press Enter.
Consume Messages (Consumer)
bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:9092
You should see the message you typed earlier.
Conclusion
Congratulations! 🎉 You have successfully installed and configured Apache Kafka on Ubuntu 24.04. Now, you can start using Kafka for real-time data streaming, event-driven architectures, and more.
Would you like a guide on integrating Kafka with NestJS? Let me know! 🚀
Top comments (0)