文章目录
1、前置
1、 sentinel版本:1.7.1
2、具体整合的代码太多了, 我就不贴代码了, 但是会简单说明
3、 存在的问题以及解决方式
4、代码地址: https://gitee.com/xmaxm/sentinel-dashboard
Docker镜像地址: https://hub.docker.com/r/chaim2436/sentinel-dashboard
5、最后就说一下部署方式
2、变动说明
代码太多了, 这里就已提交记录对操作做一下说明. git的提交日志也记录的很详细, 大家可以clone下来看下提交记录
已提交记录为概述 (五次) :
- 初始化(b2550307): 下载1.7.1对应版本代码, 导入模块 sentinel-dashboard, 上传到git
源码地 址:https://github.com/alibaba/Sentinel/releases - sentinel整合nacos, 实现数据持久化(4522635c,27296f38): 这个就不详细解释了, 网上真的太多了,搜索一下sentinel整合nacos, 都是这一步.
简单解释一下: Sentinel-1.7.1\sentinel-dashboard\src\test\java\com\alibaba\csp\sentinel\dashboard\rule\nacos是官方给的整合nacos的案列, 太简洁了, 故需进行修改完善 - 处理sentinel持久化nacos(3e87e56a): 发布配置nacos异步处理, 导致数据不一致, 以及间接导致问题 如: CUD页面刷新后,数据需在次刷新才能同步数据, 否在次添加会导致数据覆盖等问题
- 修改nacos参数为可配置(a8e05ecd,4890a4ff): 提取nacos参数为可配置项, 以及处理默认值, 可通过entrypoint.sh进行挂载指定
- 去除缓存repository(7994ab97),修改接口入参,以及页面: repository没有存在的必要, CURD都是操作的nacos, 对应的参数进行修改
- 后面的提交就是完善一下代码, 添加一下部署相关操作
2、存在的问题, 解决方式
- 问题1: 修改了前端的JS不起效果
解决方式: npm start从新编译, 项目的README.md文件有做对应说明(2. 简单说一下前端js修改) - 问题2: 在没有实现提交记录1.3的时候.
1、CUD数据, 都需要刷新才能显示出刚刚操作的结果.
2、在不刷新紧接着在次添加数据, 会覆盖上一次操作的数据
3、刷新后, 重启sentinel, 添加数据, 会从ID为1(递增)依次覆盖旧数据, 因为ID的生成规则
解决方式: 添加nacos的监听配置, 修改缓存repository的save方式(我是去除了repository, 因为整合nacos之后没有存在的意义), 修改ID的规则. (对应解决方式, 提交记录: 1.3 1.5)
3、部署
镜像已经上传至docker仓库
想自己打包, 可以参考我以前的一篇博客: SpringBoot 聚合项目打jar包,docker部署: https://blog.csdn.net/qq_38637558/article/details/105154483
docker pull chaim2436/sentinel-dashboard:1.7.1
entrypoint.sh为挂载文件, 可配置参数如下(也支持sentinel本身存在的参数):
挂载文件: entrypoint.sh:
# nacos地址
-Dspring.cloud.sentinel.datasource.nacos.server-addr=192.168.160.1:8848
# nacos分组
-Dspring.cloud.sentinel.datasource.nacos.groupId=SENTINEL_GROUP
# nacos命名空间, 默认值空
-Dspring.cloud.sentinel.datasource.nacos.namespace=
# 流控规则nacos配置文件后缀
-Dspring.cloud.sentinel.datasource.nacos.flow-data-postfix=-flow-rules
# 降级规则nacos配置文件后缀
-Dspring.cloud.sentinel.datasource.nacos.degrade-data-postfix=-degrade-rules
# 系统规则nacos配置文件后缀
-Dspring.cloud.sentinel.datasource.nacos.system-data-postfix=-system-rules
# 热点规则nacos配置文件后缀
-Dspring.cloud.sentinel.datasource.nacos.param-flow-data-postfix=-param-flow-rules
# 授权规则nacos配置文件后缀
-Dspring.cloud.sentinel.datasource.nacos.authority-data-postfix=-authority-rules
# nacos发布配置等待监听响应时长: check-count * 500ms.系统稳定状态配置6已足够
-Dspring.cloud.sentinel.datasource.nacos.check-count=6
# 服务端口
-Dserver.port=8858
# 是否开启登录鉴权,仅用于日常测试,生产上不建议关闭, 默认true
-Dauth.enabled="true"
# 登录控制台的用户名
-Dsentinel.dashboard.auth.username=sentinel
# 登录控制台的密码
-Dsentinel.dashboard.auth.password=sentinel
# 用于指定 Spring Boot 服务端 session 的过期时间,如 7200 表示 7200 秒;60m 表示 60 分钟,默认为 30 分钟;
-Dserver.servlet.session.timeout=7200
# 控制台的地址
-Dcsp.sentinel.dashboard.server=localhost:8858
# 指定应用的名称
-Dproject.name=sentinel
# 本地启动 HTTP API Server 的端口号
-Dcsp.sentinel.api.port=8719
docker-compose方式:
# Compose 版本 Version 2支持更多的指令。Version 1将来会被弃用。
version: "3"
# 定义服务
services:
# 为project定义服务
sentinel:
image: chaim2436/sentinel-dashboard:1.7.1
ports:
- 8858:8858
# 挂载
volumes:
- "F://Docker/sentinel/chaim_sentinel-dashboard/entrypoint/entrypoint.sh:/sentinel/entrypoint.sh"
- "F://Docker/sentinel/chaim_sentinel-dashboard/log/:/var/sentinel/logs/"
restart: always
container_name: sentinel
privileged: true
docker run方式:
docker run --name sentinel -p 8858:8858 -v F:\Docker\sentinel\chaim_sentinel-dashboard\entrypoint\entrypoint.sh:/sentinel/entrypoint.sh -v F:\Docker\sentinel\chaim_sentinel-dashboard\log/:/var/sentinel/logs/ -d chaim2436/sentinel-dashboard:1.7.1
4、微服务对接
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
spring:
cloud:
sentinel:
datasource:
# 名称随意
flow:
nacos:
server-addr: 127.0.0.1:8848
# 对应的规则后缀, 需要和sentinel持久化指定后缀一致
dataId: ${spring.application.name}-flow-rules
namespace: ${spring.cloud.nacos.config.namespace}
groupId: SENTINEL_GROUP
# 规则类型,取值见:oud.sentinel.datasource.RuleType
rule-type: flow
degrade:
nacos:
server-addr: localhost:8848
namespace: ${spring.cloud.nacos.config.namespace}
dataId: ${spring.application.name}-degrade-rules
groupId: SENTINEL_GROUP
rule-type: degrade
system:
nacos:
server-addr: localhost:8848
namespace: ${spring.cloud.nacos.config.namespace}
dataId: ${spring.application.name}-system-rules
groupId: SENTINEL_GROUP
rule-type: system
authority:
nacos:
server-addr: localhost:8848
namespace: ${spring.cloud.nacos.config.namespace}
dataId: ${spring.application.name}-authority-rules
groupId: SENTINEL_GROUP
rule-type: authority
param-flow:
nacos:
server-addr: localhost:8848
namespace: ${spring.cloud.nacos.config.namespace}
dataId: ${spring.application.name}-param-flow-rules
groupId: SENTINEL_GROUP
rule-type: param-flow
5、最后
其余可配置参数:
1、启动配置项: https://github.com/alibaba/Sentinel/wiki/%E5%90%AF%E5%8A%A8%E9%85%8D%E7%BD%AE%E9%A1%B9
2、控制台: https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0
git提交记录也算详细的说明了, 涉及到问题也都有处理, 可能存在还没有发现的问题, 可以留言就行修复
重点说明, 本次是基于sentinel版本:1.7.1进行的整合, 其余的版本也可以参考