部署 Sentinel 控制台:实现流量管理和监控

序言

Sentinel 是阿里巴巴开源的一款流量防护与监控平台,它可以帮助开发者有效地管理微服务的流量,实现流量控制、熔断降级、系统负载保护等功能。本文将介绍如何在项目中部署和配置 Sentinel 控制台,实现微服务的流量防护和监控。

一、Sentinel 控制台部署流程

  1. 官网下载 Sentinel 控制台

    image.png

  2. 启动 Sentinel 控制台

    java \
    # 指定 Sentinel 控制台的端口为 8080
    -Dserver.port=8080 \
    # 配置 Sentinel 控制台的地址
    -Dcsp.sentinel.dashboard.server=localhost:8080 \
    # 指定 Sentinel 控制台的项目名称
    -Dproject.name=sentinel-dashboard \
    # 指定启动的 Java 应用程序的 JAR 文件
    -jar sentinel-dashboard.jar
    
  3. 打开浏览器输入网址 localhost:8080 进入 Sentinel 控制台。Sentinel 控制台需要登录,账号和密码默认都是 sentinel

    image.png

二、微服务整合 Sentinel

  1. 引入依赖

    <dependencyManagement>
      <dependencies>
        <!-- spring-cloud-alibaba 依赖版本 -->
        <dependency>
          <groupId>com.alibaba.cloud</groupId>
          <artifactId>spring-cloud-alibaba-dependencies</artifactId>
          <version>2021.0.5.0</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
    
        <!-- spring-boot 依赖版本 -->
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-dependencies</artifactId>
          <version>2.7.15</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
    
    <!-- 引入 sentinel 依赖 -->
    <dependency>
      <groupId>com.alibaba.cloud</groupId> 
      <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    
  2. application.yml 文件中编写 Sentinel 配置

    spring:
      cloud: 
        sentinel:
          transport:
          	# 指定 dashboard
            dashboard: localhost:8080
    
  3. 访问微服务接口

    # 使用 curl 命令访问自定义 user-service 服务的 /test/helo 接口
    curl localhost:1920/test/helo
    

    多次访问之后的效果:

    image.png

三、流量监控和管理

3.1 流量监控

在这里插入图片描述

在 Sentinel 控制台的实时监控页面,同一个服务下的所有机器的簇点信息会被汇总,并且秒级地展示在 “实时监控” 页面。默认情况下,实时监控仅存储 5 分钟以内的数据,如果需要持久化,需要通过调用实时监控接口来定制。

3.2 流量管理

在这里插入图片描述

Sentinel 控制台提供简单的规则管理以及推送的功能。开发人员可以根据具体的业务需求添加相应的规则实现流量的管理(其中流量管理包括流量控制、熔断降级、热点参数限流、来源访问控制等)。

四、FAQ

  1. Sentinel 控制台所在的机器时间需要与应用的机器时间保持一致,否则会导致拉不到实时的监控数据。

  2. Sentinel 控制台定义的规则仅保存在内存中,控制台重启之后,规则将会丢失。

  3. 在使用 Sentinel 时,注意 spring-bootspring-cloud-alibaba 的版本兼容关系。版本兼容关系,可参考下图或官网

    image.png

推荐阅读

  1. Docker Compose:简化多容器应用部署
  2. cURL:命令行下的网络工具
  3. RabbitMQ(Docker 单机部署)
  4. 深入理解 Java 并发:AbstractQueuedSynchronizer 源码分析
  5. 深入了解 Arthas:Java 应用程序诊断利器

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-05-11 12:26:06       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-11 12:26:06       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-11 12:26:06       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-11 12:26:06       20 阅读

热门阅读

  1. “现行价格”、“不变价格”与“可比价格”

    2024-05-11 12:26:06       11 阅读
  2. react Hooks怎么用

    2024-05-11 12:26:06       9 阅读
  3. ArcGIS Maps :在Vue3中加载ArcGIS地图

    2024-05-11 12:26:06       11 阅读
  4. k8s拉起一个pod底层是如何运行的

    2024-05-11 12:26:06       10 阅读
  5. cpp笔记-24-05-10

    2024-05-11 12:26:06       10 阅读
  6. Linux -- Git

    2024-05-11 12:26:06       10 阅读
  7. SSH:安全远程访问的基石

    2024-05-11 12:26:06       9 阅读
  8. 哪些设计模式,你使用过哪些设计模式

    2024-05-11 12:26:06       9 阅读
  9. 【数据库】数据库事务原理

    2024-05-11 12:26:06       9 阅读
  10. linux内核网络源码 链上通知事件

    2024-05-11 12:26:06       9 阅读