官网介绍
codecentric’s Spring Boot Admin is a community project to manage and
monitor your Spring Boot ® applications. The applications register
with our Spring Boot Admin Client (via HTTP) or are discovered using
Spring Cloud ® (e.g. Eureka, Consul). The UI is just a Vue.js
application on top of the Spring Boot Actuator endpoints.
codecentric的Spring Boot Admin是一个社区项目,用于管理和监视您的Spring
Boot®应用程序。这些应用程序在我们的Spring Boot Admin Client中注册(通过HTTP),或者是通过Spring
Cloud®(例如Eureka,Consul)发现的。 UI只是Spring Boot Actuator端点之上的Vue.js应用程序
总之这玩意就是对运行中的sping-boot项目的监控组件。
在Spring Boot Admin中 对外部提供服务的项目中作为admin中的客户端,将项目注册到admin服务端上,在admin的服务端就可以统一监控这些部署的服务状态和配置。
Admin Server 端实现是为了后续将服务注册到监控客户端中统一管理和监视。
可以新建一个正常 spring boot的web项目
完整的依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.3.0.RELEASEversion>
<relativePath/>
parent>
<groupId>org.dlblog.admingroupId>
<artifactId>serverartifactId>
<version>0.0.1-SNAPSHOTversion>
<name>admin-servername>
<description>Demo project for Spring Bootdescription>
<properties>
<java.version>1.8java.version>
<spring-boot-admin.version>2.2.3spring-boot-admin.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>de.codecentricgroupId>
<artifactId>spring-boot-admin-starter-serverartifactId>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentricgroupId>
<artifactId>spring-boot-admin-dependenciesartifactId>
<version>${spring-boot-admin.version}version>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
注意版本,若Spring-boot版本过低,启动会报错,
我这里 Spring Boot Admin 的版本是2.2.3 , Spring Boot 版本是2.3.0。之前使用的是2.1.7,启动报错,官网的解决办法就是升Spring Boot 版本。
添加好依赖还需要开启Spring-Boot对AdminServer的支持
@EnableAdminServer //开启AdminServer的支持
@SpringBootApplication
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
指定监控服务的配置
# tomcat configuration
server:
port: 8082
servlet :
context-path:
# log level
logging.level:
root: WARN
org.springframework: DEBUG
org.apache.coyote.http11.Http11InputBuffer: DEBUG
sample.mybatis.mapper: DEBUG
org.apache.ibatis: DEBUG
配置访问端口,当访问这个端口时,就可以看到admin管理画面。
可以看到当前监控服务端已经成功启动,但是还没有客户端注册进来。
完整依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.3.0.RELEASEversion>
<relativePath/>
parent>
<groupId>org.dlblog.admingroupId>
<artifactId>admin-clientartifactId>
<version>0.0.1-SNAPSHOTversion>
<name>admin-clientname>
<description>Demo project for Spring Bootdescription>
<properties>
<java.version>1.8java.version>
<spring-boot-admin.version>2.2.3spring-boot-admin.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>de.codecentricgroupId>
<artifactId>spring-boot-admin-starter-clientartifactId>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentricgroupId>
<artifactId>spring-boot-admin-dependenciesartifactId>
<version>${spring-boot-admin.version}version>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
注意Spring Boot 和Spring Boot Admin的版本关系
#admin客户端注册地址
spring.boot.admin.client.url: http://localhost:8082
management.endpoints.web.exposure.include: "*"
#监视服务名
spring.application.name: adminServer
# log level
logging.level:
root: WARN
org.springframework: DEBUG
org.apache.coyote.http11.Http11InputBuffer: DEBUG
sample.mybatis.mapper: DEBUG
org.apache.ibatis: DEBUG
这里的 spring.boot.admin.client.url 中地址就时上面实现的Admin Server的地址。就是指定注册的地址,若是要注册到多个admin服务端上
用逗号分隔就可以
#admin客户端注册地址
spring.boot.admin.client.url: http://localhost:8082, http://localhost:10082
management.endpoints.web.exposure.include: "*"
#监视服务名
spring.application.name: adminServer
先启动admin 客户端的代码,在启动admin 服务端的代码, 客户端项目可以多放几个。
访问admin服务端的地址 我上面指定的是8082端口
可以看到我监控到两个服务。
spring-boot 快速集成 Admin
最后附上 admin-server 通用源码
https://github.com/DavidLei08/Spring-Boot-dlblog/releases/