GitHub中文版地址:https://github.com/alibaba/Sentinel/wiki/主页
官网地址:https://sentinelguard.io/zh-cn/
随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 是面向分布式、多语言异构化服务架构的流量治理组件,主要以流量为切入点,从流量路由、流量控制、流量整形、熔断降级、系统自适应过载保护、热点流量防护等多个维度来帮助开发者保障微服务的稳定性。
下载地址:https://github.com/alibaba/Sentinel/releases
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4QlRUplx-1668643065832)(image/143、下载Sentinel.png)]](https://1000bd.com/contentImg/2024/04/22/79b41054ad78ea78.png)
在存放下载的Sentitneljar包位置通过如下命令进行启迪
java -jar sentinel-dashboard-1.8.5.jar
页面访问本机地址的8080端口
需要保证本机的8080端口不被占用
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6lZol6pN-1668643065833)(image/144、访问sentinel.png)]](https://1000bd.com/contentImg/2024/04/22/be8c4daabf4e0a0a.png)
win单节点启动命令
startup.cmd -m standalone
浏览器访问:http://192.168.26.1:8848/nacos/index.html
cloudalibaba-sentinel-service8401模块以后使用阿里巴巴cloud的都使用前三个依赖
<dependencies>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
dependency>
<dependency>
<groupId>com.alibaba.cspgroupId>
<artifactId>sentinel-datasource-nacosartifactId>
dependency>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-sentinelartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-openfeignartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-actuatorartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-devtoolsartifactId>
<scope>runtimescope>
<optional>trueoptional>
dependency>
<dependency>
<groupId>cn.hutoolgroupId>
<artifactId>hutool-allartifactId>
<version>4.6.3version>
dependency>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<optional>trueoptional>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
server:
port: 8401
spring:
application:
name: cloudalibaba-sentinel-service
cloud:
nacos:
discovery:
#Nacos服务注册中心地址
server-addr: localhost:8848
sentinel:
transport:
#配置Sentinel dashboard地址,8080监控8401
dashboard: localhost:8080
#默认8719端口,假如被占用会自动从8719开始依次+1扫描,直至找到未被占用的端口
port: 8719
# 图像化展示,暴露所有端口
management:
endpoints:
web:
exposure:
include: '*'
package com.zcl.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* 描述:哨兵启动类
*
* @author zhong
* @date 2022-09-27 22:06
*/
@SpringBootApplication
@EnableDiscoveryClient
public class MainApp8401 {
public static void main(String[] args) {
SpringApplication.run(MainApp8401.class, args);
}
}
package com.zcl.springcloud.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 描述:流控哨兵控制器接口
*
* @author zhong
* @date 2022-09-27 22:07
*/
@RestController
public class FlowLimitController {
@GetMapping("/testA")
public String testA()
{
return "------testA";
}
@GetMapping("/testB")
public String testB()
{
return "------testB";
}
}
在下载的位置通过如下命令启动访问本机8080端口,进入登录
java -jar sentinel-dashboard-1.8.5.jar
Sentinel是懒加载,上面的8401项目已经是跑起来了的,但是直接访问Sentinl是看不到具体的监控服务信息的,需要给服务发送一些请求
http://localhost:8401/testA
http://localhost:8401/testB
访问如上接口后再次查看Sentinel的监控页面
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1pbY221N-1668643065833)(image/145、Sentinel监控服务.png)]](https://1000bd.com/contentImg/2024/04/22/e4adeb4d5ce14fe8.png)