一、说明
Spring Boot Admin是一个开源社区项目,用于管理和监控SpringBoot应用程序。
二、新建一个 Spring Boot Admin Server
1、先新建一个 client ,向服务注册中心注册,然后添加依赖
<!-- spring boot admin server -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.3</version>
</dependency>

这里的版本号需要注意一下
2、添加配置文件
spring:
application:
name: sc-admin-server
server:
port: 8768
eureka:
client:
registryFetchIntervalSeconds: 5
service-url:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
instance-id: ${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
3、启动类添加注解 @EnableAdminServer
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
/**
* 加上 @EnableAdminServer 注解,开启 admin server 的功能
*/
@SpringBootApplication
@EnableAdminServer
@EnableEurekaClient
public class ScAdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(ScAdminServerApplication.class, args);
}
}
三、新建一个 Spring Boot Admin Client
1、先新建一个 client ,向服务注册中心注册,然后添加依赖
<!-- actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
这里的版本号也需要注意一下
2、修改配置文件
spring:
application:
name: sc-admin-client
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
# 为了在服务注册中心里显示实际的 IP 地址,需添加下面的配置
instance-id: ${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true
client:
registryFetchIntervalSeconds: 5
service-url:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
server:
port: 8762
四、启动 Eureka Server、Spring Boot Admin Server、Spring Boot Admin Client

访问 Spring Boot Admin Server http://localhost:8768/
spring boot admin server
网友评论