Sentinel的安装和微服务的集成

整个项目请看gitee:https://gitee.com/xwb1056481167/spring-cloud

sentinel简介

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

sentinel的下载和安装

sentinel下载地址:https://github.com/alibaba/Sentinel/releases
1.7.1下载地址: https://github.com/alibaba/Sentinel/releases/download/1.7.1/sentinel-dashboard-1.7.1.jar

启动Sentinel

java -jar sentinel-dashboard-1.7.1.jar

访问地址:

http://localhost:8080 //用户名和密码sentinel/sentinel

访问成功的页面

微服务集成8401

微服务cloudalibaba-sentinel-service8401集成sentinel

扫描二维码关注公众号,回复: 13070513 查看本文章

1、pom.xml

<!-- alibaba sentinel -->
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
<!-- alibaba nacos -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- alibaba nacos sentinel -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

2、yml

server:
  port: 8401
spring:
  application:
    name: cloudalibaba-centinel-service
  cloud:
    nacos:
      discovery:
        #nacos服务注册中心地址
        server-addr: localhost:8848
    sentinel:
      transport:
        #默认8719端口,加入端口被占用了会自动从8719开始一次+1扫描,知道扫描到未被占用的端口
        port: 8719
        #配置sentinel dashboard地址
        dashboard: localhost:8080
management:
  endpoints:
    web:
      exposure:
        include:  '*'

3、主启动类

@SpringBootApplication
@EnableDiscoveryClient
public class SentinelMainApp8401 {
    public static void main(String[] args) {
        SpringApplication.run(SentinelMainApp8401.class, args);
    }
}

4、测试controller

@RestController
public class FlowLimitController {
    @GetMapping("/testA")
    public String testA() {
        return "-----------testA";
    }
    @GetMapping("/testB")
    public String testB() {
        return "-----------testB";
    }
}

启动测试:8848nacos服务端,8080Sentinel服务端。cloudalibaba-sentinel-service8401client端,

需要访问一次8401的接口才会被sentinel监控,不然刷新监控是没有任何信息的

猜你喜欢

转载自blog.csdn.net/www1056481167/article/details/113679945