Spring 引导管理员显示网关服务器关闭的状态



我开发了一个微服务环境。它是由春天的云发展起来的。

网关服务器由 Zuul 开发,并通过 X.509 证书身份验证(相互身份验证(进行保护。

我使用 Spring 启动管理员来监控微服务。

我已经为我的应用程序使用了Spring Cloud Discovery,并将DiscoveryClient添加到Spring Boot Admin Server:

@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class ApiAdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(ApiAdminServerApplication.class, args);
}
}

Spring 引导管理属性:

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=ALWAYS
spring.security.user.name=admin
spring.security.user.password=password

服务发现属性:

management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
management.metrics.tags.application=${spring.application.name}

网关属性:

server.ssl.enabled=true
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:tls/keyStore.p12
server.ssl.key-store-password=changeit
server.ssl.trust-store=classpath:tls/trustStore.jks
server.ssl.trust-store-password=changeit
server.ssl.trust-store-type=JKS
server.ssl.client-auth=need

网关服务器在 Spring 引导管理面板中显示为应用程序,但其状态为关闭。

如何配置弹簧启动管理员以监视 https 网关应用程序?

Spring Boot Admin 会调用/actuator/health端点以了解应用程序的运行状况。请检查此端点是否正常工作,否则,您可能需要根据需要对其进行配置。 默认情况下,Spring 会检查此处提到的许多运行状况指标:

https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#auto-configured-healthindicators

您也可以配置自己的指标,这是文档中的一个片段:

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class MyHealthIndicator implements HealthIndicator {
@Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
}

我在网关的应用程序属性文件中禁用了SSL身份验证:

management.server.ssl.enabled=false

并忽略网关的 WebSecurityConfigurerAdapter 类中的执行器 url 路径:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.authorizeRequests()
.antMatchers( "/actuator/health/**").permitAll()
.anyRequest().authenticated().and()
.x509()
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(userDetailsService());
}
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/actuator/**");
}

但请注意,此解决方案为所有请求公开网关服务器的重要运行状况信息。

最新更新