问题描述
启动需要连接kafka服务的项目,报如下错误
09:57:01.336 [http-nio-8085-exec-3] WARN org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-group-1, groupId=XX-group] Error connecting to node MY_HOST_NAME:9092 (id: 0 rack: null)
java.net.UnknownHostException: MY_HOST_NAME
at java.net.InetAddress.getAllByName0(InetAddress.java:1281)
at java.net.InetAddress.getAllByName(InetAddress.java:1193)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
... ...
解决方案
配置:centos下单hosts文件
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#未知主机 MY_HOST_NAME 和 真实kafka服务器地址的映射
172.16.10.102 MY_HOST_NAME