最近,遇到了一个关于Dubbo应用启动的问题,在部署应用的过程中,应用无法成功连接到ZooKeeper进行服务注册。尽管telnet端口显示正常,排除了网络问题,但问题仍然存在。
首先,查看日志获取线索分析问题。日志中有很明显的连接ZooKeeper失败的错误:
java.lang.RuntimeException: Can not create registry service-discovery-registry
Caused by: java.lang.IllegalStateException: Create zookeeper service discovery failed
Caused by: java.lang.IllegalStateException: failed to connect to zookeeper server
确认应用到ZooKeeper服务器的网络正常,telnet端口是通的。因此直接尝试再次启动应用,仍然是这个错误,并且注意到输出以下日志前有较长时间的停顿:
INFO org.apache.zookeeper.ClientCnxn: Will not attempt to authenticate using SASL (unknown error)
虽然日志级别是INFO,但是这条日志与前一条ZooKeeper相关的日志间隔了20秒。
SASL全称Simple Authentication and Security Layer,是一种用来扩充C/S模式验证能力的机制。如果使用SASL身份验证,需要在客户端应用程序中配置相应的jaas.conf文件,以便能够通过SASL进行身份验证并与ZooKeeper进行安全通信。
确认不需要使用SASL身份验证,