Spring Cloud Admin 实战

Spring Cloud Admin

简介

Spring Boot Admin 用于监控基于 Spring Boot 的应用,它是在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI。Spring Boot Admin 提供了很多功能,如显示 name、id 和 version,显示在线状态,Loggers 的日志级别管理,Threads 线程管理,Environment 管理等。

基于Cairo-SR3 和 Finchley.SR1

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

  • admin-server
@EnableAdminServer
@EnableEurekaClient
@SpringBootApplication
public class AdminServerApplication {

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

}

application.yml:

server:
  port: 5000
spring:
  application:
    name: admin-server
eureka:
  client:
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/

pom:


        
            
                io.spring.platform
                platform-bom
                Cairo-SR3
                pom
                import
            
            
                org.springframework.cloud
                spring-cloud-dependencies
                Finchley.SR1
                pom
                import
            
        
    

    

        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

        
            de.codecentric
            spring-boot-admin-starter-server
            2.0.1
        

    


    
        

            
                org.springframework.boot
                spring-boot-maven-plugin
            

            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                    UTF-8
                
            
        
    

  • admin-clent
@EnableDiscoveryClient
@SpringBootApplication
public class AdminClientApplication {

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

}

application.yml

server:
  port: 8762

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: admin-client

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

pom:


        
            
                io.spring.platform
                platform-bom
                Cairo-SR3
                pom
                import
            
            
                org.springframework.cloud
                spring-cloud-dependencies
                Finchley.SR1
                pom
                import
            
        
    

    

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

        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

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

        
            org.springframework.boot
            spring-boot-starter-actuator
        

    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                    UTF-8
                
            
        
    
  • eureka
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {

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

    @EnableWebSecurity
    static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable();
        }
    }

}

application.yml

server:
  port: 8761
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka

pom:

    
        
            
                io.spring.platform
                platform-bom
                Cairo-SR3
                pom
                import
            
            
                org.springframework.cloud
                spring-cloud-dependencies
                Finchley.SR1
                pom
                import
            
        
    

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        
        
            org.springframework.boot
            spring-boot-starter-security
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
    

先启动eureka然后接着启动admin-client 和 admin-server 在浏览器打开urlSpring Cloud Admin 实战_第1张图片
Spring Cloud Admin 实战_第2张图片
Spring Cloud Admin 实战_第3张图片
Spring Cloud Admin 实战_第4张图片
github:https://github.com/janlle

你可能感兴趣的:(javaee,Spring,微服务,SpringBoot2.x,SpringCloud)