Logo

dev-resources.site

for different kinds of informations.

Apache Kafka on Amazon Linux EC2

Published at
7/31/2024
Categories
apachekafka
amazonlinux
ec2
Author
sagarlakshmipathy
Categories
3 categories in total
apachekafka
open
amazonlinux
open
ec2
open
Author
17 person written this
sagarlakshmipathy
open
Apache Kafka on Amazon Linux EC2

In this article, we will walk through the steps to set up Apache Kafka on an Amazon EC2 instance (Amazon Linux distribution). We'll start with updating the system, installing Java, and then proceed with the installation and configuration of Kafka. By the end, you'll have a running Kafka instance, ready for producing and consuming messages.

Prerequisites

An Amazon EC2 instance (running Amazon Linux 2 or a similar distribution)
Basic knowledge of using the terminal

Steps

Step 1: Update the System

First, ensure your system is up to date by running:

sudo yum update -y
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Java

Apache Kafka requires Java to run. Install Java 11 using the following command:

sudo yum install java-11-amazon-corretto-devel -y
Enter fullscreen mode Exit fullscreen mode

Step 3: Download and Extract Kafka

Next, download Kafka from the official Apache archive and extract it:

wget https://archive.apache.org/dist/kafka/3.3.1/kafka_2.12-3.3.1.tgz
tar -xzf kafka_2.12-3.3.1.tgz
cd kafka_2.12-3.3.1
Enter fullscreen mode Exit fullscreen mode

Step 4: Start Zookeeper

Kafka requires Zookeeper to manage its cluster. Start Zookeeper with:

nohup bin/zookeeper-server-start.sh config/zookeeper.properties > zookeeper.log 2>&1 &
Enter fullscreen mode Exit fullscreen mode

Step 5: Configure Kafka

Edit the Kafka configuration file to set the advertised listeners. Replace ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com with your EC2 instance's public DNS:

vi config/server.properties
Enter fullscreen mode Exit fullscreen mode

Add the following line:

advertised.listeners=PLAINTEXT://ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:9092
Enter fullscreen mode Exit fullscreen mode

Step 6: Start Kafka Server

Now, start the Kafka server:

nohup bin/kafka-server-start.sh config/server.properties > kafka-server.log 2>&1 &
Enter fullscreen mode Exit fullscreen mode

Step 7: Create a Topic

Create a new Kafka topic named test:

bin/kafka-topics.sh --create --topic test --bootstrap-server ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:9092 --partitions 1 --replication-factor 1
Enter fullscreen mode Exit fullscreen mode

Step 8: Produce Messages

Start a Kafka producer to send messages to the test topic:

bin/kafka-console-producer.sh --topic test --bootstrap-server ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:9092
Enter fullscreen mode Exit fullscreen mode

You can now type messages into the console, and they will be sent to the Kafka topic.

Step 9: Consume Messages

Start a Kafka consumer to read messages from the test topic:

bin/kafka-console-consumer.sh --topic test --bootstrap-server ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:9092 --from-beginning
Enter fullscreen mode Exit fullscreen mode

You should see the messages you produced earlier displayed in the console.

Conclusion

By following these steps, you've successfully set up Apache Kafka on an Amazon EC2 instance. You can now produce and consume messages, enabling you to build real-time data streaming applications. This setup forms the foundation for more advanced Kafka configurations and use cases.

Feel free to explore Kafka's extensive features and tailor the configuration to suit your specific requirements. Happy streaming!

apachekafka Article's
30 articles in total
Favicon
Mastering Apache Kafka: A Complete Guide to the Heart of Real-Time Data Streaming
Favicon
AIM Weekly for 11/11/2024
Favicon
Apache Kafka: A Simple Guide to Messaging and Streaming
Favicon
Design a real-time data processing
Favicon
Building a Scalable Data Pipeline with Apache Kafka
Favicon
Building a Scalable Data Pipeline with Apache Kafka
Favicon
Implementing AI with Scikit-Learn and Kafka: A Complete Guide
Favicon
Understanding the Importance of Kafka in High-Volume Data Environments
Favicon
How can i stop my kafka consumer from consuming messages ?
Favicon
Getting Started with Apache Kafka: A Beginner's Guide to Distributed Event Streaming
Favicon
πŸš€ Apache Kafka Cluster Explained: Core Concepts and Architectures 🌐
Favicon
WarpStream Newsletter #5: Dealing with Rejection, Schema Validation, and Time Lag
Favicon
Dealing with rejection (in distributed systems)
Favicon
Apache Kafka on Amazon Linux EC2
Favicon
Announcing WarpStream Schema Validation
Favicon
The Kafka Metric You’re Not Using: Stop Counting Messages, Start Measuring Time
Favicon
WarpStream Newsletter #4: Data Pipelines, Zero Disks, BYOC and More
Favicon
Integrating Apache Kafka with Apache AGE for Real-Time Graph Processing
Favicon
Integrating Apache Kafka with Apache AGE for Real-Time Graph Processing
Favicon
Multiple Regions, Single Pane of Glass
Favicon
FLaNK-AIM: 20 May 2024 Weekly
Favicon
Secure by default: How WarpStream’s BYOC deployment model secures the most sensitive workloads
Favicon
Zero Disks is Better (for Kafka)
Favicon
FLaNK AI-April 22,Β 2024
Favicon
Pixel Federation Powers Mobile Analytics Platform with WarpStream, saves 83% over MSK
Favicon
FLaNK AI - 15 April 2024
Favicon
WarpStream Newsletter #3: Always Be Shipping
Favicon
Introducing WarpStream Managed Data Pipelines for BYOC Clusters
Favicon
Apache Kafka
Favicon
FLaNK-AIM Weekly 06 May 2024

Featured ones: