nacos集群服务注册orderservice失败原因分析及解决方案

2023年2月15日
大约 5 分钟

nacos集群服务注册orderservice失败原因分析及解决方案

问题现象

Nacos单机部署时,orderservice服务启动不会出现任何问题,但是Nacos集群部署时,orderservice服务启动提示服务注册失败,其他服务都可以正常注册成功,只有orderservice注册失败。

异常信息如下:

02-10 15:30:20:762 ERROR 16573 --- [           main] c.a.cloud.nacos.discovery.NacosWatch     : namingService subscribe failed, properties:NacosDiscoveryProperties{serverAddr='localhost:8848', endpoint='', namespace='', watchDelay=30000, logName='', service='orderservice', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.121.1', networkInterface='', port=-1, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, failFast=true}

com.alibaba.nacos.api.exception.NacosException: Request nacos server failed:
at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:279) ~[nacos-client-2.0.3.jar:na]
at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doSubscribe(NamingGrpcClientProxy.java:227) ~[nacos-client-2.0.3.jar:na]
at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.subscribe(NamingGrpcClientProxy.java:212) ~[nacos-client-2.0.3.jar:na]
at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.subscribe(NamingClientProxyDelegate.java:147) ~[nacos-client-2.0.3.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.subscribe(NacosNamingService.java:393) ~[nacos-client-2.0.3.jar:na]
at com.alibaba.cloud.nacos.discovery.NacosWatch.start(NacosWatch.java:134) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.7.RELEASE.jar:2.2.7.RELEASE]
...

问题分析

网上有很多不同的说法,目前这错误排查原因是由于SpringBoot版本和Nacos版本不一致而导致冲突。下面先看一下官方提供的版本依赖关系组件版本关系

版本依赖关系

由于Spring Boot 3.0Spring Boot 2.7~2.4和2.4以下版本之间变化较大,目前企业级客户老项目相关 Spring Boot 版本仍停留在Spring Boot 2.4以下,为了同时满足存量用户和新用户不同需求,社区以Spring Boot 3.02.4分别为分界线,同时维护2022.x2021.x2.2.x三个分支迭代。如果不想跨分支升级,如需使用新特性,请升级为对应分支的新版本。 为了规避相关构建过程中的依赖冲突问题,官方建议可以通过云原生应用脚手架进行项目创建。

云原生应用脚手架地址:https://start.aliyun.com/

2022.x 分支

适配Spring Boot 3.0Spring Cloud 2022.x版本及以上的Spring Cloud Alibaba版本按从新到旧排列如下表(最新版本用*标记):(注意,该分支Spring Cloud Alibaba版本命名方式进行了调整,未来将对应Spring Cloud版本,前三位为Spring Cloud版本,最后一位为扩展版本,比如适配Spring Cloud 2022.0.0版本对应的Spring Cloud Alibaba第一个版本为:2022.0.0.0,第个二版本为:2022.0.0.1,依此类推)

Spring Cloud Alibaba VersionSpring Cloud VersionSpring Boot Version
2022.0.0.0-RC*Spring Cloud 2022.0.03.0.0

2021.x 分支

适配Spring Boot 2.4Spring Cloud 2021.x版本及以上的Spring Cloud Alibaba版本按从新到旧排列如下表(最新版本用*标记):

Spring Cloud Alibaba VersionSpring Cloud VersionSpring Boot Version
2021.0.4.0*Spring Cloud 2021.0.42.6.11
2021.0.1.0Spring Cloud 2021.0.12.6.3
2021.1Spring Cloud 2020.0.12.4.2

2.2.x 分支

适配Spring Boot为2.4,Spring Cloud Hoxton版本及以下的Spring Cloud Alibaba版本按从新到旧排列如下表(最新版本用*标记):

Spring Cloud Alibaba VersionSpring Cloud VersionSpring Boot Version
2.2.10-RC1*Spring Cloud Hoxton.SR122.3.12.RELEASE
2.2.9.RELEASESpring Cloud Hoxton.SR122.3.12.RELEASE
2.2.8.RELEASESpring Cloud Hoxton.SR122.3.12.RELEASE
2.2.7.RELEASESpring Cloud Hoxton.SR122.3.12.RELEASE
2.2.6.RELEASESpring Cloud Hoxton.SR92.3.2.RELEASE
2.2.1.RELEASESpring Cloud Hoxton.SR32.2.5.RELEASE
2.2.0.RELEASESpring Cloud Hoxton.RELEASE2.2.X.RELEASE
2.1.4.RELEASESpring Cloud Greenwich.SR62.1.13.RELEASE
2.1.2.RELEASESpring Cloud Greenwich2.1.X.RELEASE
2.0.4.RELEASE(停止维护,建议升级)Spring Cloud Finchley2.0.X.RELEASE
1.5.1.RELEASE(停止维护,建议升级)Spring Cloud Edgware1.5.X.RELEASE

组件版本关系

每个Spring Cloud Alibaba版本及其自身所适配的各组件对应版本如下表所示(注意,Spring Cloud Dubbo2021.0.1.0起已被移除出主干,不再随主干演进):

Spring Cloud Alibaba VersionSentinel VersionNacos VersionRocketMQ VersionDubbo VersionSeata Version
2.2.10-RC11.8.62.2.04.9.4~1.6.1
2022.0.0.0-RC11.8.62.2.1-RC4.9.4~1.6.1
2.2.9.RELEASE1.8.52.1.04.9.4~1.5.2
2021.0.4.01.8.52.0.44.9.4~1.5.2
2.2.8.RELEASE1.8.42.1.04.9.3~1.5.1
2021.0.1.01.8.31.4.24.9.2~1.4.2
2.2.7.RELEASE1.8.12.0.34.6.12.7.131.3.0
2.2.6.RELEASE1.8.11.4.24.4.02.7.81.3.0
2021.1 or 2.2.5.RELEASE or 2.1.4.RELEASE or 2.0.4.RELEASE1.8.01.4.14.4.02.7.81.3.0
2.2.3.RELEASE or 2.1.3.RELEASE or 2.0.3.RELEASE1.8.01.3.34.4.02.7.81.3.0
2.2.1.RELEASE or 2.1.2.RELEASE or 2.0.2.RELEASE1.7.11.2.14.4.02.7.61.2.0
2.2.0.RELEASE1.7.11.1.44.4.02.7.4.11.0.0
2.1.1.RELEASE or 2.0.1.RELEASE or 1.5.1.RELEASE1.7.01.1.44.4.02.7.30.9.0
2.1.0.RELEASE or 2.0.0.RELEASE or 1.5.0.RELEASE1.6.31.1.14.4.02.7.30.7.1

解决方法

修改命名方式

orderservice的服务名称修改为order-service即可,重新启动nacos集群服务,此时注册服务成功。

调整版本关系

SpringBoot版本调整为:

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.9.RELEASE</version>
    <relativePath/>
</parent>

父工程中pom文件里的spring-cloud-alibaba-dependencies版本调整为:

 <dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2.1.0.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

引用资料

  • https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明#毕业版本依赖关系推荐使用