Home > Back-end >  kafka-server-start.sh failed with advertised.listeners set
kafka-server-start.sh failed with advertised.listeners set

Time:01-12

I am trying to start my kafka server on my localhost, and with the following two settings in config/server.properties:

listeners=PLAINTEXT://127.0.0.1:9092

# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
advertised.listeners=PLAINTEXT://host.docker.internal:9092

The reason I set advertised.listeners is because I want to run kafka-ui docker container, and it will connect to that listener, but as long as I set advertised.listeners, bin/kafka-server-start.sh config/server.properties failed with the following error:

[2023-01-12 00:06:33,814] WARN [Controller id=0, targetBrokerId=0] Error connecting to node host.docker.internal:9092 (id: 0 rack: null) (org.apache.kafka.clients.NetworkClient)
java.net.UnknownHostException: host.docker.internal
    at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:952)
    at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1658)
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1524)
    at org.apache.kafka.clients.DefaultHostResolver.resolve(DefaultHostResolver.java:27)
    at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:110)
    at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.currentAddress(ClusterConnectionStates.java:510)
    at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.access$200(ClusterConnectionStates.java:467)
    at org.apache.kafka.clients.ClusterConnectionStates.currentAddress(ClusterConnectionStates.java:173)
    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:292)
    at kafka.controller.RequestSendThread.doWork(ControllerChannelManager.scala:246)
    at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:96)

If I comment out advertised.listeners, it will work.

Can someone help me.

CodePudding user response:

Maybe the Kafka broker is unable to resolve the hostname "host.docker.internal". Try to add an IP address instead hostname (advertised.listeners=PLAINTEXT://xx.x.x.x:9092)

or add the hostname to /etc/hosts

Where is Kafka Broker running ?? Inside the Docker container??

  • Related