How to quickly install and start Kafka

144 Uncategorized Leave a Comment

Install and start Kafka is quite simple even on you local computer.

Maybe you are thinking it must need lots of dependencies, but the fact is, it only needs Java.

No database, no complicate configuration are needed, so you also no need to install Docker to run it.

How to install and start Kafka

Following are some simple steps about How to quickly install and start Kafka.

Note: please make sure your local environment have installed Java 8+

  1. Download Kafka binary tgz package from Kafka download page
  2. Unzip it:
    $ tar -xzf kafka_2.13-3.2.0.tgz
    $ cd kafka_2.13-3.2.0
  3. Because Kafka depends on zookeeper, so we should start zookeeper before Kafka:
    $ bin/zookeeper-server-start.sh config/zookeeper.properties

    Note: Soon, ZooKeeper will no longer be required by Apache Kafka.

  4. Edit config/server.properties file:
    $ vim config/server.properties

    Change following line:

    #listeners=PLAINTEXT://:9092

    to:

    listeners=PLAINTEXT://localhost:9092
  5. Start Kafka:
    $ bin/kafka-server-start.sh config/server.properties

    Then Kafka will start on 9092 port.

  6. Test it, produce some messages:
    $ bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test_topic
    >test message 1
    >test message 2

    Consume the messages:

    $ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic
    test message 1
    test message 2

Issues

  1. Error connecting to node 0.0.0.1:9092 … java.net.NoRouteToHostException: No route to host

Detail issue is:

[2022-05-25 16:28:22,997] WARN [Controller id=0, targetBrokerId=0] Error connecting to node 0.0.0.1:9092 (id: 0 rack: null) (org.apache.kafka.clients.NetworkClient)
java.net.NoRouteToHostException: No route to host
    at java.base/sun.nio.ch.Net.connect0(Native Method)
    at java.base/sun.nio.ch.Net.connect(Net.java:483)
    at java.base/sun.nio.ch.Net.connect(Net.java:472)
    at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:692)
    at org.apache.kafka.common.network.Selector.doConnect(Selector.java:277)
    at org.apache.kafka.common.network.Selector.connect(Selector.java:255)
    at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:990)
    at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:301)
    at org.apache.kafka.clients.NetworkClientUtils.awaitReady(NetworkClientUtils.java:64)
    at kafka.controller.RequestSendThread.brokerReady(ControllerChannelManager.scala:291)
    at kafka.controller.RequestSendThread.doWork(ControllerChannelManager.scala:245)
    at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:96)

To solve it, we should change following configuration as STEP 4 above:

#listeners=PLAINTEXT://:9092

to:

listeners=PLAINTEXT://localhost:9092

Leave a Reply

Your email address will not be published.

Name *