文章目录
Springboot微服务状态管理项目
一、官网地址
https://codecentric.github.io/spring-boot-admin/current/#_what_is_spring_boot_admin
二、使用目的
当网络环境中有多个springboot项目时,可以使用 springboot-admin微服务 对每个服务的运行状态,服务器的状态进行一个动态实时的监控,方便运维人员对 服务器/服务 状态进行统一掌握。
三、使用方法
(一)pom.xml文件中引入依赖
(1)服务端引入
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
(2)客户端引入
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
如果客户端不使用安全开发形式,也就是可以不引入spring-boot-starter-security依赖
(二)springboot项目启动类增加注解
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
(三)配置spring-boot-admin
####(1)配置服务端
配置监控服务的端口,避免与其他服务冲突
server:
port: 8888
(2)配置客户端
1.客户端配置文件配置信息
客户端配置文件
spring:
boot:
admin:
client:
url: http://localhost:8888 #这里的端口号需要要和服务端的配置的端口号进行对应
instance:
prefer-ip: true #如果发现应用实例是处于离线状态,则开启IP
如果客户端引入了安全模块
@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http