微服务无法获取nacos配置问题排查

微服务无法获取nacos配置问题排查

老东家给客户私有化部署中数安后子系统微服务及网关都无法启动日志显示从nacos获取到的配置文件为空

错误日志

```bash
12:45:50.148 [main] INFO  main c.a.n.c.c.i.LocalConfigInfoProcessor - [<clinit>,195] - LOCAL_SNAPSHOT_PATH:/root/nacos/config
12:45:50.252 [main] INFO  main c.a.n.c.c.i.Limiter - [<clinit>,53] - limitTime:5.0
12:45:50.384 [main] WARN  main c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[Application.yaml] & group[prod-plus]
12:45:50.413 [main] WARN  main c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[ServiceSystem] & group[prod-plus]
12:45:50.440 [main] WARN  main c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[ServiceSystem.yaml] & group[prod-plus]
12:45:50.469 [main] WARN  main c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[ServiceSystem-prod-plus.yaml] & group[prod-plus]
12:45:50.506 [main] INFO  main c.aiot5.Application - [logStartupProfileInfo,655] - The following profiles are active: prod-plus

主要可能原因分析

spring boot 配置错误

  • nacos 配置地址配置错误
  • nacos 命名空间配置错误、配置文件名或类型错误
  • nacos 中不存在配置文件

但是通过日志发现是nacos获取到的配置文件为空

登录Naocs查看是否存在配置文件

4

看到nacos中配置文件都是存在的并且配置文件名也没有错

tcpdump抓包nacos域名

真实域名、IP已替换

root@k8s-master:~/project/zsa/repository/backend# tcpdump -i eth0 host abc.abc.com -nn
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
13:31:56.174798 IP 172.18.28.207.43893 > xxx.xxx.xxx.xxx.80: Flags [S], seq 678554203, win 64800, options [mss 1440,sackOK,TS val 4116337012 ecr 0,nop,wscale 7], length 0
13:31:56.200829 IP xxx.xxx.xxx.xxx.80 > 172.18.28.207.43893: Flags [S.], seq 3589867409, ack 678554204, win 28960, options [mss 1460,sackOK,TS val 3509487916 ecr 4116337012,nop,wscale 7], length 0
13:31:56.201047 IP 172.18.28.207.43893 > xxx.xxx.xxx.xxx.80: Flags [.], ack 1, win 507, options [nop,nop,TS val 4116337038 ecr 3509487916], length 0
13:31:56.206923 IP 172.18.28.207.43893 > xxx.xxx.xxx.xxx.80: Flags [P.], seq 1:501, ack 1, win 507, options [nop,nop,TS val 4116337044 ecr 3509487916], length 500: HTTP: GET /abc/v1/cs/configs?dataId=Application.yaml&group=prod-plus&tenant=zsa-xma HTTP/1.1
13:31:56.233372 IP xxx.xxx.xxx.xxx.80 > 172.18.28.207.43893: Flags [.], ack 501, win 235, options [nop,nop,TS val 3509487948 ecr 4116337044], length 0
13:31:56.235330 IP xxx.xxx.xxx.xxx.80 > 172.18.28.207.43893: Flags [P.], seq 1:315, ack 501, win 235, options [nop,nop,TS val 3509487950 ecr 4116337044], length 314: HTTP: HTTP/1.1 404 
13:31:56.235420 IP 172.18.28.207.43893 > xxx.xxx.xxx.xxx.80: Flags [.], ack 315, win 505, options [nop,nop,TS val 4116337073 ecr 3509487950], length 0
13:31:56.267437 IP 172.18.28.207.43893 > xxx.xxx.xxx.xxx.80: Flags [P.], seq 501:1009, ack 315, win 505, options [nop,nop,TS val 4116337105 ecr 3509487950], length 508: HTTP: GET /abc/v1/cs/configs?dataId=BizFireControlRoomSystem&group=prod-plus&tenant=zsa-xma HTTP/1.1
13:31:56.295859 IP xxx.xxx.xxx.xxx.80 > 172.18.28.207.43893: Flags [P.], seq 315:629, ack 1009, win 243, options [nop,nop,TS val 3509488011 ecr 4116337105], length 314: HTTP: HTTP/1.1 404

从抓包信息看获取配置文件的接口返回404,也就是说请求配置文件的路径是不存在的

尝试手动CURL配置文件路径

root@k8s-master:~/project/zsa/repository/backend# curl "http://abc.abc.com:80/abc/v1/cs/configs?dataId=ServiceSystem.yaml&group=prod-plus&tenant=zsa-xma"
config data not exist
root@k8s-master:~/project/zsa/repository/backend#
发现获取不到配置,但是请求url的每个参数都没有问题,我尝试将命名空间也就是tenant参数的值更改为对应名称空间的id再次尝试
root@k8s-master:~/project/zsa/repository/backend# curl "http://abc.abc.com:80/abc/v1/cs/configs?dataId=ServiceSystem.yaml&group=prod-plus&tenant=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# 所有预先配置,放在这里
server:
  #文件上传的总吞吐量
  tomcat:
    max-swallow-size: 100MB #重要的一行,修改tomcat的吞吐量
........
更换为id后在此请求发现可以正常获取配置

更改微服务配置

spring:
  profiles:
    active: ${SPRING_PROFILES_ACTIVE:dev}
  cloud:
    config:
      enabled: false
    nacos:
      discovery:
        server-addr: "abc.abc.com:80"
        # 使用namespace ID,不要使用 zsa-xma
        namespace: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        group: "${spring.profiles.active}"
      config:
        server-addr: "abc.abc.com:80"
        namespace: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        prefix: "SpringGateway"
        file-extension: "yaml"
        group: "${spring.profiles.active}"
        shared-configs:
          - data-id: "Application.yaml"
            refresh: true
            group: "${spring.profiles.active}"

更改微服务配置后删除pod重启发现日志正常已可以获取到nacos中的配置

root@k8s-master:~# kubectl logs zsa-service-cfd8595dc-hz8v9 
18:37:01.461 [background-preinit] INFO  background-preinit o.h.v.i.util.Version - [<clinit>,21] - HV000001: Hibernate Validator 6.1.5.Final
 ________ _________  ___       __   ___       ________
|\   ____\\___   ___\\  \     |\  \|\  \     |\   ____\
\ \  \___\|___ \  \_\ \  \    \ \  \ \  \    \ \  \___|_
 \ \  \       \ \  \ \ \  \  __\ \  \ \  \    \ \_____  \
  \ \  \____   \ \  \ \ \  \|\__\_\  \ \  \____\|____|\  \
   \ \_______\  \ \__\ \ \____________\ \_______\____\_\  \
    \|_______|   \|__|  \|____________|\|_______|\_________\
                                                \|_________|

18:37:05.117 [main] INFO  main c.a.n.c.c.i.LocalConfigInfoProcessor - [<clinit>,195] - LOCAL_SNAPSHOT_PATH:/root/nacos/config
18:37:05.240 [main] INFO  main c.a.n.c.c.i.Limiter - [<clinit>,53] - limitTime:5.0
18:37:06.407 [main] INFO  main c.a.n.c.c.u.JVMUtil - [<clinit>,47] - isMultiInstance:false
18:37:06.469 [main] WARN  main c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[ServiceSystem] & group[prod-plus]
18:37:06.831 [main] WARN  main c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[ServiceSystem-prod-plus.yaml] & group[prod-plus]
18:37:07,231 |-WARN in net.logstash.logback.appender.LogstashTcpSocketAppender[logstash] - Log destination 172.18.28.207:4560: Waiting 29995ms before attempting reconnection.
18:37:07.245 [main] INFO  main c.aiot5.Application - [logStartupProfileInfo,655] - The following profiles are active: prod-plus
18:37:13.416 [main] WARN  main o.s.b.a.e.EndpointId - [logWarning,155] - Endpoint ID 'bus-env' contains invalid characters, please migrate to a valid format.
18:37:14.369 [main] WARN  main o.s.b.a.e.EndpointId - [logWarning,155] - Endpoint ID 'bus-refresh' contains invalid characters, please migrate to a valid format.
18:37:14.483 [main] WARN  main o.s.b.a.e.EndpointId - [logWarning,155] - Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
18:37:14.835 [main] WARN  main t.m.s.m.ClassPathMapperScanner - [doScan,146] - No MyBatis mapper was found in '[com.aiot5.equipmanagementsystem.mapper.dao_taosdb]' package. Please check your configuration.
18:37:14.883 [main] WARN  main o.m.s.m.ClassPathMapperScanner - [warn,44] - No MyBatis mapper was found in '[com.aiot5.tool.core.Mapper]' package. Please check your configuration.
18:37:18.755 [main] INFO  main o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-8080"]
18:37:18.756 [main] INFO  main o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
18:37:18.757 [main] INFO  main o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.37]
18:37:18.889 [main] INFO  main o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext

 

© 版权声明
THE END
喜欢就支持一下吧
点赞9赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容