Spring Cloud入门-Admin服务监控中心(Hoxton版本)

项目使用的Spring Cloud为Hoxton版本,Spring Boot为2.2.2.RELEASE版本

Spring Cloud入门系列汇总

序号内容链接地址
1Spring Cloud入门-十分钟了解Spring Cloudhttps://blog.csdn.net/ThinkWon/article/details/103715146
2Spring Cloud入门-Eureka服务注册与发现(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103726655
3Spring Cloud入门-Ribbon服务消费者(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103729080
4Spring Cloud入门-Hystrix断路器(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103732497
5Spring Cloud入门-Hystrix Dashboard与Turbine断路器监控(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103734664
6Spring Cloud入门-OpenFeign服务消费者(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103735751
7Spring Cloud入门-Zuul服务网关(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103738851
8Spring Cloud入门-Config分布式配置中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103739628
9Spring Cloud入门-Bus消息总线(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103753372
10Spring Cloud入门-Sleuth服务链路跟踪(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103753896
11Spring Cloud入门-Consul服务注册发现与配置中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103756139
12Spring Cloud入门-Gateway服务网关(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103757927
13Spring Cloud入门-Admin服务监控中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103758697
14Spring Cloud入门-Oauth2授权的使用(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103761687
15Spring Cloud入门-Oauth2授权之JWT集成(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103763364
16Spring Cloud入门-Oauth2授权之基于JWT完成单点登录(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103766368
17Spring Cloud入门-Nacos实现注册和配置中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103769680
18Spring Cloud入门-Sentinel实现服务限流、熔断与降级(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103770879
19Spring Cloud入门-Seata处理分布式事务问题(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103786102
20Spring Cloud入门-汇总篇(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103786588

摘要

Spring Boot Admin 可以对SpringBoot应用的各项指标进行监控,可以作为微服务架构中的监控中心来使用,本文将对其用法进行详细介绍。

Spring Boot Admin 简介

SpringBoot应用可以通过Actuator来暴露应用运行过程中的各项指标,Spring Boot Admin通过这些指标来监控SpringBoot应用,然后通过图形化界面呈现出来。Spring Boot Admin不仅可以监控单体应用,还可以和Spring Cloud的注册中心相结合来监控微服务应用。

Spring Boot Admin 可以提供应用的以下监控信息:

  • 监控应用运行过程中的概览信息;
  • 度量指标信息,比如JVM、Tomcat及进程信息;
  • 环境变量信息,比如系统属性、系统环境变量以及应用配置信息;
  • 查看所有创建的Bean信息;
  • 查看应用中的所有配置信息;
  • 查看应用运行日志信息;
  • 查看JVM信息;
  • 查看可以访问的Web端点;
  • 查看HTTP跟踪信息。

创建admin-server模块

这里我们创建一个admin-server模块来作为监控中心演示其功能。

在pom.xml中添加相关依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>

在application.yml中进行配置:

server:
  port: 9301

spring:
  application:
    name: admin-server

在启动类上添加@EnableAdminServer来启用admin-server功能:

@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdminServerApplication.class, args);
    }

}

创建admin-client模块

这里我们创建一个admin-client模块作为客户端注册到admin-server。

在pom.xml中添加相关依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>

在application.yml中进行配置:

server:
  port: 9305

spring:
  application:
    name: admin-client
  boot:
    admin:
      client:
        # 配置admin-server地址
        url: http://localhost:9301

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

# 添加开启admin的日志监控
logging:
  file: admin-client.log

启动admin-server和admin-client服务。

监控信息演示

访问如下地址打开Spring Boot Admin的主页:http://localhost:9301

在这里插入图片描述

点击wallboard按钮,选择admin-client查看监控信息;

监控信息概览;

在这里插入图片描述

度量指标信息,比如JVM、Tomcat及进程信息;

在这里插入图片描述

环境变量信息,比如系统属性、系统环境变量以及应用配置信息;

在这里插入图片描述

查看所有创建的Bean信息;

在这里插入图片描述

查看应用中的所有配置信息;

在这里插入图片描述

查看日志信息,admin-client模块的applicaiton.yml需要添加以下配置才能开启;

logging:
  #添加开启admin的日志监控
  file: admin-client.log 

在这里插入图片描述

查看JVM信息;

在这里插入图片描述

查看可以访问的Web端点;

在这里插入图片描述

结合注册中心使用

Spring Boot Admin结合Spring Cloud 注册中心使用,只需将admin-server和注册中心整合即可,admin-server 会自动从注册中心获取服务列表,然后挨个获取监控信息。这里以Eureka注册中心为例来介绍下该功能。

修改admin-server

在pom.xml中添加相关依赖:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

在application-eureka.yml中进行配置,只需添加注册中心配置即可:

server:
  port: 9301

spring:
  application:
    name: admin-server

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka/

在启动类上添加@EnableDiscoveryClient来启用服务注册功能:

@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdminServerApplication.class, args);
    }

}

修改admin-client

在pom.xml中添加相关依赖:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

在application-eureka.yml中进行配置,删除原来的admin-server地址配置,添加注册中心配置即可:

server:
  port: 9305

spring:
  application:
    name: admin-client
  boot:
    admin:
      client:
        # 配置admin-server地址
        url: http://localhost:9301

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka/

# 添加开启admin的日志监控
logging:
  file: admin-client.log

在启动类上添加@EnableDiscoveryClient来启用服务注册功能:

@EnableDiscoveryClient
@SpringBootApplication
public class AdminClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdminClientApplication.class, args);
    }

}

功能演示

启动eureka-server,使用application-eureka.yml配置启动admin-server,admin-client;

查看注册中心发现服务均已注册:http://localhost:8001/

在这里插入图片描述

查看Spring Boot Admin 主页发现可以看到服务信息:http://localhost:9301

在这里插入图片描述

添加登录认证

我们可以通过给admin-server添加Spring Security支持来获得登录认证功能。

创建admin-security-server模块

在pom.xml中添加相关依赖:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

在application.yml中进行配置,配置登录用户名和密码,忽略admin-security-server的监控信息:

server:
  port: 9301

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka/

spring:
  application:
    name: admin-security-server
  security:
    user:
      # 配置登录用户名和密码
      name: root
      password: 123456
  boot:
    admin:
      discovery:
        # 不显示admin-security-server的监控信息
        ignored-services: ${spring.application.name}

对SpringSecurity进行配置,以便admin-client可以注册:

@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {

    private final String adminContextPath;

    public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
                //1.配置所有静态资源和登录页可以公开访问
                .antMatchers(adminContextPath + "/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitAll()
                .anyRequest().authenticated()
                .and()
                //2.配置登录和登出路径
                .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
                .logout().logoutUrl(adminContextPath + "/logout").and()
                //3.开启http basic支持,admin-client注册时需要使用
                .httpBasic().and()
                .csrf()
                //4.开启基于cookie的csrf保护
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                //5.忽略这些路径的csrf保护以便admin-client注册
                .ignoringAntMatchers(
                        adminContextPath + "/instances",
                        adminContextPath + "/actuator/**"
                );
    }

}

修改启动类,开启AdminServer及注册发现功能:

@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class AdminSecurityServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdminSecurityServerApplication.class, args);
    }

}

启动eureka-server,admin-security-server,访问Spring Boot Admin 主页发现需要登录才能访问:http://localhost:9301

在这里插入图片描述

使用到的模块

springcloud-learning
├── eureka-server -- eureka注册中心
├── admin-server -- admin监控中心服务
├── admin-client -- admin监控中心监控的应用服务
└── admin-security-server -- 带登录认证的admin监控中心服务

项目源码地址

GitHub项目源码地址

<think>好的,我现在需要回答用户关于Spring Boot 3.1.15与Spring CloudSpring AdminSpring Cloud Alibaba以及Dubbo的兼容性和版本对应关系的问题。首先,我需要回忆这些框架之间的版本兼容性通常是如何确定的。一般来说,Spring Cloud会有一个对应的Spring Boot版本范围,而Spring Cloud Alibaba和Dubbo又依赖于特定的Spring Cloud版本Spring Admin可能也有其对应的Spring Boot版本要求。 首先,Spring Boot 3.1.x版本属于较新的版本,特别是3.1.15可能是一个维护版本Spring Cloud版本通常遵循命名规则,比如2022.0.x对应Spring Boot 3.0.x和3.1.x。用户提到的Spring Boot 3.1.15,我需要确认对应的Spring Cloud版本是否为2022.0.x系列,例如2022.0.4或更高。然后,Spring Cloud Alibaba的版本通常会与Spring Cloud版本绑定,比如2022.0.0.0对应Spring Cloud 2022.0.x。Dubbo方面,可能需要查看Spring Cloud Alibaba的文档,确定支持的Dubbo版本,例如Dubbo 3.x。 接下来是Spring Admin,即Spring Boot Admin,其版本需要与Spring Boot 3.1.x兼容。Spring Boot Admin 3.x版本通常适配Spring Boot 3.x,所以可能对应的版本是3.1.x。需要注意具体的小版本是否支持3.1.15,可能需要查看官方文档或GitHub发布说明。 但可能存在一些不确定的地方,比如具体的Spring Cloud Alibaba版本是否已经支持Spring Boot 3.1.15,或者Dubbo是否有已知的兼容性问题。此外,Spring Cloud版本号有时会有不同的命名规则,比如之前的Hoxton、2020.0.x等,现在可能采用日历版本,需要确认最新的对应关系。 用户提供的引用中提到了Spring Webflux的相关内容,但可能与当前问题关联不大,不过需要留意是否有版本间的依赖冲突,比如Webflux在Spring Boot 3.1中的使用是否影响其他组件。另外,用户提到引用的来源可能不完整,比如引用[2]提到后续内容未完成,所以可能需要依赖其他资料。 总结步骤: 1. 确定Spring Boot 3.1.15对应的Spring Cloud版本。 2. 根据Spring Cloud版本找到对应的Spring Cloud Alibaba版本。 3. 确定该Spring Cloud Alibaba版本支持的Dubbo版本。 4. 确认Spring Boot AdminSpring Boot 3.1.15的兼容性。 5. 检查是否有官方文档或社区确认的兼容性信息,或已知问题。 可能的挑战是,部分组件的文档可能没有明确说明对Spring Boot 3.1.15的支持情况,尤其是维护版本。可能需要查阅官方发布的版本说明或GitHub仓库的issue部分,寻找相关的兼容性信息。此外,Dubbo与Spring Cloud Alibaba的集成版本也需要具体对应,例如Dubbo 3.2.x可能与Spring Cloud Alibaba 2022.0.x兼容。 最后,整理这些信息,按顺序回答用户的问题,确保每个组件的对应版本准确,并建议用户参考官方文档进行验证。</think>关于Spring Boot 3.1.15与其他框架的兼容性,以下是详细的版本对应关系及建议: --- ### **1. Spring Boot 3.1.15 与 Spring Cloud 的兼容性** - **Spring Cloud 版本**:Spring Boot 3.1.x 对应 **Spring Cloud 2022.0.x** 系列(也称为 "Kilburn" 版本)。例如,Spring Cloud 2022.0.4 是推荐的选择[^1]。 - **依赖配置示例**: ```xml <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>2022.0.4</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` --- ### **2. Spring Boot Admin 的兼容性** - **Spring Boot Admin 版本**:Spring Boot 3.x 需要 **Spring Boot Admin 3.1.x** 及以上版本。例如: ```xml <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>3.1.7</version> </dependency> ``` - **注意**:需确保Spring Security等依赖版本Spring Boot 3.1.15一致。 --- ### **3. Spring Cloud Alibaba 的兼容性** - **Spring Cloud Alibaba 版本**:与Spring Cloud 2022.0.x兼容的版本是 **2022.0.0.0**(推荐使用最新子版本,如2022.0.0.0-RC2)。 - **依赖配置示例**: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2022.0.0.0-RC2</version> <type>pom</type> <scope>import</scope> </dependency> ``` --- ### **4. Dubbo 的兼容性** - **Dubbo 版本**:Spring Cloud Alibaba 2022.0.0.0 默认集成 **Dubbo 3.2.x**。需添加以下依赖: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-dubbo</artifactId> </dependency> ``` - **注意**:Dubbo 3.x 需要JDK 17+,与Spring Boot 3.x的要求一致。 --- ### **5. 版本兼容性验证建议** 1. **检查官方文档**: - Spring CloudSpring Boot 的对应关系:[Spring Cloud官方文档](https://spring.io/projects/spring-cloud) - Spring Cloud Alibaba 版本说明:[GitHub Wiki](https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E) 2. **测试关键功能**:如服务注册、配置中心、Dubbo RPC调用等。 3. **依赖冲突排查**:使用`mvn dependency:tree`检查版本冲突,尤其是Netty、gRPC等依赖。 --- ### **版本对应关系总结表** | 框架 | 推荐版本 | 官方文档链接 | |---------------------|------------------------|----------------------------------------------------------------------------| | Spring Boot | 3.1.15 | [Spring Boot](https://spring.io/projects/spring-boot) | | Spring Cloud | 2022.0.4 | [Spring Cloud](https://spring.io/projects/spring-cloud) | | Spring Boot Admin | 3.1.7 | [Spring Boot Admin](https://github.com/codecentric/spring-boot-admin) | | Spring Cloud Alibaba| 2022.0.0.0-RC2 | [Spring Cloud Alibaba](https://spring.io/projects/spring-cloud-alibaba) | | Dubbo | 3.2.7 | [Dubbo](https://dubbo.apache.org/) | ---
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值