• Sentinel 微服务保护


    目录

    1 雪崩问题

    2 认识Sentinel 

    3 安装Sentinel控制台 

    4 引入cloud-demo 

    5 簇点链路

     6 快速入门

    7 流控模式 

     7.1 流控模式-关联

    7.2 流控模式-链路

     8 流控效果

    8.1 流控效果-warm up 

    8.2 流控效果-排队等待 


    1 雪崩问题

    微服务调用链路中的某个服务故障,引起整个链路中的所有微服务都不可用,这就是雪崩。

    解决雪崩问题的常见方式有四种:

    超时处理:设定超时时间,请求超过一定时间没有响应就返回错误信息,不会无休止等待。

    舱壁模式:限定每个业务能使用的线程数,避免耗尽整个tomcat的资源,因此也叫线程隔离。

     

     熔断降级:由断路器统计业务执行的异常比例,如果超出阈值则会熔断该业务,拦截访问该业务的一切请求。

    流量控制:限制业务访问的QPS,避免服务因流量的突增而故障。 

    什么是雪崩问题?

    微服务之间相互调用,因为调用链中的一个服务故障,引起整个链路都无法访问的情况。

    如何避免因瞬间高并发流量而导致服务故障?

    流量控制

    如何避免因服务故障引起的雪崩问题?

    超时处理
    线程隔离
    降级熔断

    服务保护技术对比

    2 认识Sentinel 

    Sentinel是阿里巴巴开源的一款微服务流量控制组件。官网地址:home

    Sentinel 具有以下特征:

    丰富的应用场景 Sentinel 承接了阿里巴巴近 10 年的双十一大促流量的核心场景,例如秒杀(即突发流量控制在系统容量可以承受的范围)、消息削峰填谷、集群流量控制、实时熔断下游不可用应用等。
    完备的实时监控 Sentinel 同时提供实时的监控功能。您可以在控制台中看到接入应用的单台机器秒级数据,甚至 500 台以下规模的集群的汇总运行情况。
    广泛的开源生态 Sentinel 提供开箱即用的与其它开源框架 / 库的整合模块,例如与 Spring Cloud Dubbo gRPC 的整合。您只需要引入相应的依赖并进行简单的配置即可快速地接入 Sentinel
    完善的 SPI 扩展点 Sentinel 提供简单易用、完善的 SPI 扩展接口。您可以通过实现扩展接口来快速地定制逻辑。例如定制规则管理、适配动态数据源等。

    3 安装Sentinel控制台 

    sentinel官方提供了UI控制台,方便我们对系统做限流设置。大家可以在GitHub下载。课前资料提供了下载好的jar包:

    1. 将其拷贝到一个你能记住的非中文目录,然后运行命令:
    2. 然后访问: localhost:8080 即可看到控制台页面,默认的账户和密码都是 sentinel

     如果要修改Sentinel的默认端口、账户、密码,可以通过下列配置:

    4 引入cloud-demo 

    要使用Sentinel肯定要结合微服务,这里我们使用SpringCloud实用篇中的cloud-demo工程。没有的小伙伴可以在课前资料中找到:

    项目结构如下:

    我们在order-service中整合Sentinel,并且连接Sentinel的控制台,步骤如下:

    1.引入sentinel依赖:

    
        com.alibaba.cloud
        spring-cloud-starter-alibaba-sentinel
    

     2.配置控制台地址:

    spring.cloud.sentinel.transport.dashboard=localhost:8080

    3.访问微服务的任意端点,触发sentinel监控 

    5 簇点链路

    簇点链路:就是项目内的调用链路,链路中被监控的每个接口就是一个资源。默认情况下sentinel会监控SpringMVC的每一个端点(Endpoint),因此SpringMVC的每一个端点(Endpoint)就是调用链路中的一个资源。

    流控、熔断等都是针对簇点链路中的资源来设置的,因此我们可以点击对应资源后面的按钮来设置规则:

     6 快速入门

    点击资源/order/{orderId}后面的流控按钮,就可以弹出表单。表单中可以添加流控规则,如下图所示:

     其含义是限制 /order/{orderId}这个资源的单机QPS1,即每秒只允许1次请求,超出的请求会被拦截并报错。

    需求:给 /order/{orderId}这个资源设置流控规则,QPS不能超过 5。然后利用jemeter测试。

    1. 设置流控规则:

    2. jemeter 测试:

    7 流控模式 

    在添加限流规则时,点击高级选项,可以选择三种流控模式:

    直接:统计当前资源的请求,触发阈值时对当前资源直接限流,也是默认的模式
    关联:统计与当前资源相关的另一个资源,触发阈值时,对当前资源限流
    链路:统计从指定链路访问到本资源的请求,触发阈值时,对指定链路限流

     7.1 流控模式-关联

    关联模式:统计与当前资源相关的另一个资源,触发阈值时,对当前资源限流

    使用场景:比如用户支付时需要修改订单状态,同时用户要查询订单。查询和修改操作会争抢数据库锁,产生竞争。

    业务需求是有限支付和更新订单的业务,因此当修改订单业务触发阈值时,需要对查询订单业务限流。

    /write资源访问量触发阈值时,就会对/read资源限流,避免影响/write资源。 

    需求:

    OrderController 新建两个端点: /order/query /order/update ,无需实现业务
    配置流控规则,当 /order/ update 资源被访问的 QPS 超过 5 时,对 /order/query 请求限流

    7.2 流控模式-链路

    需求:有查询订单和创建订单业务,两者都需要查询商品。针对从查询订单进入到查询商品的请求统计,并设置限流。

    步骤:

    1. OrderService 中添加一个 queryGoods 方法,不用实现业务
    2. OrderController 中,改造 /order/query 端点,调用 OrderService 中的 queryGoods 方法
    3. OrderController 中添加一个 /order/save 的端点,调用 OrderService queryGoods 方法
    4. queryGoods 设置限流规则,从 /order/query 进入 queryGoods 的方法限制 QPS 必须小于 2

     Sentinel默认只标记Controller中的方法为资源,如果要标记其它方法,需要利用@SentinelResource注解,示例:

     Sentinel默认会将Controller方法做context整合,导致链路模式的流控失效,需要修改application.yml,添加配置:

    #关闭context整合
    spring.cloud.sentinel.web-context-unify=false

     8 流控效果

    流控效果是指请求达到流控阈值时应该采取的措施,包括三种:

    快速失败:达到阈值后,新的请求会被立即拒绝并抛出 FlowException 异常。是默认的处理方式。
    warm up :预热模式,对超出阈值的请求同样是拒绝并抛出异常。但这种模式阈值会动态变化,从一个较小值逐渐增加到最大阈值。
    排队等待:让所有的请求按照先后次序排队执行,两个请求的间隔不能小于指定时长

    8.1 流控效果-warm up 

    warm up也叫预热模式,是应对服务冷启动的一种方案。请求阈值初始值是 threshold / coldFactor,持续指定时长后,逐渐提高到threshold值。而coldFactor的默认值是3.

    例如,我设置QPSthreshold10,预热时间为5秒,那么初始阈值就是 10 / 3 ,也就是3,然后在5秒后逐渐增长到10.

    8.2 流控效果-排队等待 

    当请求超过QPS阈值时,快速失败和warm up 会拒绝新的请求并抛出异常。而排队等待则是让所有请求进入一个队列中,然后按照阈值允许的时间间隔依次执行。后来的请求必须等待前面执行完成,如果请求预期的等待时间超出最大时长,则会被拒绝。

    例如:QPS = 5,意味着每200ms处理一个队列中的请求;timeout = 2000,意味着预期等待超过2000ms的请求会被拒绝并抛出异常

    9 热点参数限流

    之前的限流是统计访问某个资源的所有请求,判断是否超过QPS阈值。而热点参数限流是分别统计参数值相同的请求,判断是否超过QPS阈值。

     配置示例:

    代表的含义是:对hot这个资源的0号参数(第一个参数)做统计,每1相同参数值的请求数不能超过5

    在热点参数限流的高级选项中,可以对部分参数设置例外配置:

     

     结合上一个配置,这里的含义是对0号的long类型参数限流,每1秒相同参数的QPS不能超过5,有两个例外:

    如果参数值是 100 ,则每 1 秒允许的 QPS 10
    如果参数值是 101 ,则每 1 秒允许的 QPS 15

    /order/{orderId}这个资源添加热点参数限流,规则如下:

    默认的热点参数规则是每 1 秒请求量不超过 2
    102 这个参数设置例外:每 1 秒请求量不超过 4
    103 这个参数设置例外:每 1 秒请求量不超过 10

    10 隔离和降级 

    虽然限流可以尽量避免因高并发而引起的服务故障,但服务还会因为其它原因而故障。而要将这些故障控制在一定范围,避免雪崩,就要靠线程隔离(舱壁模式)和熔断降级手段了。

    不管是线程隔离还是熔断降级,都是对客户端(调用方)的保护。

    11 Feign整合Sentinel

    SpringCloud中,微服务调用都是通过Feign来实现的,因此做客户端保护必须整合FeignSentinel

    1.修改OrderServiceapplication.yml文件,开启FeignSentinel功能

    feign.sentinel.enabled=true

    2.FeignClient编写失败后的降级逻辑 

    方式一: FallbackClass ,无法对远程调用的异常做处理
    方式二: FallbackFactory ,可以对远程调用的异常做处理,我们选择这种

    步骤一:order项目中定义类,实现FallbackFactory 

    步骤二:feing-api项目中的DefaultFeignConfiguration类中将UserClientFallbackFactory注册为一个Bean

    1. package com.xzj.order.feigin;
    2. import com.xzj.entity.Product;
    3. import feign.hystrix.FallbackFactory;
    4. import lombok.extern.slf4j.Slf4j;
    5. import org.springframework.stereotype.Component;
    6. /**
    7. * @author xuan
    8. */
    9. @Slf4j
    10. @Component
    11. public class ProductFeiginFactory implements FallbackFactory {
    12. @Override
    13. public ProductFeigin create(Throwable throwable) {
    14. // 创建UserClient接口实现类,实现其中的方法,编写失败降级的处理逻辑
    15. ProductFeigin productFeigin = new ProductFeigin() {
    16. @Override
    17. public Product getById(Integer pid) {
    18. Product product = new Product();
    19. product.setPname("服务器正忙");
    20. return product;
    21. }
    22. };
    23. return productFeigin;
    24. }
    25. }

    步骤三:feing-api项目中的UserClient接口中使用UserClientFallbackFactory

    1. package com.xzj.order.feigin;
    2. import com.xzj.entity.Product;
    3. import org.springframework.cloud.openfeign.FeignClient;
    4. import org.springframework.web.bind.annotation.GetMapping;
    5. import org.springframework.web.bind.annotation.PathVariable;
    6. @FeignClient(value = "nacos-product",fallbackFactory =ProductFeiginFactory.class)
    7. public interface ProductFeigin {
    8. @GetMapping("product/getById/{pid}")
    9. public Product getById (@PathVariable Integer pid);
    10. }

    12 线程隔离

    线程隔离有两种方式实现:

    线程池隔离
    信号量隔离( Sentinel 默认采用)

    优缺点

    在添加限流规则时,可以选择两种阈值类型:

    QPS :就是每秒的请求数,在快速入门中已经演示过
    线程数:是该资源能使用用的 tomcat 线程数的最大值。也就是通过限制线程数量,实现 舱壁模式

    13 熔断降级

    熔断降级是解决雪崩问题的重要手段。其思路是由断路器统计服务调用的异常比例、慢请求比例,如果超出阈值则会熔断该服务。即拦截访问该服务的一切请求;而当服务恢复时,断路器会放行访问该服务的请求。

    13.1 熔断策略-慢调用

    断路器熔断策略有三种:慢调用、异常比例、异常数

    慢调用:业务的响应时长(RT)大于指定时长的请求认定为慢调用请求。在指定时间内,如果请求数量超过设定的

    最小数量,慢调用比例大于设定的阈值,则触发熔断。例如:

     解读:RT超过500ms的调用是慢调用,统计最近10000ms内的请求,如果请求量超过10次,并且慢调用比例不低于0.5,则触发熔断,熔断时长为5秒。然后进入half-open状态,放行一次请求做测试。

    需求:给 UserClient的查询用户接口设置降级规则,慢调用的RT阈值为50ms,统计时间为1秒,最小请求数量为5,失败阈值比例为0.4,熔断时长为5

    提示:为了触发慢调用规则,我们需要修改UserService中的业务,增加业务耗时:

     13.2 熔断策略-异常比例、异常数

    断路器熔断策略有三种:慢调用、异常比例或异常数

    异常比例或异常数:统计指定时间内的调用,如果调用次数超过指定请求数,并且出现异常的比例达到设定的比例阈值(或超过指定异常数),则触发熔断。例如:

    解读:统计最近1000ms内的请求,如果请求量超过10次,并且异常比例不低于0.5,则触发熔断,熔断时长为5秒。然后进入half-open状态,放行一次请求做测试。

    13.3 熔断策略-异常比例

    需求:给 UserClient的查询用户接口设置降级规则,统计时间为1秒,最小请求数量为5,失败阈值比例为0.4,熔断时长为5s

    提示:为了触发异常统计,我们需要修改UserService中的业务,抛出异常:

     14 授权规则

    授权规则可以对调用方的来源做控制,有白名单和黑名单两种方式。

    白名单:来源( origin )在白名单内的调用者允许访问
    黑名单:来源( origin )在黑名单内的调用者不允许访问

    例如,我们限定只允许从网关来的请求访问order-service,那么流控应用中就填写网关的名称

    Sentinel是通过RequestOriginParser这个接口的parseOrigin来获取请求的来源的。

    例如,我们尝试从request中获取一个名为origin的请求头,作为origin的值:

    @Component
    public class HeaderOriginParser implements RequestOriginParser {
       
    @Override
       
    public String parseOrigin(HttpServletRequest request) {
            String origin = request.getHeader(
    "origin");
           
    if(StringUtils.isEmpty(origin)){
               
    return "blank";
            }
           
    return origin;
        }
    }

     

    我们还需要在gateway服务中,利用网关的过滤器添加名为gatewayorigin头:

    spring:
     
    cloud:
        gateway:
         
    default-filters:
            - AddRequestHeader=origin,gateway
    # 添加名为origin的请求头,值为gateway

    /order/{orderId} 配置授权规则

     15 自定义异常结果

    默认情况下,发生限流、降级、授权拦截时,都会抛出异常到调用方。如果要自定义异常时的返回结果,需要实现BlockExceptionHandler接口:

    BlockException包含很多个子类,分别对应不同的场景:

     我们在order-service中定义类,实现BlockExceptionHandler接口:

    package com.xzj.order.hander;
    
    import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
    import com.alibaba.csp.sentinel.slots.block.BlockException;
    import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
    import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
    import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
    import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
    import org.springframework.stereotype.Component;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    @Component
    public class SentinelBlockHandler implements BlockExceptionHandler {
        @Override
        public void handle(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse, BlockException e) throws Exception {
          String msg = "未知异常";
          int status = 429;
          if (e instanceof FlowException) {
              msg = "请求被限流了!";
          } else if (e instanceof DegradeException) {
              msg = "请求被降级了!";
          } else if (e instanceof ParamFlowException) {
              msg = "热点参数限流!";
          } else if (e instanceof AuthorityException) {
              msg = "请求没有权限!";status = 401;
          }   httpServletResponse.setContentType("application/json;charset=utf-8");
         httpServletResponse.setStatus(status);
            httpServletResponse.getWriter().println("{\"message\": \"" + msg + "\", \"status\": " + status + "}");
        }
    }
    

    16 规则持久化 

    规则管理模式

    Sentinel的控制台规则管理有三种模式:

     16.1 规则管理模式-原始模式

    原始模式:控制台配置的规则直接推送到Sentinel客户端,也就是我们的应用。然后保存在内存中,服务重启则丢失

    16.2 规则管理模式-pull模式 

    pull模式:控制台将配置的规则推送到Sentinel客户端,而客户端会将配置规则保存在本地文件或数据库中。以后会定时去本地文件或数据库中查询,更新本地规则。

    首先 Sentinel 控制台通过 API 将规则推送至客户端并更新到内存中,接着注册的写数据源会将新的规则保存到本地的文件中。

    步骤一:编写处理类

    1. package com.xzj.order.config;
    2. import com.alibaba.csp.sentinel.command.handler.ModifyParamFlowRulesCommandHandler;
    3. import com.alibaba.csp.sentinel.datasource.*;
    4. import com.alibaba.csp.sentinel.init.InitFunc;
    5. import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
    6. import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRuleManager;
    7. import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
    8. import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
    9. import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
    10. import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
    11. import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
    12. import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
    13. import com.alibaba.csp.sentinel.slots.system.SystemRule;
    14. import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
    15. import com.alibaba.csp.sentinel.transport.util.WritableDataSourceRegistry;
    16. import com.alibaba.fastjson.JSON;
    17. import com.alibaba.fastjson.TypeReference;
    18. import org.springframework.beans.factory.annotation.Value;
    19. import java.io.File;
    20. import java.io.IOException;
    21. import java.util.List;
    22. public class FilePersistence implements InitFunc {
    23. @Value("${spring.application.name}")
    24. private String appcationName;
    25. @Override
    26. public void init() throws Exception {
    27. String ruleDir ="./sentinel-rules/" + appcationName;
    28. String flowRulePath = ruleDir + "/flow-rule.json";
    29. String degradeRulePath = ruleDir + "/degrade-rule.json";
    30. String systemRulePath = ruleDir + "/system-rule.json";
    31. String authorityRulePath = ruleDir + "/authority-rule.json";
    32. String paramFlowRulePath = ruleDir + "/param-flow-rule.json";
    33. this.mkdirIfNotExits(ruleDir);
    34. this.createFileIfNotExits(flowRulePath);
    35. this.createFileIfNotExits(degradeRulePath);
    36. this.createFileIfNotExits(systemRulePath);
    37. this.createFileIfNotExits(authorityRulePath);
    38. this.createFileIfNotExits(paramFlowRulePath);
    39. // 流控规则
    40. ReadableDataSource> flowRuleRDS = new FileRefreshableDataSource<>(
    41. flowRulePath,
    42. flowRuleListParser
    43. );
    44. FlowRuleManager.register2Property(flowRuleRDS.getProperty());
    45. WritableDataSource> flowRuleWDS = new FileWritableDataSource<>(
    46. flowRulePath,
    47. this::encodeJson
    48. );
    49. WritableDataSourceRegistry.registerFlowDataSource(flowRuleWDS);
    50. // 降级规则
    51. ReadableDataSource> degradeRuleRDS = new FileRefreshableDataSource<>(
    52. degradeRulePath,
    53. degradeRuleListParser
    54. );
    55. DegradeRuleManager.register2Property(degradeRuleRDS.getProperty());
    56. WritableDataSource> degradeRuleWDS = new FileWritableDataSource<>(
    57. degradeRulePath,
    58. this::encodeJson
    59. );
    60. WritableDataSourceRegistry.registerDegradeDataSource(degradeRuleWDS);
    61. // 系统规则
    62. ReadableDataSource> systemRuleRDS = new FileRefreshableDataSource<>(
    63. systemRulePath,
    64. systemRuleListParser
    65. );
    66. SystemRuleManager.register2Property(systemRuleRDS.getProperty());
    67. WritableDataSource> systemRuleWDS = new FileWritableDataSource<>(
    68. systemRulePath,
    69. this::encodeJson
    70. );
    71. WritableDataSourceRegistry.registerSystemDataSource(systemRuleWDS);
    72. // 授权规则
    73. ReadableDataSource> authorityRuleRDS = new FileRefreshableDataSource<>(
    74. authorityRulePath,
    75. authorityRuleListParser
    76. );
    77. AuthorityRuleManager.register2Property(authorityRuleRDS.getProperty());
    78. WritableDataSource> authorityRuleWDS = new FileWritableDataSource<>(
    79. authorityRulePath,
    80. this::encodeJson
    81. );
    82. WritableDataSourceRegistry.registerAuthorityDataSource(authorityRuleWDS);
    83. // 热点参数规则
    84. ReadableDataSource> paramFlowRuleRDS = new FileRefreshableDataSource<>(
    85. paramFlowRulePath,
    86. paramFlowRuleListParser
    87. );
    88. ParamFlowRuleManager.register2Property(paramFlowRuleRDS.getProperty());
    89. WritableDataSource> paramFlowRuleWDS = new FileWritableDataSource<>(
    90. paramFlowRulePath,
    91. this::encodeJson
    92. );
    93. ModifyParamFlowRulesCommandHandler.setWritableDataSource(paramFlowRuleWDS);
    94. }
    95. private Converter> flowRuleListParser = source -> JSON.parseObject(
    96. source,
    97. new TypeReference>() {
    98. }
    99. );
    100. private Converter> degradeRuleListParser = source -> JSON.parseObject(
    101. source,
    102. new TypeReference>() {
    103. }
    104. );
    105. private Converter> systemRuleListParser = source -> JSON.parseObject(
    106. source,
    107. new TypeReference>() {
    108. }
    109. );
    110. private Converter> authorityRuleListParser = source -> JSON.parseObject(
    111. source,
    112. new TypeReference>() {
    113. }
    114. );
    115. private Converter> paramFlowRuleListParser = source -> JSON.parseObject(
    116. source,
    117. new TypeReference>() {
    118. }
    119. );
    120. private void mkdirIfNotExits(String filePath) throws IOException {
    121. File file = new File(filePath);
    122. if (!file.exists()) {
    123. file.mkdirs();
    124. }
    125. }
    126. private void createFileIfNotExits(String filePath) throws IOException {
    127. File file = new File(filePath);
    128. if (!file.exists()) {
    129. file.createNewFile();
    130. }
    131. }
    132. private String encodeJson(T t) {
    133. return JSON.toJSONString(t);
    134. }
    135. }

    步骤二:添加配置  

    resources下创建配置目录 META-INF/services ,然后添加文件

    com.alibaba.csp.sentinel.init.InitFunc

    在文件中添加配置类的全路径

    com.xzj.order.config.FilePersistence

    16.3 规则管理模式-实现push模式

    push模式:控制台将配置规则推送到远程配置中心,例如NacosSentinel客户端监听Nacos,获取配置变更的推送消息,完成本地配置更新。

    push模式实现最为复杂,依赖于nacos,并且需要改在Sentinel控制台。整体步骤如下:

    1. 修改 order-service 服务,使其监听 Nacos 配置中心
    2. 修改 Sentinel-dashboard 源码,配置 nacos 数据源
    3. 修改 Sentinel-dashboard 源码,修改前端页面
    4. 重新编译、打包 -dashboard 源码

    详细步骤可以参考课前资料的《sentinel规则持久化

    步骤一:修改order-service服务,使其监听Nacos配置中心

    具体步骤如下:

    1. 引入依赖

    <dependency>
        <
    groupId>com.alibaba.cspgroupId>
        <artifactId>sentinel-datasource-nacosartifactId>
    dependency>

    配置nacos地址

    spring:
     
    cloud:
        sentinel:
          datasource:
           
    flow:
             
    nacos:
               
    server-addr: localhost:8848 # nacos地址
                dataId: orderservice-flow-rules
               
    groupId: SENTINEL_GROUP
               
    rule-type: flow # 还可以是:degradeauthorityparam-flow

    步骤二:修改sentinel-dashboard源码,添加nacos数据源

    具体步骤如下:

    1. 解压课前资料中的 sentinel 源码包,并用 IDEA 打开:

     

    2. 修改 sentinel-dashboard 源码的 pom 文件,将 sentinel- datasource - nacos 依赖的 scope 去掉

    <dependency>
        <
    groupId>com.alibaba.cspgroupId>
        <
    artifactId>sentinel-datasource-nacosartifactId>
       

    dependency>

     步骤三:修改sentinel-dashboard的源码,配置nacos数据源

    具体步骤如下:

    1. 拷贝 test 目录下的 nacos 代码到 main 下的 com.alibaba.csp.sentinel.dashboard.rule 包:

     

    2. 修改刚刚拷贝的 nacos 包下的 NacosConfig 类,修改其中的 nacos 地址:

     3.修改 com.alibaba.csp.sentinel.dashboard.controller.v2包下的FlowControllerV2类:

    步骤四:修改sentinel-dashboard的源码,修改前端页面:

    修改src/main/webapp/resources/app/scripts/directives/sidebar/目录下的sidebar.html文件:

     

    修改src/main/webapp/resources/app/scripts/directives/sidebar/目录下的sidebar.html文件。

    将其中的这部分注释打开:

    修改其中的文本:

  • 相关阅读:
    ERP采购管理系统软件
    4.0、C语言——goto语句
    快速入门 git 代码版本管理工具(07)
    什么是指令微调(LLM)
    全真模拟题!PMP提分必练
    Jacoco—代码增量覆盖率踩过的坑
    NumPy 数组创建方法与索引访问详解
    wazuh运营使用
    分布式存储系统之Ceph集群状态获取及ceph配置文件说明
    基于java+SpringBoot+HTML+Mysql政务审批网站的设计与实现
  • 原文地址:https://blog.csdn.net/m0_58380757/article/details/126507912