本地服务启动连接Linux服务器上的kafka报错:Error connecting to node aaaa-9930:9092 (id: 0 rack: null) java.net.UnknownHostException: aaaa-9930

报错异常信息:UnknownHostException

10:52:12.565 [kafka-producer-network-thread | client1] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=client1] Error connecting to node aaaa-9930:9092 (id: 0 rack: null)
java.net.UnknownHostException: aaaa-9930
    at java.net.InetAddress.getAllByName0(InetAddress.java:1259)
    at java.net.InetAddress.getAllByName(InetAddress.java:1171)
    at java.net.InetAddress.getAllByName(InetAddress.java:1105)
    at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:110)
    at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.currentAddress(ClusterConnectionStates.java:403)
    at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.access$200(ClusterConnectionStates.java:363)
    at org.apache.kafka.clients.ClusterConnectionStates.currentAddress(ClusterConnectionStates.java:151)
    at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:962)
    at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:294)
    at org.apache.kafka.clients.producer.internals.Sender.sendProducerData(Sender.java:350)
    at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:323)
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:239)
    at java.lang.Thread.run(Thread.java:745)
10:52:12.666 [kafka-producer-network-thread | client1] DEBUG org.apache.kafka.clients.NetworkClient - [Producer clientId=client1] Give up sending metadata request since no node is available

本质原因是kafka配置文件server.properites中默认监听hostname:

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092 
#advertised.listeners=PLAINTEXT://8.88.88.88:9092

 

两种解决方案

1.修改配置文件,改为监听ip,将 advertised.listeners 中的your.host.name 改为服务器的IP地址即可:

#advertised.listeners=PLAINTEXT://your.host.name:9092 
advertised.listeners=PLAINTEXT://8.88.88.88:9092

2.修改本机的host文件,在host文件中添加如下信息:

8.88.88.88 aaaa-9930

 

posted @ 2022-11-09 11:05  BlogMemory  阅读(2424)  评论(0编辑  收藏  举报