springboot admin圖文+視訊教程
1.背景
大綱
Spring Boot Admin 是一個管理和監控Spring Boot 應用程式的開源軟體。每個應用都認為是一個客戶端,通過HTTP或者使用 Eureka註冊到admin server中進行展示,Spring Boot Admin UI部分使用AngularJs將資料展示在前端。
Spring Boot Admin 是一個針對spring-boot的actuator介面進行UI美化封裝的監控工具。他可以:在列表中瀏覽所有被監控spring-boot專案的基本資訊,詳細的Health資訊、記憶體資訊、JVM資訊、垃圾回收資訊、各種配置資訊(比如資料來源、快取列表和命中率)等,還可以直接修改logger的level。
因此初學者首先要清楚的區分客戶端和服務端的概念
服務端:是指springboot admin這個應用(通常就是指監控伺服器),一個服務端可以監控多個客戶端
客戶端是:被服務端監控的物件(通常就是指你的業務系統)
2.服務端準備
步驟一:搭建springboot maven專案
步驟二:配置pom.xml檔案
主要是新增依賴
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.3.1</version> </dependency>
步驟三:application.properties中配置埠號
server.port=8000
步驟四:啟動類上加註解@EnableAdminServer
@SpringBootApplication @EnableAdminServer public class SpringbootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringbootAdminApplication.class, args); } }
步驟五:啟動專案,訪問http://localhost:8000/applications,顯示如下
服務端搞定,夠簡單吧!
3.客戶端準備
步驟一:在需要監控的springboot專案中新增jar包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!--admin server 監控--> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.3.1</version> </dependency>
步驟二:在啟動配置檔案中配置如下
#監控配置
management:
endpoints:
web:
exposure:
include: '*'
spring:
application:
name: mpdemo #應用名稱,可以任意取
boot:
admin:
client:
url: http://localhost:8000 #監控伺服器的地址
instance:
service-url: http://192.168.5.195:8080/api #當前系統api地址
View Code
步驟三:安全配置 SecurityPermitAllConfig
package com.ldp.mp.common.config; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration public class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().permitAll() .and().csrf().disable(); } }View Code
步驟四:啟動專案,客戶端搞定!
4.測試效果
重新整理監控服務端:http://localhost:8000/applications,介面如下,可以看到如下資訊
如果監控了多個專案,在這裡都可以看到,
點選看監控詳情
5.課程演示程式碼與視訊學習資料獲取
1.部落格對應的視訊教程
2.視訊資料領取,課程程式碼下載,加微信851298348,傳送“admin”。
3.如果這篇部落格幫助到了您,希望您可以請作者喝杯咖啡,表示鼓勵!