SpringBoot环境整合
SpringBoot环境整合
引入Pom依赖
如果要在您的项目中引入 Sentinel,使用 group ID 为 com.alibaba.cloud 和 artifact ID 为 spring-cloud-starter-alibaba-sentinel 的 starter。
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>注意
如果项目中未引入Spring Cloud Alibaba相关配置,请先在 dependencyManagement 中添加如下配置。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>Sentinel 控制台
Sentinel控制台提供一个轻量级的控制台,它提供机器发现、单机资源实时监控、集群资源汇总,以及规则管理的功能。您只需要对应用进行简单的配置,就可以使用这些功能。
注意: 集群资源汇总仅支持 500 台以下的应用集群,有大概 1 - 2 秒的延时。

获取控制台
根据你项目中依赖的Sentinel版本,您可以从 release 页面 下载最新版本的控制台 jar 包。
我的是1.6.3版本

启动控制台
Sentinel 控制台是一个标准的 Spring Boot 应用,以 Spring Boot 的方式运行 jar 包即可。
Sentinel默认8080端口启动。如若8080端口冲突,可使用 --server.port=新端口 进行设置。
java -jar sentinel-dashboard-1.6.3.jar --server.port=8333
浏览器访问
浏览器访问 http://localhost:8333 进入Sentinel控制台界面
默认用户名和密码均为sentinel,登录即可
注意:
首次登录,页面可能为空白状态,这是因为Sentinel为懒加载模式,只有监控到对应的请求后,才会有数据展现

配置控制台
修改application.yml文件,增加如下配置:
spring:
cloud:
sentinel:
transport:
# Sentinel与服务之间通信的接口
port: 8719
# Sentinel控制台地址
dashboard: localhost:8333这里的 spring.cloud.sentinel.transport.port 端口配置会在应用对应的机器上启动一个 Http Server,该 Server 会与 Sentinel 控制台做交互。比如 Sentinel 控制台添加了一个限流规则,会把规则数据 push 给这个 Http Server 接收,Http Server 再将规则注册到 Sentinel 中。
Endpoint 支持
Sentinel Endpoint 里暴露的信息非常有用。包括当前应用的所有规则信息、日志目录、当前实例的 IP,Sentinel Dashboard 地址,Block Page,应用与 Sentinel Dashboard 的心跳频率等等信息。
在使用 Endpoint 特性之前需要在 Maven 中添加 spring-boot-starter-actuator 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>并在配置中允许 Endpoints 的访问。
- Spring Boot 1.x 中添加配置
management.security.enabled=false。暴露的 endpoint 路径为/sentinel - Spring Boot 2.x 中添加配置
management.endpoints.web.exposure.include=*。暴露的 endpoint 路径为/actuator/sentinel
# 配置Endpoint信息
management:
endpoints:
web:
exposure:
include: '*'请求测试
在浏览器中访问项目中的某个请求后,在Sentinel控制台查看监控情况如下

