美文网首页
微服务 Spring Cloud Alibaba 项目搭建(六、

微服务 Spring Cloud Alibaba 项目搭建(六、

作者: 一介书生独醉江湖 | 来源:发表于2023-07-27 10:08 被阅读0次

一、下载 Sentinel

官方下载地址 : https://github.com/alibaba/Sentinel/releases

# 目前最新正式版:v1.8.6
百度网盘链接: https://pan.baidu.com/s/1pNrEZFhgtiuLduoPMy99DA  密码: gr3r

二、启动 Sentinel

## 启动sentinel命令 (默认8080端口,可以通过启动命令更改端口)

# 直接运行
java -jar /usr/local/alibaba/sentinel/sentinel-dashboard-1.8.6.jar --server.port=9090

# 后台运行
nohup java -jar /usr/local/alibaba/sentinel/sentinel-dashboard-1.8.6.jar --server.port=9090 >/usr/local/alibaba/sentinel/log.out 2>&1 &
image.png

三、访问 Sentinel

http://192.168.0.119:9090/#/login
sentinel  /  sentinel

四、Sentinel配置介绍

用户登录的相关配置可以在启动命令中增加下面的参数来进行配置:

-Dserver.port=9090 用于指定 Sentinel 控制台端口为 9090
-Dsentinel.dashboard.auth.username=sentinel : 用于指定控制台的登录用户名为 sentinel;
-Dsentinel.dashboard.auth.password=123456 : 用于指定控制台的登录密码为 123456;如果省略这两个参数,默认用户和密码均为 sentinel
-Dserver.servlet.session.timeout=7200 : 用于指定 Spring Boot 服务端 session 的过期时间,如 7200 表示 7200 秒;60m 表示 60 分钟,默认为 30 分钟;

五、gateway模块的sentinel配置(bootstrap-dev.yml)

image.png
 # 这种配置有可能不显示应用(空白)
    sentinel:
      clientIp: 192.168.0.119
      port: 8719                                        # 默认8719端口,假如被占用会自动从8719开始依次+1扫描,直至找到未被占用的端口
      dashboard: 192.168.0.119:9090                    # [sentinel]管理控制台地址
# 正确
    sentinel:
      transport:
        port: 8719                                     # 默认8719端口,假如被占用会自动从8719开始依次+1扫描,直至找到未被占用的端口
        dashboard: 127.0.0.1:9090                    # [sentinel]管理控制台地址
      eager: true

六、gateway模块的sentinel配置(pom.xml)

<!-- SpringCloud Alibaba Sentinel 流量监控控制台 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        <!-- SpringCloud Alibaba Sentinel 网关限流 -->
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-transport-simple-http</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <!--nacos config client 依赖-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

七、Sentinel控制台

image.png
image.png
在项目搭建完毕,创建完Oauth2.0 安全认证子模块、api子模块创建后进行测试流控、熔断等;
参考:
https://www.jianshu.com/p/36873b6f70a6

相关文章

网友评论

      本文标题:微服务 Spring Cloud Alibaba 项目搭建(六、

      本文链接:https://www.haomeiwen.com/subject/zfikpdtx.html