版本说明
springboot 2.7.18
springCloud 2021.0.9
springCloud Alibaba 2021.1
sentinel-dashboard 1.8.7
网关pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 以下依赖仅为整合时的部门pom文件 -->
<!-- Gateway 网关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
<!-- Nacos 服务发现 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- 服务发现:OpenFeign服务调用 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- 整合nacos需要添加负载均衡依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
</dependencies>
</project>
yml配置
spring:
cloud:
sentinel:
filter:
# 通过Spring Cloud Alibaba接入sentinel需要将spring.cloud.sentinel.filter.enabled 配置项置为 false
enabled: false
transport:
# sentinel控制台地址
dashboard: 192.168.60.129:8080
# sentinel控制台端口
port: 8719
# 客户端IP
client-ip: 192.168.34.127
#数据源
datasource:
ds1:
nacos:
server-addr: 192.168.60.129:8848
username: nacos
password: nacos
dataId: sentinel-flow-rules
group-id: DEFAULT_GROUP
namespace: 97a510c9-a3ac-429d-a32b-0c66f0009107
# 若使用 Spring Cloud Alibaba Sentinel 数据源模块,需要注意网关流控规则数据源类型是 gw-flow,若将网关流控规则数据源指定为 flow 则不生效
rule-type: gw_flow
data-type: json
# nacos 相关配置
nacos:
discovery:
# nacos服务器地址
server-addr: 192.168.60.129:8848
# 用户名
username: nacos
# 密码
password: nacos
# 命名空间
namespace: 97a510c9-a3ac-429d-a32b-0c66f0009107
# 网关配置
gateway:
# 路由配置
routes:
- id: easy-login-auth
uri: lb://easy-login-auth
# 路由匹配规则
predicates:
- Path=/auth/**
nacos添加响应的配置规则
[
{
"app": "easy-login-gateway",
"ip": "192.168.60.129",
"resource": "easy-login-auth",
"resourceMode": 0,
"grade": 1,
"count": 120.0,
"interval": 1,
"intervalUnit": 0,
"controlBehavior": 0,
"burst": 0,
"maxQueueingTimeoutMs": 500,
"paramItem": null
}
]
刷新sentinel控制台
以上步骤就实现了nacos推送规则至sentinel控制台,sentinel同步规则至nacos待研究
踩坑
-
nacos添加完规则sentinel控制台不显示
原因: