dubbo-admin 因连接ZooKeeper超时启动失败问题

一、遇见的问题

1.1 问题背景

dubbo-admin开源项目地址:https://github.com/apache/dubbo-admin/blob/master/README_ZH.md

尝试本地运行 dubbo-admin 项目,项目的后端部分是一个纯SpringBoot工程,按理说只需要配置一下我的注册中心的地址就可以在本地运行。但是每次运行都会报错。

1.2 问题描述

  1. 启动失败,报错信息为 failed to connect to zookeeper server 下载下来的Dubbo-admin项目,运行其 dubbo-admin-server 的SpringBoot项目启动失败。下载下来后仅仅修改过三个注册相关的Zookeeper地址。
# centers in dubbo2.7, if you want to add parameters, please add them to the url
admin.registry.address=
admin.config-center=
admin.metadata-report.address=

报错信息

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-07-13 02:15:59.659 ERROR 2712 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getServiceDiscoveryRegistry' defined in class path resource [org/apache/dubbo/admin/config/ConfigCenter.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.dubbo.registry.client.ServiceDiscovery]: Factory method 'getServiceDiscoveryRegistry' threw exception; nested exception is java.lang.IllegalStateException: Create zookeeper service discovery failed.
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:485)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1341)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1181)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:755)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:402)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236)
	at org.apache.dubbo.admin.DubboAdminApplication.main(DubboAdminApplication.java:35)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.dubbo.registry.client.ServiceDiscovery]: Factory method 'getServiceDiscoveryRegistry' threw exception; nested exception is java.lang.IllegalStateException: Create zookeeper service discovery failed.
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:652)
	... 20 common frames omitted
Caused by: java.lang.IllegalStateException: Create zookeeper service discovery failed.
	at org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.<init>(ZookeeperServiceDiscovery.java:77)
	at org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscoveryFactory.createDiscovery(ZookeeperServiceDiscoveryFactory.java:27)
	at org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory.lambda$getServiceDiscovery$0(AbstractServiceDiscoveryFactory.java:53)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
	at org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory.getServiceDiscovery(AbstractServiceDiscoveryFactory.java:53)
	at org.apache.dubbo.admin.config.ConfigCenter.getServiceDiscoveryRegistry(ConfigCenter.java:187)
	at org.apache.dubbo.admin.config.ConfigCenter$$EnhancerBySpringCGLIB$$8706a7ed.CGLIB$getServiceDiscoveryRegistry$3(<generated>)
	at org.apache.dubbo.admin.config.ConfigCenter$$EnhancerBySpringCGLIB$$8706a7ed$$FastClassBySpringCGLIB$$c84e93b5.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at org.apache.dubbo.admin.config.ConfigCenter$$EnhancerBySpringCGLIB$$8706a7ed.getServiceDiscoveryRegistry(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 21 common frames omitted
Caused by: java.lang.IllegalStateException: failed to connect to zookeeper server
	at org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkUtils.buildCuratorFramework(CuratorFrameworkUtils.java:75)
	at org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.<init>(ZookeeperServiceDiscovery.java:72)
	... 36 common frames omitted
  1. 更换本机的 ZooKeeper 地址就能启动成功

二、问题分析

2.1 问题原因分析

  1. 应该是连接远程的 ZooKeeper 网络耗时更长,导致连接超时了

2.2 解决方向

  1. 第一步 验证远程的ZooKeeper服务是否正常
  2. 如果正常,则 debug 判断是否是超时配置导致未连接成功。如果超时则尝试修改Dubbo的超时配置
    1. dubbo有注册中心超时时间 dubbo.registry.timeout 是启动时注册配置中心就要用的
    2. dubbo 的 dubbo.config-center.timeout 是获取配置可能用到的

三、问题解决

3.1 确定原因

确定远程ZooKeeper是否正常
通过可视化桌面连接软件直接连接远程ZooKeeper 发现连接正常但是稍慢,那很大肯能性就是连接超时
image.png

3.2 解决过程

debug定位问题

  1. 使用curator 连接Zookeeper时出问题导致抛出异常 org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery#ZookeeperServiceDiscovery

4702d2fa8d4c5ac6ddb671cae3ae3b6.png

  1. 继续定位 发现 dubbo使用curator连接ZooKeeper时,使用了 blockUntilConnected 这个方法,这里的默认超时时间是10秒 org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkUtils#buildCuratorFramework
  2. 这里的超时时间,默认值为 Dubbo 提前定义的枚举中获取,但是也可以从URL中获取,org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParamsimage.png
  3. 修改配置
    1. 结果可行】直接修改URL admin.registry.address=zookeeper://127.0.0.1:15881?blockUntilConnectedWait=50 image.png
    2. 结果可行】修改dubbo配置,dubbo会自动拼接到url上 dubbo.registry.timeout=50000

image.png

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Dubbo-AdminDubbo 提供的一个可视化管理平台,用于监控和管理 Dubbo 服务。安装和部署 Dubbo-Admin 需要以下步骤: 1. 下载 Dubbo-Admin 的安装包,可以从 Dubbo 的官方 GitHub 仓库中获取。你可以访问 https://github.com/apache/dubbo-admin/releases 下载最新版本的安装包。 2. 解压下载的安装包到你选择的目录。你可以使用以下命令解压: ```shell unzip dubbo-admin-x.x.x.zip ``` 3. 进入解压后的目录,找到 `dubbo-admin-server` 目录。 4. 打开 `dubbo-admin-server` 目录下的 `src/main/resources/application.properties` 文件,修改其中的配置信息。 - 配置 Dubbo 注册中心的地址:`dubbo.registry.address=zookeeper://localhost:2181`,根据你实际的注册中心地址进行修改。 - 配置 Dubbo Admin 的访问端口:`server.port=8080`,根据你的需求进行修改。 5. 保存并关闭 `application.properties` 文件。 6. 在 `dubbo-admin-server` 目录下执行以下命令来构建 Dubbo-Admin: ```shell mvn clean package ``` 7. 构建完成后,进入 `target` 目录,执行以下命令来启动 Dubbo-Admin: ```shell java -jar dubbo-admin-x.x.x.jar ``` 8. 等待启动完成,访问 http://localhost:8080 即可进入 Dubbo-Admin 的管理界面。 请注意,安装和部署 Dubbo-Admin 需要满足以下依赖条件: - JDK 1.8 或以上版本 - Maven 3.x - ZooKeeper 3.x 或以上版本 希望以上步骤对你有帮助!如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值