您的位置:首页 > 编程语言 > Java开发

SpringCloud(Hoxton.SR3)集成Alibaba Sentinel(1.7.2)流量限流

2020-06-04 06:41 274 查看

一、安装Sentinel控制台
1、下载最新版本控制台sentinel-dashboard-1.7.2.jar,下载地址
2、Linux启动命令

java -Dserver.port=8892 -Dcsp.sentinel.dashboard.server=10.101.128.148:8892 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.7.2.jar

二、集成到项目中
1、pom.xml 中引入依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>

2、yml配置文件如下所示

spring:
cloud:
sentinel:
eager: true  #Sentinel控制台懒加载
transport:
client-ip: 10.101.128.64  #客户端IP(将被注册到 Sentinel Server 端)
port: 8701  #应用与Sentinel控制台交互的端口,应用本地会起一个该端口占用的HttpServer
dashboard: 10.101.128.148:8892  #Sentinel服务端地址和端口号
heartbeat-interval-ms: 500  #应用与Sentinel控制台的心跳间隔时间
enabled: true

Spring Cloud Alibaba Sentinel 配置选项

配置项 含义 默认值
spring.application.name or project.name Sentinel项目名
spring.cloud.sentinel.enabled Sentinel自动化配置是否生效 TRUE
spring.cloud.sentinel.eager 是否提前触发 Sentinel 初始化 FALSE
spring.cloud.sentinel.transport.port 应用与Sentinel控制台交互的端口,应用本地会起一个该端口占用的HttpServer 8719
spring.cloud.sentinel.transport.dashboard Sentinel 控制台地址
spring.cloud.sentinel.transport.heartbeat-interval-ms 应用与Sentinel控制台的心跳间隔时间
spring.cloud.sentinel.transport.client-ip 此配置的客户端IP将被注册到 Sentinel Server 端
spring.cloud.sentinel.filter.order Servlet Filter的加载顺序。Starter内部会构造这个filter Integer.MIN_VALUE
spring.cloud.sentinel.filter.url-patterns 数据类型是数组。表示Servlet Filter的url pattern集合 /*
spring.cloud.sentinel.filter.enabled Enable to instance CommonFilter TRUE
spring.cloud.sentinel.metric.charset metric文件字符集 UTF-8
spring.cloud.sentinel.metric.file-single-size Sentinel metric 单个文件的大小
spring.cloud.sentinel.metric.file-total-count Sentinel metric 总文件数量
spring.cloud.sentinel.log.dir Sentinel 日志文件所在的目录
spring.cloud.sentinel.log.switch-pid Sentinel 日志文件名是否需要带上pid FALSE
spring.cloud.sentinel.servlet.block-page 自定义的跳转 URL,当请求被限流时会自动跳转至设定好的 URL
spring.cloud.sentinel.flow.cold-factor https://github.com/alibaba/Sentinel/wiki 3
spring.cloud.sentinel.zuul.order.pre SentinelZuulPreFilter 的 order 10000
spring.cloud.sentinel.zuul.order.post SentinelZuulPostFilter 的 order 1000
spring.cloud.sentinel.zuul.order.error SentinelZuulErrorFilter 的 order -1
spring.cloud.sentinel.scg.fallback.mode Spring Cloud Gateway 熔断后的响应模式(选择 redirect or response)
spring.cloud.sentinel.scg.fallback.redirect Spring Cloud Gateway 响应模式为 ‘redirect’ 模式对应的重定向 URL
spring.cloud.sentinel.scg.fallback.response-body Spring Cloud Gateway 响应模式为 ‘response’ 模式对应的响应内容
spring.cloud.sentinel.scg.fallback.response-status Spring Cloud Gateway 响应模式为 ‘response’ 模式对应的响应码 429
spring.cloud.sentinel.scg.fallback.content-type Spring Cloud Gateway 响应模式为 ‘response’ 模式对应的 content-type application/json

3、启动项目,就可登录Sentinel进行相关操作

登录地址:http://10.101.128.148:8892
用户名:sentinel
密码:sentinel

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: