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

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监控,不然刷新监控是没有任何信息的

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值