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地址
步驟三:安全配置 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(); } }
步驟四:啟動項目,客戶端搞定!
4.測試效果
刷新監控服務端: http://localhost:8000/applications ,界面如下,可以看到如下信息
如果監控了多個項目,在這里都可以看到,
點擊看監控詳情
5.課程演示代碼與視頻學習資料獲取
1.博客對應的視頻教程
2.視頻資料領取,課程代碼下載,加微信851298348,發送“admin”。
3.如果這篇博客幫助到了您,希望您可以請作者喝杯咖啡,表示鼓勵!