Quick Start


1. Spring Boot Admin是干什么的?

用来监控Spring Boot项目,可以通过Spring Boot Admin Client(via Http) 或者 使用Spring Cloud(例如:eureka,Consul)将项目注册到Spring Boot Admin进行管理


2. 通过Spring Boot Admin Client注册client application

2.1 Spring Boot Admin Server应用程序

2.1.1 依赖:pom.xml

<dependencies>
<!-- @Start Spring boot Admin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- @End Spring boot Admin -->
</dependencies>

2.1.2 在启动类上添加@EnableAdminServer注解

@SpringBootApplication
@EnableAdminServer
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}

2.2 client application

2.2.1. 依赖:pom.xml

<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.2</version>
</dependency>
<!--@Start 为了保护endpoints -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!--@End为了保护endpoints -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

2.2.2 在SBA Client配置文件中添加Spring Boot Admin Server的服务器地址:application.yml

#Spring Boot Admin Server的地址
spring.boot.admin.client.url: "http://localhost:8080"
#在Spring Boot 2中大多数的endpoints都没有通过http协议暴露,* 暴露所有
management.endpoints.web.exposure.include: "*"
spring.application.name: client1

2.2.3 使actuator endpoints 可以访问

@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll()
.and().csrf().disable();
}
}

2.3.效果图

3. 通过Spring Cloud Eureka 注册client application

3.1 Eureka Server

3.1.1 依赖:pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

3.1.2 配置文件:application.properties

server.port=8761

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF

3.1.3 启动类

@EnableEurekaServer
@SpringBootApplication
public class EurekaServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication.class, args);
}
}

3.2 Spring Boot Admin Server

3.2.1 添加依赖

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- @Start Spring boot Admin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

3.2.2 配置文件 application.yml

server:
port: 8080
spring:
application:
name: spring-boot-admin-server
#配置Eureka客户端
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/

3.2.3 启动类

@SpringBootApplication
@EnableAdminServer
@EnableDiscoveryClient
public class SpringBootAdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminServerApplication.class, args);
}
}

3.3 Spring Boot Admin Client

3.3.1 添加依赖,pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<!-- @Start Spring Boot Admin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- @End Spring Boot Admin --> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

3.3.2 修改配置application.xml

server.port: 9090
spring.application.name: spring-boot-admin-client
#配置Eureka客户端
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
#通过http暴露所有的endpoints(spring boot 2 大部门都没有暴露)
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS

3.3.3 启动类

@SpringBootApplication
@EnableDiscoveryClient
public class SpringBootAdminClientApplication { public static void main(String[] args) {
SpringApplication.run(SpringBootAdminClientApplication.class, args);
} @Configuration
public class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll()
.and().csrf().disable();
}
}
}

3.4 效果图

GitHub地址

Spring Boot Admin Quick Start的更多相关文章

  1. Spring Boot Admin 的使用 2

    http://blog.csdn.net/kinginblue/article/details/52132113 ******************************************* ...

  2. Spring Boot Admin的使用

    http://www.jianshu.com/p/e20a5f42a395 ******************************* 上一篇文章中了解了Spring Boot提供的监控接口,例如 ...

  3. Spring Boot Admin Reference Guide

    1. What is Spring Boot Admin? Spring Boot Admin is a simple application to manage and monitor your S ...

  4. spring boot admin

    这里记录一个spring cloud的模板,有的模块spring cloud eureka + spring boot admin + spring cloud zuul + 一个普通spring c ...

  5. spring boot admin + spring boot actuator + erueka 微服务监控

    关于spring boot actuator简单使用,请看 简单的spring boot actuator 使用,点击这里 spring boot admin 最新的正式版本是1.5.3 与 spri ...

  6. Spring Boot admin 2.0 详解

    一.什么是Spring Boot Admin ? Spring Boot Admin是一个开源社区项目,用于管理和监控SpringBoot应用程序. 应用程序作为Spring Boot Admin C ...

  7. Spring boot admin 节点状态一直为DOWN的排查

    项目中需要监控各个微服务节点的健康状态,找到了spring boot admin这个全家桶监控工具,它其实是Vue.js美化过的Spring Boot Actuator,官方的解释是: codecen ...

  8. SpringCloud(8)微服务监控Spring Boot Admin

    1.简介 Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的开源软件.Spring Boot Admin 分为 Server 端和 Client 端,Spring ...

  9. Spring Boot Admin 的使用

    Spring Boot 版本: 1.5.20 一.Spring Boot Admin Server 1.在pom.xml中增加 <dependency> <groupId>or ...

随机推荐

  1. 基于三个kinect的人体建模

       单个kinect的人体重建,在Kinect SDK 1.8中,Kinect Fusion的效果已经很不错了.其缺点显而易见,一是扫描时间长,重建对象也需要长时间保持静态:二是需要人体或者kine ...

  2. SCWS中文分词,安装说明(以:Win32环境、utf8字符集为例)

    SCWS官方网站:http://www.xunsearch.com/scws/ 1. 根据您当前用的 PHP 版本,下载相应已编译好的 php_scws.dll 扩展库.    目前支持 PHP-5. ...

  3. Java考试题

    1.     public class GC { 2.     private Object o; 3.     private voiddoSomethingElse(Object obj) { o ...

  4. python 常用 time, datetime处理

    python 中 time 有三种格式: float, struct tuple(time.struct_time 或 datetime.datetime), str 常用的: float --> ...

  5. Codeforces 934.C A Twisty Movement

    C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. 2018-2019 ACM-ICPC 沈阳赛区 K. Let the Flames Begin

    K. Let the Flames Begin 题目链接:https://codeforces.com/gym/101955/problem/K 题意: n个人围成一个圈,然后依次从1开始报数,报到k ...

  7. Google Cast和ChromeCast

    Google Cast类似于DLNA,AirPlayer,Miracast,就是一种投屏技术.我们ATV产品是对Google Cast和ChromeCast都是支持的. Google Cast 大致工 ...

  8. Land of Farms HDU - 5556 二分图匹配

    Farmer John and his brothers have found a new land. They are so excited and decide to build new farm ...

  9. bzoj 1528 [POI2005]sam-Toy Cars 堆维护+贪心

    1528: [POI2005]sam-Toy Cars Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 716  Solved: 306[Submit][S ...

  10. horizon源码分析(二)

    源码版本:H版 一.简要回顾 对于请求: 地址:/dashboard/admin/instances/ 方式:POST 参数: instances_filter_q: action:instances ...