Kafka启动报错java.net.UnknownHostException

今天安装kafka节点做实验,然后启动报如下错误:

[2020-08-15 16:27:31,185] ERROR [KafkaServer id=0] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.Kaf
java.net.UnknownHostException: bj-kafka-node1: bj-kafka-node1: Name or service not known
    at java.net.InetAddress.getLocalHost(InetAddress.java:1475)
    at kafka.server.KafkaServer$$anonfun$3.apply(KafkaServer.scala:387)
    at kafka.server.KafkaServer$$anonfun$3.apply(KafkaServer.scala:385)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
    at scala.collection.AbstractTraversable.map(Traversable.scala:104)
    at kafka.server.KafkaServer.createBrokerInfo(KafkaServer.scala:385)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:253)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
    at kafka.Kafka$.main(Kafka.scala:92)
    at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.UnknownHostException: bj1-10-112-179-12: Name or service not known
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295)
    at java.net.InetAddress.getLocalHost(InetAddress.java:1471)
    ... 13 more
[2020-08-15 16:27:31,187] INFO [KafkaServer id=0] shutting down (kafka.server.KafkaServer)
[2020-08-15 16:27:31,189] INFO [SocketServer brokerId=0] Stopping socket server request processors (kafka.network.SocketServer)
[2020-08-15 16:27:31,208] INFO [SocketServer brokerId=0] Stopped socket server request processors (kafka.network.SocketServer)
[2020-08-15 16:27:31,211] INFO [ReplicaManager broker=0] Shutting down (kafka.server.ReplicaManager)
[2020-08-15 16:27:31,211] INFO [LogDirFailureHandler]: Shutting down (kafka.server.ReplicaManager$LogDirFailureHandler)
[2020-08-15 16:27:31,212] INFO [LogDirFailureHandler]: Stopped (kafka.server.ReplicaManager$LogDirFailureHandler)
[2020-08-15 16:27:31,212] INFO [LogDirFailureHandler]: Shutdown completed (kafka.server.ReplicaManager$LogDirFailureHandler)
[2020-08-15 16:27:31,212] INFO [ReplicaFetcherManager on broker 0] shutting down (kafka.server.ReplicaFetcherManager)
[2020-08-15 16:27:31,214] INFO [ReplicaFetcherManager on broker 0] shutdown completed (kafka.server.ReplicaFetcherManager)
[2020-08-15 16:27:31,214] INFO [ReplicaAlterLogDirsManager on broker 0] shutting down (kafka.server.ReplicaAlterLogDirsManager)
[2020-08-15 16:27:31,215] INFO [ReplicaAlterLogDirsManager on broker 0] shutdown completed (kafka.server.ReplicaAlterLogDirsMana
[2020-08-15 16:27:31,215] INFO [ExpirationReaper-0-Fetch]: Shutting down (kafka.server.DelayedOperationPurgatory$ExpiredOperatio
[2020-08-15 16:27:31,366] INFO [ExpirationReaper-0-Fetch]: Stopped (kafka.server.DelayedOperationPurgatory$ExpiredOperationReape
[2020-08-15 16:27:31,366] INFO [ExpirationReaper-0-Fetch]: Shutdown completed (kafka.server.DelayedOperationPurgatory$ExpiredOpe
[2020-08-15 16:27:31,366] INFO [ExpirationReaper-0-Produce]: Shutting down (kafka.server.DelayedOperationPurgatory$ExpiredOperat
[2020-08-15 16:27:31,565] INFO [ExpirationReaper-0-Produce]: Stopped (kafka.server.DelayedOperationPurgatory$ExpiredOperationRea
[2020-08-15 16:27:31,565] INFO [ExpirationReaper-0-Produce]: Shutdown completed (kafka.server.DelayedOperationPurgatory$ExpiredO
[2020-08-15 16:27:31,565] INFO [ExpirationReaper-0-DeleteRecords]: Shutting down (kafka.server.DelayedOperationPurgatory$Expired
[2020-08-15 16:27:31,567] INFO [ExpirationReaper-0-DeleteRecords]: Stopped (kafka.server.DelayedOperationPurgatory$ExpiredOperat
[2020-08-15 16:27:31,567] INFO [ExpirationReaper-0-DeleteRecords]: Shutdown completed (kafka.server.DelayedOperationPurgatory$Ex
[2020-08-15 16:27:31,571] INFO [ReplicaManager broker=0] Shut down completely (kafka.server.ReplicaManager)
[2020-08-15 16:27:31,571] INFO Shutting down. (kafka.log.LogManager)
[2020-08-15 16:27:31,583] INFO Shutdown complete. (kafka.log.LogManager)
[2020-08-15 16:27:31,584] INFO [ZooKeeperClient] Closing. (kafka.zookeeper.ZooKeeperClient)
[2020-08-15 16:27:31,585] INFO Processed session termination for sessionid: 0x162b3c499880001 (org.apache.zookeeper.server.PrepR
[2020-08-15 16:27:31,588] INFO Closed socket connection for client /127.0.0.1:39719 which had sessionid 0x162b3c499880001 (org.a
[2020-08-15 16:27:31,588] INFO Session: 0x162b3c499880001 closed (org.apache.zookeeper.ZooKeeper)
[2020-08-15 16:27:31,589] INFO EventThread shut down for session: 0x162b3c499880001 (org.apache.zookeeper.ClientCnxn)
[2020-08-15 16:27:31,589] INFO [ZooKeeperClient] Closed. (kafka.zookeeper.ZooKeeperClient)
[2020-08-15 16:27:31,590] INFO [ThrottledRequestReaper-Fetch]: Shutting down (kafka.server.ClientQuotaManager$ThrottledRequestRe
[2020-08-15 16:27:31,610] INFO [ThrottledRequestReaper-Fetch]: Stopped (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
[2020-08-15 16:27:31,610] INFO [ThrottledRequestReaper-Fetch]: Shutdown completed (kafka.server.ClientQuotaManager$ThrottledRequ
[2020-08-15 16:27:31,611] INFO [ThrottledRequestReaper-Produce]: Shutting down (kafka.server.ClientQuotaManager$ThrottledRequest
[2020-08-15 16:27:32,611] INFO [ThrottledRequestReaper-Produce]: Stopped (kafka.server.ClientQuotaManager$ThrottledRequestReaper
[2020-08-15 16:27:32,611] INFO [ThrottledRequestReaper-Produce]: Shutdown completed (kafka.server.ClientQuotaManager$ThrottledRe
[2020-08-15 16:27:32,611] INFO [ThrottledRequestReaper-Request]: Shutting down (kafka.server.ClientQuotaManager$ThrottledRequest
[2020-08-15 16:27:32,612] INFO [ThrottledRequestReaper-Request]: Stopped (kafka.server.ClientQuotaManager$ThrottledRequestReaper
[2020-08-15 16:27:32,612] INFO [ThrottledRequestReaper-Request]: Shutdown completed (kafka.server.ClientQuotaManager$ThrottledRe
[2020-08-15 16:27:32,613] INFO [SocketServer brokerId=0] Shutting down socket server (kafka.network.SocketServer)
[2020-08-15 16:27:32,749] INFO [SocketServer brokerId=0] Shutdown completed (kafka.network.SocketServer)
[2020-08-15 16:27:32,754] INFO [KafkaServer id=0] shut down completed (kafka.server.KafkaServer)
[2020-08-15 16:27:32,754] ERROR Exiting Kafka. (kafka.server.KafkaServerStartable)
已邀请:

空心菜 - 牛逼你来

赞同来自: chris

关键信息在于:
java.net.UnknownHostException: bj-kafka-node1: bj-kafka-node1: Name or service not known
不管你怎么设置Kafka配置文件,设置listeners 、advertised.listeners 还是 host.name,  kafka默认都会通过InetAddress localhost = InetAddress.getLocalHost() 去解析主机名。

我也不知道Kafka为啥要做这种强依赖设计,我觉得是烂设计了,希望以后改进。

解决方法,就是/etc/hosts添加你的主机的ip对应的主机名bj-kafka-node1的映射记录。
参考: https://stackoverflow.com/questions/1881546/inetaddress-getlocalhost-throws-unknownhostexception 

要回复问题请先登录注册