Sentinel生产环境实践
来自杨三超wiki
1、功能描述
API 限流
sentinel默认会探测所有API,但需要注意,Sentinel 会在客户端首次调用时候进行初始化,开始向控制台发送心跳包。因此需要确保客户端有访问量,才能在控制台上看到监控数据。
RPC限流粒度
可以是服务接口和服务方法两种粒度:
- 服务接口:resourceName 为
接口全限定名
,如com.alibaba.csp.sentinel.demo.dubbo.FooService
- 服务方法:resourceName 为
接口全限定名:方法签名
,如com.alibaba.csp.sentinel.demo.dubbo.FooService:sayHello(java.lang.String)
存在问题
1、规则持久化
支持基于 ZooKeeper / Nacos / Apollo 的数据源规则持久化,但需要改造;
2、统一异常处理;
需要自己改造;
3、监控数据持久化;
需要自己改造;
2、Dashboard改造部署
1、修改路由规则
第一步:修改dashboad.flowV1为dashboad.flow;
第二步:FlowServiceV1修改为FlowServiceV2;
2、支持规则持久化
sentinel支持限流、降级、热点、系统、授权五种规则,目前常用的功能是限流和降级、基于zookeeper实现持久化规则;
dashboad默认规则都是内存,同时需要修改对应的Controller;
3、监控日志持久化
默认监控日志仅在内容保留5分钟
4、部署
- 编译jar包:https://github.com/alibaba/Sentinel/releases
- 启动:java -Dserver.port=8100 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.6.2.jar
-
-Dserver.port=8080
用于指定 Sentinel 控制台端口为8100
。
-
- 扩展阅读 Sentinel 控制台: https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0
3、服务如何使用
1、添加相关pom
1.1 springboot2.x添加pom
|
1.2 springboot1.5.x添加pom
折叠源码
|
2、添加配置
|
3、添加统一异常
API统一异常
|
dubbo统一异常
|