• SpringCloudAlibaba-Sentinel流量监控


    开发环境

    开发工具:IDEA 2021.3.2

    JDK版本:JDK1.8

    Maven版本:Maven3.8

    SpringCloud版本:Hoxton.SR12

    SpringCloudAlibaba版本:2.2.7.RELEASE

    SpringBoot版本:2.3.12.RELEASE

    Nacos版本:2.0.3

    Sentinel版本:1.8.2

    下载安装Nacos

    根据Nacos官方文档,下载Nacos2.X源码或者压缩包进行安装

    使用Nacos2.0.3下载安装教程下载安装Nacos

    下载安装Sentinel

    根据Sentinel官方文档,下载Sentinel源码或者压缩包(下载速度慢)进行安装

    Sentinel简介

    Sentinel 是面向分布式、多语言异构化服务架构的流量治理组件,主要以流量为切入点,从流量路由、流量控制、流量整形、熔断降级、系统自适应过载保护、热点流量防护等多个维度来帮助开发者保障微服务的稳定性。

    下载安装Sentinel-dashboard

    ①从Gitee克隆Sentinel1.8.2项目代码

    1. # -b 后面是版本号
    2. git clone -b 1.8.2 https://gitee.com/mirrors/Sentinel.git

    ②进入Sentinel\sentinel-dashboard目录下,打包sentinel-dashboard

    1. cd Sentinel\sentinel-dashboard
    2. mvn clean package

    ③进入target目录下,打开cmd输入java -jar sentinel-dashboard.jar 启动sentinel控制台

     ④访问http://localhost:8080/,登录sentinel控制台(默认账号密码都是sentinel)

    搭建Sentinel客户端

    搭建Spring Cloud项目

    以Nacos作为注册中心,搭建spring cloud项目

    创建Sentinel客户端

    ①创建maven模块,命名为cloud-provider-sentinel8021

    ②导入依赖

    1. <dependencies>
    2. <dependency>
    3. <groupId>com.alibaba.cloudgroupId>
    4. <artifactId>spring-cloud-starter-alibaba-sentinelartifactId>
    5. dependency>
    6. <dependency>
    7. <groupId>com.alibaba.cspgroupId>
    8. <artifactId>sentinel-datasource-nacosartifactId>
    9. dependency>
    10. <dependency>
    11. <groupId>com.alibaba.cloudgroupId>
    12. <artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
    13. dependency>
    14. <dependency>
    15. <groupId>org.springframework.bootgroupId>
    16. <artifactId>spring-boot-starter-webartifactId>
    17. dependency>
    18. <dependency>
    19. <groupId>org.springframework.bootgroupId>
    20. <artifactId>spring-boot-starter-actuatorartifactId>
    21. dependency>
    22. dependencies>

    ③创建application.yml配置文件

    1. server:
    2. port: 8021
    3. spring:
    4. application:
    5. name: cloud-provider-sentinel
    6. cloud:
    7. #nacos注册中心配置
    8. nacos:
    9. discovery:
    10. server-addr: 127.0.0.1:8848
    11. #sentinel配置
    12. sentinel:
    13. transport:
    14. port: 8719
    15. dashboard: 127.0.0.1:8080
    16. management:
    17. endpoints:
    18. web:
    19. exposure:
    20. include: "*"

    ④创建启动类

    1. @EnableDiscoveryClient
    2. @SpringBootApplication
    3. public class ProviderSentinel8021 {
    4. public static void main(String[] args) {
    5. SpringApplication.run(ProviderSentinel8021.class, args);
    6. }
    7. }

    ⑤创建controller

    1. @RestController
    2. @RequestMapping("/provider")
    3. public class ProviderController {
    4. @Value("${server.port}")
    5. private String port;
    6. @GetMapping("/getUUID")
    7. public String getUUID() {
    8. return port + "\t:\t" + UUID.randomUUID();
    9. }
    10. }

    测试

    启动Nacos注册中心

    启动Sentinel控制台

    启动cloud-provider-sentinel8021

    测试

    ①浏览器访问http://localhost:8021/provider/getUUID,向后端发送请求

    ②浏览器访问http://localhost:8080/,打开Sentinel客户端并登录

     ③再向后端发送几次请求,观察实时数据

  • 相关阅读:
    vue使用腾讯地图,实现点标记,搜索
    牛客网语法篇练习复合类型(一)
    基于Python和mysql开发的智慧校园答题考试系统(源码+数据库+程序配置说明书+程序使用说明书)
    dockerfile文件详解(常用命令)
    智能优化与机器学习结合算法实现数据分类matlab代码清单
    基于nodejs+vue云旅青城系统
    C++提高编程
    刷爆力扣之有效的山脉数组
    开源OLAP数据库ClickHouse获2.5亿美元B轮融资
    C++类模板的重载
  • 原文地址:https://blog.csdn.net/weixin_46899412/article/details/127715660