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

相关推荐
青鱼入云21 分钟前
介绍Spring Cloud Gateway
spring cloud·微服务
戮戮25 分钟前
一次深入排查:Spring Cloud Gateway TCP 连接复用导致 K8s 负载均衡失效
tcp/ip·spring cloud·kubernetes·gateway·负载均衡·netty
2301_797604243 小时前
d44:Sentinel 微服务流量控制与 Seata 分布式事务
分布式·微服务·sentinel
新手小白*6 小时前
Redis Sentinel哨兵集群
数据库·redis·sentinel
后端小张6 小时前
【JAVA 进阶】Mybatis-Plus 实战使用与最佳实践
java·spring boot·spring·spring cloud·tomcat·mybatis·mybatis plus
青鱼入云18 小时前
介绍Spring Cloud Stream
spring cloud·微服务
青鱼入云18 小时前
介绍一下Ribbon的工作原理
spring cloud·微服务·ribbon
青鱼入云1 天前
Ribbon是如何与服务注册中心nacos交互的
spring cloud·微服务·ribbon
青鱼入云1 天前
OpenFeign介绍
spring cloud·微服务
勇往直前plus1 天前
学习和掌握RabbitMQ及其与springboot的整合实践(篇一)
spring boot·学习·spring cloud·rabbitmq·java-rabbitmq