- 新建一个admin server工程
- 新建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
- 启动类增加注解:
@EnableDiscoveryClient
@EnableAdminServer
- 其他待监控应用增加pom配置(版本号跟随实际spring boot版本号)
<!-- spring-boot-security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- 访问localhost:port即可,密码为bootstrap.yml内设置的spring security密码
- 如有整合了类似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();
}