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文件
相关推荐
程序无bug3 分钟前
Java中的8中基本数据类型转换
java·后端
雨落倾城夏未凉7 分钟前
8.Qt文件操作
c++·后端·qt
51710 分钟前
Django中序列化与反序列化
后端·python·django
也许明天y11 分钟前
Spring Cloud Gateway 自定义分布式限流
redis·后端·spring cloud
CodeWithMe17 分钟前
【Note】Linux Kernel 之 内核架构、源码文件、API/ABI 、FHS
linux·运维·架构
Shan120539 分钟前
编辑器Vim的快速入门
linux·编辑器·vim
一块plus1 小时前
深度详解 Revive 和 Precompile 技术路径
后端·设计模式·架构
HONG_YANG1 小时前
2025 ERPNext 一键部署方案
linux
iOS开发上架哦1 小时前
没有Mac如何完成iOS 上架:iOS App 上架App Store流程
后端
晴空月明1 小时前
分布式系统高可用性设计-负载均衡与容错机制深度解析
后端