<dependency>
<groupId>de.codecentricgroupId>
<artifactId>spring-boot-admin-starter-serverartifactId>
<version>${spring.admin.version}version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-securityartifactId>
<version>2.5.2version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-mailartifactId>
dependency>
1-2)资源配置文件引入配置
#代表打开所有的监控点
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引入配置如下
<dependency>
<groupId>de.codecentricgroupId>
<artifactId>spring-boot-admin-starter-clientartifactId>
<version>${spring.admin.version}version>
dependency>
2-2 ymal配置文件设置
#客户端访问服务端地址,用户名密码配置
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 输出日志文件配置
<configuration>
<property name="APP_Name" value="model-server" />
<contextName>${APP_Name}contextName>
<property name="LOG_HOME" value="./${APP_Name}-log" />
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(LN:%L){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}pattern>
<charset>utf8charset>
encoder>
appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/output.logfile>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/server-%d{yyyy-MM-dd}.logFileNamePattern>
<MaxHistory>30MaxHistory>
rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%npattern>
<pattern>${CONSOLE_LOG_PATTERN}pattern>
<charset>utf8charset>
encoder>
appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
root>
<root level="ERROR">
<appender-ref ref="FILE" />
root>
configuration>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)