SpringCloudAlibaba 网关gateway整合sentinel日志默认路径修改

SpringCloudAlibaba 网关gateway整合sentinel 实现网关限流熔断

问题提出

今天运维突然告诉我 在服务器上内存满了 原因是nacos日志高达3G,然后将日志文件发给我看了一下之后才发现是gateway整合sentinel使用了默认日志地址导致日志生成地址直接存在与根路径下而且一下存在多个日志。提出问题当然要解决问题,当然以下就是我解决问题的方法

原有文件以及引入jar

引入jar包

复制代码
		<!-- sentinel 网关限流 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
        </dependency>
        <!-- 熔断限流组件 -->
        <dependency>
            <groupId>com.yjwl.utils.sentinel</groupId>
            <artifactId>sentinel-spring-boot-starter</artifactId>
        </dependency>

yml中配置

复制代码
spring:
  cloud:
    sentinel:
      filter:
        enabled: false
      datasource:
        # 名称随意
        flow:
          nacos:
            server-addr: 172.16.22.21:18848
            dataId: ${spring.application.name}-sentinel-gw-flow
            groupId: SENTINEL
            # 规则类型,取值见:
            # com.alibaba.cloud.sentinel.datasource.RuleType
            rule-type: gw-flow

存在问题

所有的资源访问都会产生秒级监控日志,日志文件默认为

复制代码
${user_home}/logs/csp/${app_name}-${pid}-metrics.log

(会随时间滚动) 从而会导致在项目地址的跟目录下会产生很多关于sentinel的日志文件,所以在初始配置时需要添加yml日志指定输出路径

问题解决

修改yml配置

复制代码
spring:
  cloud:
    sentinel:
      filter:
        enabled: false
      log:
        dir: \opt\csp\
      datasource:
        # 名称随意
        flow:
          nacos:
            server-addr: 172.16.22.21:18848
            dataId: ${spring.application.name}-sentinel-gw-flow
            groupId: SENTINEL
            # 规则类型,取值见:
            # com.alibaba.cloud.sentinel.datasource.RuleType
            rule-type: gw-flow

控制台输出日志为:

然后在对应的linux文件地址下也可以看到对应的日志文件

官方文档接口:https://sentinelguard.io/zh-cn/docs/logs.html 有感兴趣的小伙伴可以直接查看官方文档。

github源码地址日志配置json文件地址:https://github.com/alibaba/spring-cloud-alibaba/blob/2.2.x/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/resources/META-INF/additional-spring-configuration-metadata.json

相关推荐
研究司马懿4 小时前
【云原生】Gateway API介绍
云原生·gateway
研究司马懿4 小时前
【云原生】Gateway API路由、重定向、修饰符等关键操作
云原生·gateway
研究司马懿5 小时前
【云原生】初识Gateway API
云原生·gateway
小马爱打代码1 天前
Spring Boot:Sentinel 企业级熔断、降级与限流实战
spring boot·后端·sentinel
没有bug.的程序员1 天前
Spring Cloud Sentinel:熔断降级规则配置与分布式流量防线实战终极指南
java·分布式·后端·spring cloud·sentinel·熔断规则·分布式流量防线
七夜zippoe1 天前
API网关设计模式实战 Spring Cloud Gateway路由过滤限流深度解析
java·设计模式·gateway·路由·api网关
汪碧康1 天前
一文讲解kubernetes的gateway Api的功能、架构、部署、管理及使用
云原生·容器·架构·kubernetes·gateway·kubelet·xkube
大佐不会说日语~1 天前
Docker Compose 部署 Spring Boot 应用 502 Bad Gateway 问题排查与解决
spring boot·docker·gateway·maven·故障排查
Dontla3 天前
Kubernetes流量管理双雄:Ingress与Gateway API解析(Nginx与Ingress与Gateway API的关系)
nginx·kubernetes·gateway
JavaLearnerZGQ3 天前
Gateway网关将登录用户信息传递给下游微服务(完整实现方案)
微服务·架构·gateway