2022-11-21 16:16:37.836 |-ERROR [main] com.alibaba.nacos.client.naming [552] -| request: /nacos/v1/ns/instance failed, servers: [localhost:8848], code: 500, msg: Connection refused (Connection refused)
2022-11-21 16:16:37.837 |-ERROR [main] com.alibaba.cloud.nacos.registry.NacosServiceRegistry [80] -| nacos registry, quick-user-service register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='localhost:8848', endpoint='', namespace='aef02670-f003-419a-b20b-496f2536dd1d', watchDelay=30000, logName='', service='quick-user-service', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='61.52.197.170', networkInterface='', port=5720, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, failFast=true}},
com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance after all servers([localhost:8848]) tried: java.net.ConnectException: Connection refused (Connection refused)
2022-11-21 16:16:37.815 |-ERROR [main] com.alibaba.nacos.client.naming [617] -| [NA] failed to request
java.net.ConnectException: Connection refused (Connection refused)
微服务项目部署
有gateway项目、user-service项目和公共common项目
通过打包jar文件,在build成镜像,最后通过rancher启动服务
排查了服务器的端口8848启动着。
又有说Docker 部署的nacos没有使用宿主机网段。
我使用的以下命令部署的
docker run --env MODE=standalone --name
docker-nacos -d -p 8848:8848 nacos/nacos-
server
并且nacos使用外网(公网网段)能够访问到nacos服务,并且能够正常操作。因此排除此问题。问应该出现在微服务上面。
【参考】(因为我的spring nacos引包在common中)。所以一路开始找“Maven父子模块相互引用问题”上面。
参考1
参考2
参考3
最后发现并不是这样的。所以我怀疑是不是我的boostrap.yml出问题了
初始版本的
spring:
application:
name: quick-user-service
main:
allow-bean-definition-overriding: true
cloud:
nacos:
config:
server-addr: 120.212.92.71:8848 #Nacos配置中心地址
file-extension: yaml #文件拓展格式
password: 123456
username: nacos
group: DEFAULT_GROUP
extension-configs: ${spring.application.name}.yaml
namespace: aef02670-f003-419a-b20b-496f2536dd1d
shared-configs: application.yaml
# 因为是Docker容器化部署的,所以改成本机对外ip(百度搜索”ip查询“复制查询到的ip地址)
discovery:
ip: 61.52.197.170
namespace: aef02670-f003-419a-b20b-496f2536dd1d
profiles:
active: prod
server:
port: 5720
然后还是会报nacos拒绝链接的问题
2022-11-21 16:16:37.815 |-ERROR [main] com.alibaba.nacos.client.naming [617] -| [NA] failed to request
java.net.ConnectException: Connection refused (Connection refused)
2022-11-21 16:16:40.788 |-ERROR [com.alibaba.nacos.client.naming.updater] com.alibaba.nacos.client.naming [552] -| request: /nacos/v1/ns/instance/list failed, servers: [localhost:8848], code: 500, msg: Connection refused (Connection refused)
2022-11-21 16:16:40.788 |-WARN [com.alibaba.nacos.client.naming.updater] com.alibaba.nacos.client.naming [488] -| [NA] failed to update serviceName: DEFAULT_GROUP@@quick-user-service
com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance/list after all servers([localhost:8848]) tried: java.net.ConnectException: Connection refused (Connection refused)
正确版本:
spring:
application:
name: quick-user-service
main:
allow-bean-definition-overriding: true
cloud:
nacos:
server-addr: 120.212.92.71:8848 #Nacos配置中心地址
password: 123456
username: nacos
config:
file-extension: yaml #文件拓展格式
group: DEFAULT_GROUP
extension-configs: ${spring.application.name}.yaml
namespace: aef02670-f003-419a-b20b-496f2536dd1d
shared-configs: application.yaml
# 因为是Docker容器化部署的,所以改成本机对外ip(百度搜索”ip查询“复制查询到的ip地址)
discovery:
ip: 61.52.197.170
namespace: aef02670-f003-419a-b20b-496f2536dd1d
profiles:
active: prod
server:
port: 5720
放到nacos下层和config上层的位置。
具体的我也不清楚。。。。
初始版本的情况下,使用本地的nacos链接没啥问题的。