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采取了懒加载机制,故而需要我们发起服务请求,才可以在控制台看到服务。

相关推荐
方便面不加香菜12 小时前
Docker Compose 文件 -- docker-compose.yml
spring cloud·docker·容器
txxzjmzlh1 天前
Alibaba Sentinel
sentinel
真上帝的左手2 天前
31. 占位-14
分布式·spring cloud·架构·系统架构
captain3763 天前
SpringCloud(12)-Gateway
spring boot·spring cloud·gateway
行百里er4 天前
【Spring Insight 技术分享】如何让 AI 解释失败也不拖垮控制台
后端·spring cloud·开源
行百里er5 天前
【Spring Insight 技术分享】如何给 AI 接口调用做滑动窗口限流
spring boot·后端·spring cloud
小南家的青蛙8 天前
Sentinel实战指南
sentinel
逃逸线LOF10 天前
SpringCloud Stream
后端·spring·spring cloud
时间的拾荒人11 天前
Redis 哨兵(Sentinel)详解:原理、选举机制与实战部署
redis·面试·架构·sentinel
wz975413 天前
Docker 从 systemd 托管容器、overlay2 存储驱动到 Compose 多容器实战
spring cloud·docker·eureka