首页 > 解决方案 > 启动 kafka 服务器时出现“java.nio.channels.UnresolvedAddressException”

问题描述

之后我启动了 zookeeper,我运行了“kafka-server-start.bat mypath\server.properties”命令来启动 kafka 服务器。

在 kafka 服务器窗口中出现以下错误。

 INFO Opening socket connection to server localhost/<unresolved>:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
 WARN Session 0x0 for server localhost/<unresolved>:2181, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
 java.nio.channels.UnresolvedAddressException
  at java.base/sun.nio.ch.Net.checkAddress(Net.java:149)
  at java.base/sun.nio.ch.Net.checkAddress(Net.java:157)
  at java.base/sun.nio.ch.SocketChannelImpl.checkRemote(SocketChannelImpl.java:815)
  at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:837)
  at org.apache.zookeeper.ClientCnxnSocketNIO.registerAndConnect(ClientCnxnSocketNIO.java:277)
  at org.apache.zookeeper.ClientCnxnSocketNIO.connect(ClientCnxnSocketNIO.java:287)
  at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1021)
  at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1064)

以下是 server.properties 中的属性

num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=C:\KafkaLog
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=localhost:2181
zookeeper.connection.timeout.ms=6000
confluent.support.metrics.enable=true
confluent.support.customer.id=anonymous
group.initial.rebalance.delay.ms=0

Zookeeper 属性是

dataDir=C:\ZookeeperLog
clientPort=2181
maxClientCnxns=0

标签: windowsapache-kafkaapache-zookeeper

解决方案


我们尝试检查以下事项以解决它们。

  1. 更新了配置文件中的dataDir&log.dirs属性(用于匹配 windows 平台)
  2. 使用命令验证zookeeper启动netstat -aon | findstr '2181'
  3. zookeeper.connect将网址更新为127.0.0.1:2181
  4. 在文件中添加了以下缺少的环回条目hosts并重新启动了系统。

127.0.0.1 localhost


推荐阅读