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文件
相关推荐
嵩山小老虎8 小时前
Windows 10/11 安装 WSL2 并配置 VSCode 开发环境(C 语言 / Linux API 适用)
linux·windows·vscode
Fleshy数模9 小时前
CentOS7 安装配置 MySQL5.7 完整教程(本地虚拟机学习版)
linux·mysql·centos
a41324479 小时前
ubuntu 25 安装vllm
linux·服务器·ubuntu·vllm
一点程序10 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
一只自律的鸡10 小时前
【Linux驱动】bug处理 ens33找不到IP
linux·运维·bug
17(无规则自律)11 小时前
【CSAPP 读书笔记】第二章:信息的表示和处理
linux·嵌入式硬件·考研·高考
!chen11 小时前
linux服务器静默安装Oracle26ai
linux·运维·服务器
REDcker11 小时前
Linux 文件描述符与 Socket 选项操作详解
linux·运维·网络
蒹葭玉树11 小时前
【C++上岸】C++常见面试题目--操作系统篇(第二十八期)
linux·c++·面试
2501_9277730711 小时前
imx6驱动
linux·运维·服务器