Set up Kafka in local

Anukool DixitAnukool Dixit
2 min read

Table of contents

To run Kafka on Ubuntu using the terminal, you can follow these steps. Please note that these instructions assume you have Java installed on your system.

  1. Download Apache Kafka: Download the latest version of Apache Kafka from the official Apache Kafka website: https://kafka.apache.org/downloads

    For example, you can use wget to download Kafka:

     wget https://downloads.apache.org/kafka/2.8.0/kafka_2.13-2.8.0.tgz
    

    Extract the downloaded archive:

     tar -xzf kafka_2.13-2.8.0.tgz
    

    Navigate to the Kafka directory:

     cd kafka_2.13-2.8.0
    
  2. Start Zookeeper: Kafka uses Zookeeper for coordination. Start Zookeeper in a new terminal:

     bin/zookeeper-server-start.sh config/zookeeper.properties
    
  3. Start Kafka Broker: In a new terminal, start the Kafka broker:

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

    Kafka should now be running.

  4. Create a Topic: In another terminal, create a Kafka topic. Replace "my-topic" with your desired topic name:

     bin/kafka-topics.sh --create --topic my-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
    
  5. Produce and Consume Messages: In separate terminals, you can produce and consume messages. Replace "my-topic" with your actual topic name:

    • Produce messages:

        bin/kafka-console-producer.sh --topic my-topic --bootstrap-server localhost:9092
      
    • Consume messages:

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

Now, you have Kafka running on your Ubuntu machine, and you can produce and consume messages using the Kafka command-line tools.

Keep in mind that this is a basic setup, and for production environments, you would need to configure Kafka and Zookeeper appropriately, considering factors like replication, security, and tuning. Always refer to the official Kafka documentation for more details: https://kafka.apache.org/documentation/

0
Subscribe to my newsletter

Read articles from Anukool Dixit directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anukool Dixit
Anukool Dixit