de.codecentric
spring-boot-admin-starter-server
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-web
de.codecentric
spring-boot-admin-server-ui
org.springframework.boot
spring-boot-starter-security
@SpringBootApplication
@EnableAdminServer
public class SpringbootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootAdminApplication.class, args);
}
}
@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 {
// @formatter:off
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
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()
//启用HTTP-Basic支持。这是Spring Boot Admin Client注册所必需的
.httpBasic().and()
.csrf()
//使用Cookie启用CSRF保护
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers(
adminContextPath + "/instances", //禁用CRSF-Protection Spring Boot Admin Client用于注册的端点。
adminContextPath + "/actuator/**" //
);
// @formatter:on
}
}
server.port=8088
server.tomcat.uri-encoding=UTF-8
server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30
#账户密码
spring.security.user.name=gzpflm
spring.security.user.password=gzpflm
#项目访问名
spring.boot.admin.context-path=/szq-monitoring
#UI界面标题
spring.boot.admin.ui.title=szq-Monitpring
启动运行:http://localhost:8088/szq-monitoring/login 出现登录界面表示成功
de.codecentric
spring-boot-admin-starter-client
application.properties配置文件
server.port=8081
spring.application.name=Spring Boot Client
spring.boot.admin.client.url=http://localhost:8088/szq-monitoring
management.endpoints.web.exposure.include=*
spring.boot.admin.client.username=gzpflm
spring.boot.admin.client.password=gzpflm
spring.boot.admin.client.enabled=true
#启用ip显示
spring.boot.admin.client.instance.prefer-ip=true
启动后:监控的服务端就会收到通知 刷新页面就可以看到监控的服务
项目地址:https://gitee.com/qinxuewu/SpringBoot--Admin-demo
spring.boot.admin.client.enabled #启用Spring Boot Admin Client,默认值true
spring.boot.admin.client.url #逗号分隔Spring Boot Admin服务器的有序URL列表以进行注册
spring.boot.admin.client.api-path #管理服务器上的注册端点的Http路径 默认值"instances"
#SBA Server api受HTTP基本身份验证保护时的用户名和密码。
spring.boot.admin.client.username
spring.boot.admin.client.password
spring.boot.admin.client.period #重复注册的间隔(以ms为单位)默认自10,000
spring.boot.admin.client.connect-timeout #连接超时进行注册(以ms为单位 #默认5,000
http://codecentric.github.io/spring-boot-admin/current/#register-clients-via-spring-boot-admin