1-2)资源配置文件引入配置de.codecentric spring-boot-admin-starter-server ${spring.admin.version} org.springframework.boot spring-boot-starter-security 2.5.2 org.springframework.boot spring-boot-starter-mail
#代表打开所有的监控点
management:
endpoints:
web:
exposure:
include: "*"
# 代表启用单独的url地址来监控 Spring Boot 应用,
base-path: /
endpoint:
health:
show-details: always
#程序名称
spring:
main:#配置是否开启权限认证标识
allow-circular-references: true
cloud:
compatibility-verifier:
enabled: false
#配置自定义web页面banner
boot:
admin:
ui:
title: 服务监控系统
brand: >服务监控系统
cache:
no-cache: true
no-store: true
mail: #配置发送邮件邮箱
host: smtp.163.com
username: xxxx@163.com
password: xxxxx
1-3)spring boot服务后台代码
1-3-1 主程序启动配置
@SpringBootApplication
@EnableAdminServer
//过滤掉数据库加载
@EnableAutoConfiguration(exclude ={DataSourceAutoConfiguration.class})
public class MonitorApplication{
public static void main(String[] args) {
SpringApplication.run(MonitorApplication.class,args);
}
}
1-3-2 启用安全检查配置
@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 {
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();
}
}
2、springboot admin 客户端
2-1 pom引入配置如下
2-2 ymal配置文件设置de.codecentric spring-boot-admin-starter-client ${spring.admin.version}
#客户端访问服务端地址,用户名密码配置
spring:
boot:
admin:
client:
url: http://localhost:8099
username: admin
password: ****
#监控客户端程序的访问路径配置
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
logfile: #客户端文件输出配置
external-file: ./server-log/output.log
2-3 输出日志文件配置
${APP_Name} ${CONSOLE_LOG_PATTERN} utf8 ${LOG_HOME}/output.log ${LOG_HOME}/server-%d{yyyy-MM-dd}.log 30 %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n ${CONSOLE_LOG_PATTERN} utf8



