SpringCloud Alibaba Sentinel基础入门与安装

GitHub地址:https://github.com/alibaba/Sentinel

中文文档:https://sentinelguard.io/zh-cn/docs/introduction.html

下载地址:https://github.com/alibaba/Sentinel/releases

Spring Cloud Alibaba 官方说明文档:Spring Cloud Alibaba Reference Documentation

WIKI地址:https://github.com/alibaba/Sentinel/wiki/介绍

随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 是面向分布式、多语言异构化服务架构的流量治理组件,主要以流量为切入点,从流量路由、流量控制、流量整形、熔断降级、系统自适应过载保护、热点流量防护等多个维度来帮助开发者保障微服务的稳定性。

Sentinel 具有以下特征:

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

简单来讲,其是SpringCloud Hystrix的阿里替代升级版。

【1】安装

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

使用命令进行启动,这里需要事先配置好java环境:

bash 复制代码
java -jar sentinel-dashboard-1.8.8.jar

浏览器访问 http://localhost:8080,账号密码均为 sentinel 。

【2】服务监控

先启动Nacos和Sentinel两个服务。

① pom依赖

如下所示,对于SpringCloud Alibaba来说Nacos与sentinel标配组合。

xml 复制代码
<dependency>
     <groupId>com.alibaba.cloud</groupId>
     <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
 </dependency>
 <!-- 后续做持久化用到 -->
 <dependency>
     <groupId>com.alibaba.csp</groupId>
     <artifactId>sentinel-datasource-nacos</artifactId>
 </dependency>
 <dependency>
     <groupId>com.alibaba.cloud</groupId>
     <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
 </dependency>

② yml配置

yml 复制代码
server:
  port: 8401

spring:
  application:
    name: cloud-alibaba-sentinel-service
  cloud:
    nacos:
      discovery:
        # 服务注册中心地址
        server-addr: localhost:8848
    sentinel:
      transport:
        # 配置sentinel dashboard地址
        dashboard: localhost:8080
        # 默认 8719端口,假如被占用从8719开始+1扫描直到直到未被占用的端口
        port: 8719
management:
  endpoints:
    web:
      exposure:
        include: '*'

③ 主启动类

java 复制代码
@SpringBootApplication
@EnableDiscoveryClient
public class SentinelServiceMain8401 {
    public static void main(String[] args) {
        SpringApplication.run(SentinelServiceMain8401.class,args);
    }
}

由于Sentinel采取了懒加载机制,故而需要我们发起服务请求,才可以在控制台看到服务。

相关推荐
星辰_mya19 小时前
Spring Cloud服务熔断与降级
后端·spring·spring cloud
yzp-1 天前
Sentinel 执行流程
sentinel
全栈开发圈2 天前
新书速览|从零开始学Spring Cloud微服务架构
spring cloud·微服务·架构
sniper_fandc2 天前
Spring Cloud系列—Seata分布式事务解决方案AT模式
spring cloud·seata
七夜zippoe2 天前
Spring Cloud与Dubbo架构哲学对决
java·spring cloud·架构·dubbo·配置中心
SmartBrain2 天前
AI智能体:MCP模型上下文管理设计及实现
人工智能·spring cloud·架构
Slow菜鸟2 天前
Spring Cloud 教程(四) | OpenFeign 的作用
后端·spring·spring cloud
却话巴山夜雨时i2 天前
互联网大厂Java面试:从Spring到微服务
spring cloud·微服务·oauth2·java面试·stream api
停水咋洗澡2 天前
Redis Sentinel高可用实战:主从自动故障转移
java·redis·sentinel
鬼先生_sir3 天前
SpringCloud-Sentinel(熔断降级 & 流量控制)
spring·spring cloud·sentinel