1. 程式人生 > >kafka啟動時報錯:java.net.UnknownHostException: Name or service not known

kafka啟動時報錯:java.net.UnknownHostException: Name or service not known

今天在用下面的指令啟動kafa的時候報錯了:

# bin/kafka-server-start.sh config/server.properties &
錯誤資訊如下:
[2018-04-11 16:27:31,185] ERROR [KafkaServer id=0] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.Kaf
java.net.UnknownHostException: bj1-10-112-179-12: bj1-10-112-179-12: 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
[2018-04-11 16:27:31,187] INFO [KafkaServer id=0] shutting down (kafka.server.KafkaServer)
[2018-04-11 16:27:31,189] INFO [SocketServer brokerId=0] Stopping socket server request processors (kafka.network.SocketServer)
[2018-04-11 16:27:31,208] INFO [SocketServer brokerId=0] Stopped socket server request processors (kafka.network.SocketServer)
[2018-04-11 16:27:31,211] INFO [ReplicaManager broker=0] Shutting down (kafka.server.ReplicaManager)
[2018-04-11 16:27:31,211] INFO [LogDirFailureHandler]: Shutting down (kafka.server.ReplicaManager$LogDirFailureHandler)
[2018-04-11 16:27:31,212] INFO [LogDirFailureHandler]: Stopped (kafka.server.ReplicaManager$LogDirFailureHandler)
[2018-04-11 16:27:31,212] INFO [LogDirFailureHandler]: Shutdown completed (kafka.server.ReplicaManager$LogDirFailureHandler)
[2018-04-11 16:27:31,212] INFO [ReplicaFetcherManager on broker 0] shutting down (kafka.server.ReplicaFetcherManager)
[2018-04-11 16:27:31,214] INFO [ReplicaFetcherManager on broker 0] shutdown completed (kafka.server.ReplicaFetcherManager)
[2018-04-11 16:27:31,214] INFO [ReplicaAlterLogDirsManager on broker 0] shutting down (kafka.server.ReplicaAlterLogDirsManager)
[2018-04-11 16:27:31,215] INFO [ReplicaAlterLogDirsManager on broker 0] shutdown completed (kafka.server.ReplicaAlterLogDirsMana
[2018-04-11 16:27:31,215] INFO [ExpirationReaper-0-Fetch]: Shutting down (kafka.server.DelayedOperationPurgatory$ExpiredOperatio
[2018-04-11 16:27:31,366] INFO [ExpirationReaper-0-Fetch]: Stopped (kafka.server.DelayedOperationPurgatory$ExpiredOperationReape
[2018-04-11 16:27:31,366] INFO [ExpirationReaper-0-Fetch]: Shutdown completed (kafka.server.DelayedOperationPurgatory$ExpiredOpe
[2018-04-11 16:27:31,366] INFO [ExpirationReaper-0-Produce]: Shutting down (kafka.server.DelayedOperationPurgatory$ExpiredOperat
[2018-04-11 16:27:31,565] INFO [ExpirationReaper-0-Produce]: Stopped (kafka.server.DelayedOperationPurgatory$ExpiredOperationRea
[2018-04-11 16:27:31,565] INFO [ExpirationReaper-0-Produce]: Shutdown completed (kafka.server.DelayedOperationPurgatory$ExpiredO
[2018-04-11 16:27:31,565] INFO [ExpirationReaper-0-DeleteRecords]: Shutting down (kafka.server.DelayedOperationPurgatory$Expired
[2018-04-11 16:27:31,567] INFO [ExpirationReaper-0-DeleteRecords]: Stopped (kafka.server.DelayedOperationPurgatory$ExpiredOperat
[2018-04-11 16:27:31,567] INFO [ExpirationReaper-0-DeleteRecords]: Shutdown completed (kafka.server.DelayedOperationPurgatory$Ex
[2018-04-11 16:27:31,571] INFO [ReplicaManager broker=0] Shut down completely (kafka.server.ReplicaManager)
[2018-04-11 16:27:31,571] INFO Shutting down. (kafka.log.LogManager)
[2018-04-11 16:27:31,583] INFO Shutdown complete. (kafka.log.LogManager)
[2018-04-11 16:27:31,584] INFO [ZooKeeperClient] Closing. (kafka.zookeeper.ZooKeeperClient)
[2018-04-11 16:27:31,585] INFO Processed session termination for sessionid: 0x162b3c499880001 (org.apache.zookeeper.server.PrepR
[2018-04-11 16:27:31,588] INFO Closed socket connection for client /127.0.0.1:39719 which had sessionid 0x162b3c499880001 (org.a
[2018-04-11 16:27:31,588] INFO Session: 0x162b3c499880001 closed (org.apache.zookeeper.ZooKeeper)
[2018-04-11 16:27:31,589] INFO EventThread shut down for session: 0x162b3c499880001 (org.apache.zookeeper.ClientCnxn)
[2018-04-11 16:27:31,589] INFO [ZooKeeperClient] Closed. (kafka.zookeeper.ZooKeeperClient)
[2018-04-11 16:27:31,590] INFO [ThrottledRequestReaper-Fetch]: Shutting down (kafka.server.ClientQuotaManager$ThrottledRequestRe
[2018-04-11 16:27:31,610] INFO [ThrottledRequestReaper-Fetch]: Stopped (kafka.server.ClientQuotaManager$ThrottledRequestReaper)
[2018-04-11 16:27:31,610] INFO [ThrottledRequestReaper-Fetch]: Shutdown completed (kafka.server.ClientQuotaManager$ThrottledRequ
[2018-04-11 16:27:31,611] INFO [ThrottledRequestReaper-Produce]: Shutting down (kafka.server.ClientQuotaManager$ThrottledRequest
[2018-04-11 16:27:32,611] INFO [ThrottledRequestReaper-Produce]: Stopped (kafka.server.ClientQuotaManager$ThrottledRequestReaper
[2018-04-11 16:27:32,611] INFO [ThrottledRequestReaper-Produce]: Shutdown completed (kafka.server.ClientQuotaManager$ThrottledRe
[2018-04-11 16:27:32,611] INFO [ThrottledRequestReaper-Request]: Shutting down (kafka.server.ClientQuotaManager$ThrottledRequest
[2018-04-11 16:27:32,612] INFO [ThrottledRequestReaper-Request]: Stopped (kafka.server.ClientQuotaManager$ThrottledRequestReaper
[2018-04-11 16:27:32,612] INFO [ThrottledRequestReaper-Request]: Shutdown completed (kafka.server.ClientQuotaManager$ThrottledRe
[2018-04-11 16:27:32,613] INFO [SocketServer brokerId=0] Shutting down socket server (kafka.network.SocketServer)
[2018-04-11 16:27:32,749] INFO [SocketServer brokerId=0] Shutdown completed (kafka.network.SocketServer)
[2018-04-11 16:27:32,754] INFO [KafkaServer id=0] shut down completed (kafka.server.KafkaServer)
[2018-04-11 16:27:32,754] ERROR Exiting Kafka. (kafka.server.KafkaServerStartable)
主要是這句:java.net.UnknownHostException: bj1-10-112-179-12: bj1-10-112-179-12: Name or service not known,提示找不到bj1-10-112-179-12這個名字(用hostname指令可以檢視我自己的計算機名就是bj1-10-112-179-12)

解決方法:

1.開啟/etc/hosts檔案,我的是這樣的

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
10.112.179.12 VM-10-112-179-12
2.改成如下
10.112.179.12 bj1-10-112-179-12 localhost
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
10.112.179.12 VM-10-112-179-12

問題解決

參考連結:https://stackoverflow.com/questions/1881546/inetaddress-getlocalhost-throws-unknownhostexception