Spring Boot Admin Server(Spring Boot Actuator)与Nacos整合配置

  1. 新建一个admin server工程
  2. 新建bootstrap.yml文件(内设置了spring security的密码,需在pom内加入security的pom配置):
server:
  port: #{port}
spring:
  application:
    name: admin-server
  cloud:
    nacos:
      discovery:
        server-addr: #{ip:port}
        namespace: #{namespace}
  boot:
    admin:
      ui:
        title: 应用服务状态监控
  security:
    user:
      name: #{name}
      password: #{pwd}
#开启全部
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
  1. 启动类增加注解:
@EnableDiscoveryClient
@EnableAdminServer
  1. 其他待监控应用增加pom配置(版本号跟随实际spring boot版本号)


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


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


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

  1. 访问localhost:port即可,密码为bootstrap.yml内设置的spring security密码
  2. 如有整合了类似Oauth2.0这类授权服务,需配置Actuator的部分接口路径以跳过鉴权
    类似以下配置:
 @Override
    protected void configure(HttpSecurity http) throws Exception {
        //所有请求必须认证
        http.authorizeRequests()
                .antMatchers("/oauth/**","/webjars/**", "/doc.html", "/swagger-resources/**",
                        "/v2/api-docs/", "/actuator/**", "/instances/**").permitAll()
                .anyRequest().authenticated()
                .and().csrf().disable();
    }

你可能感兴趣的:(Spring,Boot,spring,boot,Actuator,应用监控,Admin,Server,Nacos)