Spring Boot Admin(SBA)

        Spring Boot Admin(SBA)是一个针对Spring Boot的Actuator接口进行UI美化封装的监控工具。他可以返回在列表中浏览所有被监控Spring Boot项目的基本信息比如:Spring容器管理的所有的bean、详细的Health信息、内存信息、JVM信息、垃圾回收信息、各种配置信息(比如数据源、缓存列表和命中率)等,Threads 线程管理,Environment 管理等。

        Spring Boot Admin在对单一服务监控的同时也提供了集群监控方案,支持通过eureka、nacos、zookeeper等注册中心的方式实现多服务监控与管理。

         Spring Boot Admin 是由Client端和Server端组成,在 Spring Boot 项目中,Spring Boot Admin 作为 Server 端,其他的要被监控的应用作为 Client 端,基于这种的配置如下步骤:

一、Spring Boot Admin Server服务端

1)pom



    4.0.0
    com.king
    admin-server
    0.0.1-SNAPSHOT
    admin-server
    Demo project for Spring Boot

    
        1.8
        UTF-8
        UTF-8
        2.3.7.RELEASE
    

    
        
            org.springframework.boot
            spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            de.codecentric
            spring-boot-admin-starter-server
            2.2.2
        
        
            org.springframework.boot
            spring-boot-starter-security
            2.3.7.RELEASE
        
    

    
        
            
                org.springframework.boot
                spring-boot-dependencies
                ${spring-boot.version}
                pom
                import
            
        
    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.8.1
                
                    1.8
                    1.8
                    UTF-8
                
            
            
                org.springframework.boot
                spring-boot-maven-plugin
                2.3.7.RELEASE
                
                    com.king.adminserver.AdminServerApplication
                
                
                    
                        repackage
                        
                            repackage
                        
                    
                
            
        
    


2)application.yml

spring:
  application:
    name:
      admin-server
  security:
    user:
      name: admin
      password: admin
server:
    port: 9090

3)config

@Configuration
public class SercuityConfig extends WebSecurityConfigurerAdapter {

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

        http.authorizeRequests()
                .antMatchers("/assets/**").permitAll()
                .antMatchers("/login").permitAll()
                .anyRequest().authenticated().and()
                .formLogin().loginPage("/login")
                .successHandler(successHandler).and()
                .logout().logoutUrl("/logout").and()
                .httpBasic().and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(
                        "/instances",
                        "/actuator/**"
                );
    }
}

4)添加@EnableAdminServer

@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {

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

}

二、Spring Boot Admin Client客户端

1)pom


    de.codecentric
    spring-boot-admin-starter-client
    2.2.2


    org.springframework.boot
    spring-boot-starter-security
    2.3.7.RELEASE

2)application.yml

spring:
  boot:
    admin:
      client:
        url: http://localhost:9090
        username: admin
        password: admin

三、服务端启动,客户端注册成功

通过 http//loacalhost:9090访问,出现以下内容说明服务端已启动,且客户端已注册成功。

Spring Boot Admin(SBA)_第1张图片

Spring Boot Admin(SBA)_第2张图片

你可能感兴趣的:(spring,boot,java,后端)