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文件
相关推荐
oMcLin6 小时前
在RHEL 8系统上如何实现基于Docker的微服务架构,并进行自动化部署?
docker·微服务·架构
Xの哲學6 小时前
Linux SLUB 内存分配器深度剖析: 从设计哲学到实战调试
linux·服务器·网络·算法·边缘计算
橘色的喵6 小时前
嵌入式 ARM Linux 平台高性能无锁异步日志系统设计与实现
linux·arm开发·cache line·ring buffer
IT_陈寒6 小时前
Redis性能翻倍的5个冷门技巧:从每秒10万到20万的实战优化之路
前端·人工智能·后端
何中应6 小时前
linux使用root账户操作提示没有权限
linux·运维·服务器
天上飞的粉红小猪6 小时前
网络基础概念
linux·服务器·网络·c++
qq_5470261797 小时前
Shell 高级用法
linux
Hello_wshuo7 小时前
记RP2040使用Arduino+platformio开发配置
linux·嵌入式硬件·arduino
KingRumn7 小时前
DBUS源码剖析之DBusMessage消息头
linux·服务器·算法
没有bug.的程序员7 小时前
技术中台的职责边界:基础能力抽象、统一组件平台与过度封装风险深度解析
微服务·云原生·研发效能·架构设计·中台架构·技术中台·sdk设计