<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
複製代碼
@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 出現登陸界面表示成功 前端
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
複製代碼
application.properties配置文件git
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
複製代碼
啓動後:監控的服務端就會收到通知 刷新頁面就能夠看到監控的服務 github
項目地址:gitee.com/qinxuewu/Sp…web
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
複製代碼