Spring Boot Admin服务监控

Spring Boot Admin

1.Spring Boot Admin是什么?

它是用于监控springboot应用程序的监控系统,应用程序通过Apring Boot Admin Client进行注册(通过HTTP的方式),或者使用springcloud来发现(比如:eureka),UI只是在Spring Boot Actuator端点上的一个AngularJs应用程序

这里写图片描述


2、开始

2.1、设置spring Boot Admin Server

1.pom.xml

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server</artifactId>
    <version>1.5.4</version>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server-ui</artifactId>
    <version>1.5.4</version>
</dependency>

2.通过在配置中添加@enableadminserver,来导入Spring Boot Admin Server配置:

@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}
2.2、注册客户端应用程序
2.2.1、spring-boot-admin-starter-client

想要注册的每个应用程序都必须包含Spring Boot Admin Client。
1.在依赖项添加spring-boo-admin-starclient-client:
pom.xml

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>1.5.4</version>
</dependency>

2.通过配置Spring Boot Admin Server URL来启用SBA客户端
application.yml | application.properties

spring.boot.admin.url: http://localhost:8080  
management.security.enabled: false 

Spring Boot Admin Server的URL
所有端点在缺省情况下都是安全的。为了简便起见,禁用安全性


3.安全

1.spring-boot-admin-server-ui-login和spring-boot-starter-security添加到依赖项中

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server-ui-login</artifactId>
    <version>1.5.2</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

2.Spring的安全配置可能如下:

## Securing Spring Boot Admin Server
 @Configuration
  public static class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
      // Page with login form is served as /login.html and does a POST on /login
      http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();
      // The UI does a POST on /logout on logout
      http.logout().logoutUrl("/logout");
      // The ui currently doesn't support csrf
      http.csrf().disable();

      // Requests for the login page and the static assets are allowed
      http.authorizeRequests()
          .antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**")
          .permitAll();
      // ... and any other request needs to be authorized
      http.authorizeRequests().antMatchers("/**").authenticated();

      // Enable so that the clients can authenticate via HTTP basic for registering
      http.httpBasic();
    }
  }

3.当actuator endpoints使用HTTP基本身份验证时,SBA服务器需要凭证来访问它们,在注册应用程序时,可以在元数据中提交凭据,BasicAuthHttpHeaderProvider使用该元数据添加授权头来访问应用程序的actuator endpoints,可以提供自己的httpheadprovider来改变行为(例如添加一些解密)或添加额外的头。

## Securing Client Actuator Endpoints
spring.boot.admin.client.metadata.user.name=${security.user.name}
spring.boot.admin.client.metadata.user.password=${security.user.password}
spring.boot.admin.url=http://localhost:9090/dlc-admin

DEMO:Spring-Boot-admin-example


4.发送邮件配置

1.配置一个JavaMailSender,使用spring-startmail-mail,并设置一个接收方。
pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

application.properties

spring.mail.host=smtp.example.com
spring.boot.admin.notify.mail.to=admin@example.com
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值