Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Kafka Socket server failed - Bind Exception

avatar
Contributor

I am trying to start kafka server. But I am getting the below error. Any idea about fix?

[2019-01-23 16:36:17,954] ERROR [KafkaServer id=0] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
org.apache.kafka.common.KafkaException: Socket server failed to bind to 0.0.0.0:9092: Address already in use.
at kafka.network.Acceptor.openServerSocket(SocketServer.scala:442)
at kafka.network.Acceptor.<init>(SocketServer.scala:332)
    at kafka.network.SocketServer$$anonfun$createAcceptorAndProcessors$1.apply(SocketServer.scala:149)
    at kafka.network.SocketServer$$anonfun$createAcceptorAndProcessors$1.apply(SocketServer.scala:145)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
    at kafka.network.SocketServer.createAcceptorAndProcessors(SocketServer.scala:145)
    at kafka.network.SocketServer.startup(SocketServer.scala:94)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:250)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
    at kafka.Kafka$.main(Kafka.scala:75)
    at kafka.Kafka.main(Kafka.scala)
    Caused by: java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
    at kafka.network.Acceptor.openServerSocket(SocketServer.scala:438)
2 REPLIES 2

avatar
Master Mentor

@Mahendiran Palani Samy

That's typical a port conflict issue "Socket server failed to bind to 0.0.0.0:9092:Address already inuse" Kafka listens on TCP port 9092 so this means there is already a process running on port 9092 change the port KafkaServer id=0 to something like 9093 or get the PID running on the port and kill it then restart kafka

# lsof -n -i :9092 | grep LISTEN

The PID should be the second column entry eg 7812 below

java 7812 root 205u IPv6 60200 0t0 TCP *:webcache (LISTEN)

Now kill the process

# kill -9 7812

Now your Kafka should restart successfully , if you are running multiple brokers do configure like below

broker.id=0
listeners=PLAINTEXT://:9092
log.dirs=/tmp/kafka-logs


server.1.properties
broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/tmp/kafka-logs1


server.2.properties
broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=/tmp/kafka-logs2


server.3.properties
broker.id=3
listeners=PLAINTEXT://:9095
log.dirs=/tmp/kafka-logs3


avatar
Master Mentor

@Mahendiran Palani Samy

Any updates if the answer resolved your issue please click "Accept" so that the thread is marked as close and can get referenced by other members for similar errors.