铁匠 铁匠
首页
收藏
java
架构之路
常用算法
  • Java
  • nginx
  • 系统运维
  • 系统安全
  • mysql
  • redis
参考文档
关于
链接
  • 分类
  • 标签
  • 归档

专注、不予评判地关注当下
首页
收藏
java
架构之路
常用算法
  • Java
  • nginx
  • 系统运维
  • 系统安全
  • mysql
  • redis
参考文档
关于
链接
  • 分类
  • 标签
  • 归档
  • 概览

  • 设计模式

  • 高可用

  • 性能优化

  • 分布式

  • 网关

  • 流量治理

    • 不改一行源码,实现 sentinel-dashboard 所有配置支持 apollo 持久化
    • sentinel-dashboard-apollo 使用
      • 说明
      • 获取 sentinel-dashboard-apollo
      • apollo 开放平台配置
      • 启动 dashboard
        • 启动参数
        • docker 方式启动
      • dataId 命名规则
      • 客户端配置
        • 动态规则扩展 - 普通应用接入参考
        • Spring Cloud Alibaba Sentinel 参考
        • spring-boot(cloud) 整合 demo
      • 交流群
  • 数据治理

  • 云原生

  • 网络安全

  • 架构
  • 流量治理
fengjx
2022-08-01
目录

sentinel-dashboard-apollo 使用

# 说明

使用前需要对 apollo 的基本使用有一定了解,如果对 apollo 还不是很了解,可以先看下 apollo 的使用文档。

  • github: https://github.com/apolloconfig/apollo (opens new window)
  • 文档: https://www.apolloconfig.com/#/zh/README (opens new window)
  • spring-boot(cloud) 整合 demo: https://github.com/fengjx/sentinel-dashboard-demo (opens new window)

# 获取 sentinel-dashboard-apollo

  1. 从 release (opens new window) 页面下载对应版本 jar 包
  2. 从源码编译
    git clone https://github.com/fengjx/Sentinel.git
    # 替换成实际版本
    cd Sentinel
    version=1.8.4
    git checkout tags/dashboard/apollo/v${version} -b sentinel-dashboard-apollo-${version}
    cd sentinel-dashboard
    mvn clean package -DskipTests=true -Dmaven.javadoc.skip=true
    # 打包好的 jar 在 target/sentinel-dashboard-apollo-${version}.jar
    
    1
    2
    3
    4
    5
    6
    7
    8

# apollo 开放平台配置

参考:https://www.apolloconfig.com/#/zh/usage/apollo-open-api-platform (opens new window)

# 启动 dashboard

可以直接通过 java -jar 启动,在官方版本启动参数的基础上增加了 apollo 的配置,对官方版本启动参数完全兼容。

官方版本启动参数请查看:Sentinel 控制台 (opens new window),这里不做说明。

# 启动参数

参数 默认值 说明 版本支持
metric.store-type default 监控数据持久化类型:default, redis 1.8.6.1+
spring.redis.host 127.0.0.1 metric.store-type = redis 时需要配置 1.8.6.1+
spring.redis.port 6379 metric.store-type = redis 时需要配置 1.8.6.1+
rule.store.type default 规则配置持久化类型:default, apollo 1.8.6.1+
apollo.sentinel.portalUrl http://localhost:8080 apollo portal server 地址 1.8.4+
apollo.sentinel.token token apollo 开放平台 token,根据实际修改 1.8.4+
apollo.sentinel.operator apollo 数据提交的 apollo 用户 1.8.4+
apollo.sentinel.appId app-sentinel 数据持久化的 appId 1.8.4+
apollo.sentinel.env DEV 对应 apollo 环境 1.8.4+
apollo.sentinel.clusterName default apollo 集群,一般都是 default 1.8.4+
apollo.sentinel.namespace application 数据保存的命名空间 1.8.4+

启动命令示例

java -jar sentinel-dashboard-apollo.jar \
  --server.port=8081 \
  --metric.store-type=redis \
  --spring.redis.host=redis-demo \
  --spring.redis.port=6379 \
  --rule.store.type=apollo \
  --apollo.sentinel.portalUrl=http://192.168.1.10:8070 \
  --apollo.sentinel.token=7273d9b5892d8af51b0d7400b61401ef57f1bf4e \
  --apollo.sentinel.operator=halo \
  --apollo.sentinel.appId=halo-common \
  --apollo.sentinel.env=DEV \
  --apollo.sentinel.namespace=halo-sentinel-rule
1
2
3
4
5
6
7
8
9
10
11
12

# docker 方式启动

docker run -d --name sentinel-dashboard \
-p 8080:8080 \
-e JAVA_OPTS="-Dlogging.level.com.alibaba.csp.sentinel=debug \
-Dserver.port=8080 \
-Dmetric.store-type=redis \
-Dspring.redis.host=redis-demo \
-Dspring.redis.port=6379 \
-Drule.store.type=apollo \
-Dapollo.sentinel.portalUrl=http://apollo-demo:8070 \
-Dapollo.sentinel.token=183d39a00a46656063ab286830f71e023d24c454 \
-Dapollo.sentinel.operator=apollo \
-Dapollo.sentinel.appId=sentinel-demo-server \
-Dapollo.sentinel.env=DEV \
-Dapollo.sentinel.namespace=sentinel-rule \
fengjx/sentinel-dashboard:1.8.6.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# dataId 命名规则

服务名-规则类型

共有 7 种规则类型,对应类型可以查看枚举 com.alibaba.csp.sentinel.dashboard.rule.RuleType

/**
  * 流控规则
  */
FLOW("flow", FlowRuleEntity.class),
/**
  * 熔断规则
  */
DEGRADE("degrade", DegradeRuleEntity.class),
/**
  * 热点规则
  */
PARAM_FLOW("param-flow", ParamFlowRuleEntity.class),
/**
  * 系统规则
  */
SYSTEM("system", SystemRuleEntity.class),
/**
  * 授权规则
  */
AUTHORITY("authority", AuthorityRuleEntity.class),
/**
  * 网关流控规则
  */
GW_FLOW("gw-flow", GatewayFlowRuleEntity.class),
/**
  * api 分组
  */
GW_API_GROUP("gw-api-group", ApiDefinitionEntity.class);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

apollo 中的配置示例

# 客户端配置

添加数据源扩展依赖依赖

<groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-apollo</artifactId>
    <version>对应官方版本号</version>
</dependency>
1
2
3
4

参数配置与官方配置完全一致

# 动态规则扩展 - 普通应用接入参考

文档:https://sentinelguard.io/zh-cn/docs/dynamic-rule-configuration.html (opens new window)

参考推模式:使用 Apollo 配置规则 章节

# Spring Cloud Alibaba Sentinel 参考

文档:https://github.com/alibaba/spring-cloud-alibaba/wiki/Sentinel (opens new window)

配置示例

sentinel.apollo.namespace-name=halo-sentinel-rule
spring.cloud.sentinel.transport.dashboard=192.168.1.10:8081
spring.cloud.sentinel.log.dir=${LOG_PATH:./logs}/sentinel

# 流控规则
spring.cloud.sentinel.datasource.ds1.apollo.rule-type=flow
spring.cloud.sentinel.datasource.ds1.apollo.namespace-name=${sentinel.apollo.namespace-name}
spring.cloud.sentinel.datasource.ds1.apollo.flow-rules-key=${spring.application.name}-${spring.cloud.sentinel.datasource.ds1.apollo.rule-type}

# 熔断规则
spring.cloud.sentinel.datasource.ds2.apollo.rule-type=degrade
spring.cloud.sentinel.datasource.ds2.apollo.namespace-name=${sentinel.apollo.namespace-name}
spring.cloud.sentinel.datasource.ds2.apollo.flow-rules-key=${spring.application.name}-${spring.cloud.sentinel.datasource.ds2.apollo.rule-type}

## 热点规则
spring.cloud.sentinel.datasource.ds3.apollo.rule-type=param-flow
spring.cloud.sentinel.datasource.ds3.apollo.namespace-name=${sentinel.apollo.namespace-name}
spring.cloud.sentinel.datasource.ds3.apollo.flow-rules-key=${spring.application.name}-${spring.cloud.sentinel.datasource.ds3.apollo.rule-type}

# 系统规则
spring.cloud.sentinel.datasource.ds4.apollo.rule-type=system
spring.cloud.sentinel.datasource.ds4.apollo.namespace-name=${sentinel.apollo.namespace-name}
spring.cloud.sentinel.datasource.ds4.apollo.flow-rules-key=${spring.application.name}-${spring.cloud.sentinel.datasource.ds4.apollo.rule-type}

# 认证规则
spring.cloud.sentinel.datasource.ds5.apollo.rule-type=authority
spring.cloud.sentinel.datasource.ds5.apollo.namespace-name=${sentinel.apollo.namespace-name}
spring.cloud.sentinel.datasource.ds5.apollo.flow-rules-key=${spring.application.name}-${spring.cloud.sentinel.datasource.ds5.apollo.rule-type}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# spring-boot(cloud) 整合 demo

https://github.com/fengjx/sentinel-dashboard-demo (opens new window)

# 交流群

#sentinel#流量治理
不改一行源码,实现 sentinel-dashboard 所有配置支持 apollo 持久化
MySQL 异构数据同步方案 - canal 高可用部署

← 不改一行源码,实现 sentinel-dashboard 所有配置支持 apollo 持久化 MySQL 异构数据同步方案 - canal 高可用部署→

最近更新
01
策略模式
01-09
02
模板方法
01-06
03
观察者模式
01-06
更多文章>
Theme by Vdoing | Copyright © 2016-2023 铁匠 | 粤ICP备15021633号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式