五、配置Sentinel

GitEgg...大约 1 分钟快速开始快速开始安装Sentinel

1. Sentinel 是一个标准的 Spring Boot 应用,以 Spring Boot 的方式运行 jar 包即可,在官网下载好 sentinel-dashboard-1.8.2.jar 包之后,直接运行启动命令(Windows):

java '-Dserver.port=8086' '-Dcsp.sentinel.dashboard.server=127.0.0.1:8086' '-Dproject.name=sentinel-dashboard' -jar sentinel-dashboard-1.8.2.jar

请注意 Windows 的下执行命令,参数需要加单引号,否则会报 错误: 找不到或无法加载主类 .port=错误

2. 启动成功之后,访问 Sentinel 管理台地址:http://127.0.0.1:8086open in new window , 默认用户名/密码:sentinel/sentinel。

3. 在 Nacos 中配置 Sentinel 相关配置项,新增配置项 Data ID 为 gitegg-config-sentinel,Group 为 GITEGG 的配置项,请注意,这里的配置格式是 JSON。

[
    {
        "resource": "/system/sentinel/protected",
        "count": 5,
        "grade": 1,
        "limitApp": "default",
        "strategy": 0,
        "controlBehavior": 0,
        "clusterMode": false
    }
]

4. 在 Nacos 中 gitegg-config.yaml 配置项中修改相关 Sentinel 配置。

  cloud:
    sentinel:
      filter:
        enabled: true
      transport:
        port: 8719
        dashboard: 127.0.0.1:8086
      eager: true
      datasource:
        ds2:
          nacos:
            data-type: json
            server-addr: 127.0.0.1:8848
            dataId: gitegg-config-sentinel
            groupId: GITEGG
            rule-type: flow