一、环境安装
1、下载jar包
jar包下载地址 github.com/alibaba/Sen…
选择sentinel-dashboard-1.8.5.jar
2、启动
java -Dserver.port=8086 -Dcsp.sentinel.dashboard.server=localhost:8086 -jar sentinel-dashboard-1.8.5.jar
3、访问测试
二、项目开始
搭建一个简单的springboot项目
1、pom文件
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<!-- nacos服务注册与发现 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.7.2</version>
</dependency>
<!-- openfeign 远程调用 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
2、application.yml
server:
port: 8800
#暴露actuator端点 http://localhost:8800/actuator/sentinel
management:
endpoints:
web:
exposure:
include: '*'
spring:
application:
name: chenys-sentinel
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
sentinel:
transport:
# 添加sentinel的控制台地址
dashboard: 127.0.0.1:8086
port: 8719
eager: true
feign:
sentinel:
enabled: true # 激活Sentinel对Feign的支持
3、controler代码
@RestController
public class TestController {
@GetMapping(value = "/test")
@SentinelResource(value="test")
public String test(){
return "test";
}
}
4、配置流控规则
进入sentinel
点击流控规则进行配置
5、测试
快速双击访问,出现如下结果,表示测试成功