springboot微服务连接nacos超时

问题现象

java应用启动失败,查看日志,发现是连接Nacos超时,获取不到配置,导致dubbo注册失败,错误日志如下:

java 复制代码
2025-05-01 14:50:08.973 ERROR [TW-172.29.245.61-9063-3] [com.alibaba.nacos.common.utils.LoggerUtils.printIfErrorEnabled:102] c.a.nacos.common.remote.client.grpc.GrpcClient - Server check fail, please check server 172.29.242.158 ,port 9848 is available , error ={}
java.util.concurrent.TimeoutException: Waited 3000 milliseconds (plus 147164 nanoseconds delay) for com.alibaba.nacos.shaded.io.grpc.stub.ClientCalls$GrpcFuture@5fcf7541[status=PENDING, info=[GrpcFuture{clientCall=PendingCall{realCall=ClientCallImpl{method=MethodDescriptor{fullMethodName=Request/request, type=UNARY, idempotent=false, safe=false, sampledToLocalTracing=true, requestMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller@720ff3a9, responseMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller@7f335908, schemaDescriptor=com.alibaba.nacos.api.grpc.auto.RequestGrpc$RequestMethodDescriptorSupplier@1b679ea8}}}}]]
        at com.alibaba.nacos.shaded.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:508)
        at com.alibaba.nacos.common.remote.client.grpc.GrpcClient.serverCheck(GrpcClient.java:218)
        at com.alibaba.nacos.common.remote.client.grpc.GrpcClient.connectToServer(GrpcClient.java:329)
        at com.alibaba.nacos.common.remote.client.RpcClient.start(RpcClient.java:363)
        at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.ensureRpcClient(ClientWorker.java:891)
        at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.getOneRunningClient(ClientWorker.java:1038)
        at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.queryConfig(ClientWorker.java:946)
        at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:403)
        at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:184)
--
        at com.tongweb.web.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1642)
        at com.tongweb.web.util.net.SocketProcessorBase.run(SocketProcessorBase.java:33)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at com.tongweb.web.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:47)
        at java.lang.Thread.run(Thread.java:748)

排查思路

1.网络问题

因为连接超时,第一反应就是网络或者端口不通,通过telnet命令排查,发现正常

bash 复制代码
telnet 172.29.242.145 8848   # 测试Http端口
telnet 172.29.242.145 9848   # 测试gRPC端口

2.域名解析

已排除网络和端口,那么可能是连接真的超时了,超时时间是3s。

(1)解析本机ip

(2)发请求到nacos服务端

(3)服务端返回数据

通过hostname -i命令本机ip,发现大概4~5秒才返回,明显有问题,使用hostname查看主机名称,然后通过cat /etc/hosts命令查看host,发现主机名称没有配置host;加上host,重启服务,能正常注册,问题解决。

bash 复制代码
hostname -i     # 查看主机ip
hostname        # 查看主机名称
cat /etc/hosts  # 查看host文件
相关推荐
东阳马生架构2 小时前
Nacos源码—6.Nacos升级gRPC分析一
nacos
帅得不敢出门2 小时前
Ubuntu打开中文文本乱码
linux·运维·ubuntu·vim
源码云商2 小时前
基于 SpringBoot + Vue 的校园管理系统设计与实现
vue.js·spring boot·后端
pp-周子晗(努力赶上课程进度版)3 小时前
【计算机网络-传输层】传输层协议-UDP
linux·计算机网络·udp
only火车头3 小时前
mdadm 报错: buffer overflow detected
linux·mdadm·blktest
Flaming_1233 小时前
将develop分支的修改同步到main分支
linux·git·merge
奔驰的小野码3 小时前
SpringAI实现AI应用-内置顾问
java·人工智能·后端·spring
普通人zzz~3 小时前
SpringBoot记录用户操作日志
java·spring boot·后端
大三开学菜鸟3 小时前
记录一下spring-cloud-starter-alibaba-nacos-config 2023.0.3.2与springboot版本及配置问题
java·spring boot·后端·spring·intellij-idea
weixin_428498494 小时前
使用 pgrep 杀掉所有指定进程
linux