Set up Kafka in local

Table of contents

No heading

No headings in the article.

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: 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: kafka.apache.org/documentation