spring boot admin监控管理的使用

近期通过spring boot集成了redis、rabbitMQ及websocket服务,并对外提供相应的技术服务,整合完成之后,需要对这几个服务进行spring boot应用运行健康状况监控。之前了解过spring boot admin,但是没有系统的学习使用过,借着本次实践,记录下spring boot admin的配置及使用过程。

  1. 概述
    Spring Boot Admin是一个Web应用,用于管理和监视Spring Boot应用程序的运行状态。每个Spring Boot应用程序都被视为客户端并注册到管理服务器。背后的数据采集是由Spring Boot Actuator端点提供。

  2. 设置管理服务器

  • 国际惯例,添加依赖
<dependency>
   <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

添加spring boot admin的server及mail依赖,mail用于进行监控邮件告警,spring security用于对spring boot admin的管理后台系统进行用户名密码验证,如果仅仅是spring boot admin的话,只需要spring-boot-admin-starter-server依赖即可

  • application.yml(properties)配置信息
    在这里插入图片描述
    首先设置spring boot admin的用户名与密码,然后设置监控邮箱,其次为服务端口配置。

  • 启动类修改

@EnableAdminServer
@SpringBootApplication
@ComponentScan(basePackages = {"com.ews.framework.*"})
@EnableSwagger2
public class EwsManagerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EwsManagerApplication.class, args);
        System.out.println("******************启动成功*****************");
    }
}


  • 安全配置
@Configuration
public class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
    private final String adminContextPath;

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

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        //静态资源和登录页面可以不用认证
        http.authorizeRequests().antMatchers(adminContextPath + "/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitAll()
                //其他请求必须认证
                .anyRequest().authenticated()
                //自定义登录和退出
                .and().formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and().logout()
                .logoutUrl(adminContextPath + "/logout")
                //启用HTTP-Basic, 用于Spring Boot Admin Client注册
                .and().httpBasic().and().csrf().disable();
    }
}

此时,服务器已准备好启动并可以注册客户端应用程序。

  1. 客户端配置
  • 国际惯例
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
  • application.yml(properties)配置
    在这里插入图片描述
    在这里插入图片描述
    首先设置spring boot admin管理服务器的url、用户名及密码。定义自身元数据用户名密码。设置暴漏所有监控点。
  • 安全配置
@Slf4j
@Configuration
public class SpringSecurityActuatorConfig extends WebSecurityConfigurerAdapter {
    public SpringSecurityActuatorConfig() {
        log.info("SpringSecurityActuatorConfig... start");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //actuator请求
        http.antMatcher("/actuator/**")
                .authorizeRequests().anyRequest().authenticated()
                //启用httpBasic认证
                .and().httpBasic()
                //禁用csrf
                .and().csrf().disable();
    }
}
  1. 启动管理服务及客户端
    在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  1. 告警邮件
    先后运行管理服务器与客户端后,停掉客户端服务后会受到告警邮件:
    在这里插入图片描述

  2. 以上,整理完毕。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰红茶不会渴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值