情况:

本地测试zookeeper客户端报错,解析错误

核心报错信息:
java.lang.IllegalArgumentException: Unable to canonicalize address localhost/:2181 because it’s not resolvable


问题描述

错误一:

[2024-01-30 17:30:50,097] WARN Session 0x0 for server localhost/<unresolved>:2181, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.lang.IllegalArgumentException: Unable to canonicalize address localhost/<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)

在这里插入图片描述
执行./zkCli.sh之后,会出现报错信息以及客户端链接JDK情况。原先是安装的JDK21版本,出现了localhost/<unresolved>:2181 because it's not resolvable报错

错误二:
本地修改了/etc/profile的JDK环境变量配置,source之后还是不生效。


原因分析:

错误一:原因是因为JDK的版本太高,需要使用JDK8版本。

错误二:主要是因为linux电脑,不是root权限下,bash时候不会去读etc/profile文件,需要去修改/.bashrc

可以参考:https://www.yisu.com/ask/25763933.html


解决方案:

问题一:修改JDK版本为JDK8
问题二:根据上述参考,修改/.bashrc文件

步骤一:检查是否正确配置了环境变量。在Bash shell中,可以编辑/.bashrc或/.bash_profile文件,添加类似以下内容:

export JAVA_HOME=/path/to/jdk
export PATH=$PATH:$JAVA_HOME/bin

步骤二:重新加载配置文件:在配置环境变量之后,使用source命令重新加载配置文件,例如:

source ~/.bashrc

补充排查命令:

which java
java -version
$JAVA_HOME
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐