Spring Boot Admin é um projeto de comunidade de código aberto para gerenciar e monitorar aplicativos SpringBoot. O aplicativo atua como um Spring Boot Admin Client para se registrar no Spring Boot Admin Server (via HTTP) ou usar o registro Spring Cloud (como Eureka, Consul).
Este artigo é uma etapa de construção simples sem introduzir seu princípio, o site oficial https://codecentric.github.io/spring-boot-admin/current/
Este artigo coopera com o eureka para monitorar os serviços, portanto, nenhum cliente de administrador é necessário. Basta registrar o servidor do administrador no eureka. O administrador extrairá automaticamente os serviços do eureka para monitoramento e outros serviços podem ser monitorados sem alterações.
Deve-se observar que outros arquivos yml de serviço monitorados também precisam adicionar o seguinte código, caso contrário, a página de monitoramento de serviço exibirá apenas informações de informação padrão:
#Actuator配置:暴露敏感路径,默认情况下,敏感路径并不暴露
management:
endpoints:
web:
exposure:
# 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
1: Crie um novo projeto de agregação maven pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.xxx.xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>admin-server</artifactId>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- admin-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.1.6</version>
</dependency>
<!-- ui 依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- spring security-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- 邮箱配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${artifactId}</warName>
</configuration>
</plugin>
</plugins>
<finalName>${artifactId}</finalName>
</build>
</project>
2: admin yml 配置
server:
port: 8079
spring:
application:
name: server-admin
# mail:
# host: smtp.qq.com
# username: [email protected]
# password: paudschxdxijbcja
# properties:
# mail.debug: false
# mail.smtp.auth: true #安全认证(默认是true)
# mail.smtp.port: 465
# mail.smtp.ssl.enable: true #开启ssl加密 否则项目启动时报530error
# mail.smtp.ssl.socketFactory: sf
# mail.smtp.starttls.enable: true
# mail.smtp.starttls.required: true
boot:
admin:
ui:
title: admin-Server
# notify:
# mail:
# to: [email protected] #收件人邮箱
# from: [email protected] #发件人邮箱
security:
user:
name: "admin"
password: "admin"
#eureka注册中心地址
eureka:
instance:
metadata-map:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
prefer-ip-address: true
client:
service-url:
defaultZone: http://127.0.0.1:8060/eureka/
register-with-eureka: true
fetch-registry: true
#Actuator配置:暴露敏感路径,默认情况下,敏感路径并不暴露
management:
endpoints:
web:
exposure:
# 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
3: classe de entrada, 2 anotações @EnableDiscoveryClient usado com eureka @EnableAdminServer representa o servidor admin
package com.fencer.admin.server;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* 类描述:
*
* @author :carry
* @version: 1.0 CreatedDate in 2019年12月02日
* <p>
* 修订历史: 日期 修订者 修订描述
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableAdminServer
public class SpringbootAdminServerApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(SpringbootAdminServerApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println("######################监控服务启动完成!######################");
}
}
4: Configuração de login de segurança
package com.fencer.admin.server.config;
import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
/**
* 类描述:
*
* @author :carry
* @version: 1.0 CreatedDate in 2019年12月02日
* <p>
* 修订历史: 日期 修订者 修订描述
*/
@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 {
// @formatter:off
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" ).and()
.httpBasic().and()
.csrf().disable();
// @formatter:on
}
}
Depois que a configuração acima for concluída, inicie o projeto, digite localhost: 8079 no navegador para entrar na página de login, digite a senha da conta admin, você pode entrar na página de monitoramento
Clique em um serviço para ver o status do serviço, outras informações como armazém de feijão, interface solicitada, etc., que podem ser explicados pelo Baidu