您好,登錄后才能下訂單哦!
前言
Spring Boot Admin是一個(gè)Web應(yīng)用,用于管理和監(jiān)視Spring Boot應(yīng)用程序的運(yùn)行狀態(tài)。每個(gè)Spring Boot應(yīng)用程序都被視為客戶端并注冊(cè)到管理服務(wù)器。背后的數(shù)據(jù)采集是由Spring Boot Actuator端點(diǎn)提供。
集成
注意一定要版本對(duì)應(yīng),否則會(huì)出現(xiàn)意想不到的問(wèn)題,建議使用Srping Boot Admin 2.0+以上版本,可以多語(yǔ)言切換。
父項(xiàng)目
pom.xml引入:
<modules> <module>admin-server</module> <module>admin-client</module></modules><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.2.RELEASE</version> <relativePath/></parent><dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency></dependencies>
監(jiān)控服務(wù)端
pom.xml引入:
<artifactId>admin-server</artifactId><dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.2.1</version> </dependency> <!--登錄認(rèn)證--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!--掉線發(fā)送郵件通知--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency></dependencies>
application.properties配置文件:
https://blog.52itstyle.vipserver.port=9000spring.application.name=SpringBootAdminspring.security.user.name=adminspring.security.user.password=adminspring.boot.admin.monitor.status-interval = 10000spring.boot.admin.monitor.info-interval = 10000spring.mail.host = smtp.163.comspring.mail.username = 13188888888@163.comspring.mail.password = 2020spring.boot.admin.notify.mail.from = 13188888888@163.comspring.boot.admin.notify.mail.to = 88888888@qq.com
啟動(dòng)類(lèi):
/** * 系統(tǒng)監(jiān)控 * 爪哇筆記:https://blog.52itstyle.vip */@Configuration@EnableAutoConfiguration@EnableAdminServerpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Configuration public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter { private final AdminServerProperties adminServer; public SecuritySecureConfig(AdminServerProperties adminServer) { this.adminServer = adminServer; } @Override protected void configure(HttpSecurity http) throws Exception { SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter("redirectTo"); successHandler.setDefaultTargetUrl(this.adminServer.path("/")); http.authorizeRequests() .antMatchers(this.adminServer.path("/assets/**")).permitAll() .antMatchers(this.adminServer.path("/login")).permitAll() .anyRequest().authenticated() .and() .formLogin().loginPage(this.adminServer.path("/login")).successHandler(successHandler).and() .logout().logoutUrl(this.adminServer.path("/logout")).and() .httpBasic().and() .csrf() .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .ignoringRequestMatchers( new AntPathRequestMatcher(this.adminServer.path("/instances"), HttpMethod.POST.toString()), new AntPathRequestMatcher(this.adminServer.path("/instances/*"), HttpMethod.DELETE.toString()), new AntPathRequestMatcher(this.adminServer.path("/actuator/**")) ) .and() .rememberMe().key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600); } }}
監(jiān)控客戶端
pom.xml引入:
<artifactId>admin-client</artifactId><dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.2.1</version> </dependency></dependencies>
application.properties配置文件:
https://blog.52itstyle.vipspring.boot.admin.client.instance.name = 007spring.boot.admin.client.url= http://localhost:9000management.endpoints.web.exposure.include=*spring.boot.admin.client.username = adminspring.boot.admin.client.password = adminspring.boot.admin.client.period = 10000spring.boot.admin.client.connect-timeout = 5000spring.boot.admin.client.read-timeout = 5000spring.boot.admin.client.instance.service-url = http://localhost:8080
監(jiān)控界面
不得不說(shuō),2.X 版本還是很美觀大氣上檔次的,并且監(jiān)控告警功能齊全,
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。