Dubbo环境搭建报错:无法规范化127.0.0.1/<unresolved>:2181地址
解决Dubbo连接ZooKeeper时的地址解析异常(Unable to canonicalize address)
问题场景
搭建Dubbo环境时出现ZooKeeper连接异常,核心报错信息如下:
2024-09-12 10:16:28.896 INFO 18540 --- [ main] o.a.d.c.d.DefaultApplicationDeployer : [DUBBO] use registry as config-center: <dubbo:config-center highestPriority="false" id="config-center-zookeeper-127.0.0.1-2181" address="zookeeper://127.0.0.1:2181" protocol="zookeeper" port="2181" parameters="{client=null}" />, dubbo version: 3.2.5, current host: 192.168.31.116 2024-09-12 10:16:29.106 WARN 18540 --- [127.0.0.1:2181)] org.apache.zookeeper.ClientCnxn : Session 0x0 for server 127.0.0.1/<unresolved>:2181, unexpected error, closing socket connection and attempting reconnect java.lang.IllegalArgumentException: Unable to canonicalize address 127.0.0.1/<unresolved>:2181 because it's not resolvable at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:65) at org.apache.zookeeper.SaslServerPrincipal.getServerPrincipal(SaslServerPrincipal.java:41) at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1001) at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1060)
使用环境:
- Dubbo Admin Server: 0.7.0
- ZooKeeper: 3.9.2
- JDK: 1.8
已尝试更换JDK、Dubbo Admin及ZooKeeper版本,问题仍未解决。
解决方案
1. 禁用ZooKeeper的SASL认证
该异常由SASL认证过程中地址解析失败触发,直接禁用SASL可绕过问题:
- YAML配置方式:
dubbo: registry: address: zookeeper://127.0.0.1:2181 parameters: zookeeper.sasl.enabled: false - XML配置方式:
<dubbo:registry address="zookeeper://127.0.0.1:2181"> <dubbo:parameter key="zookeeper.sasl.enabled" value="false"/> </dubbo:registry> - JVM启动参数方式:启动Dubbo Admin时添加
-Dzookeeper.sasl.client=false
2. 修复本地hosts文件的地址映射
确保127.0.0.1能正确解析到localhost:
- 打开系统hosts文件:
- Windows:
C:\Windows\System32\drivers\etc\hosts - Linux/Mac:
/etc/hosts
- Windows:
- 添加或确认以下映射:
127.0.0.1 localhost ::1 localhost - 刷新DNS缓存:
- Windows:执行
ipconfig /flushdns - Linux/Mac:执行
sudo dscacheutil -flushcache(Mac)或sudo systemctl restart nscd(Linux)
- Windows:执行
3. 替换ZooKeeper连接地址
将配置中的zookeeper://127.0.0.1:2181改为zookeeper://localhost:2181,部分环境下localhost的解析逻辑更稳定。
4. 调整ZooKeeper绑定地址
修改ZooKeeper配置文件conf/zoo.cfg,确保客户端端口绑定的地址可被本地解析:
# 允许所有地址访问,或明确设置为127.0.0.1/localhost clientPortAddress=0.0.0.0
内容的提问来源于stack exchange,提问作者Chen
相关产品推荐
相关产品推荐

