一、Spring Boot Admin用于管理和监控一个或者多个Spring Boot程序。Spring Boot Admin分为Server端和Client 端,Client端可以通过向Http Server端注册,也可以结合SpringCloud的服务注册组件Eureka 进行注册。SpringBoot Admin 提供了用AngularJs 写的 Ul 界面,用于管理和监控。其中监控内容包括Spring Boot的监控组件Actuator的各个Http节点,也支持更高级的功能,包括Turbine、Jmx、Loglevel 等。

  二、直接使用Spring Boot Admin监控客户端

  1、Admin Server

  (1)加入依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

  (2)编写启动项

package com.cetc;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
@EnableAdminServer
public class AdminServerApplication { public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
} }

  (3)编写配置文件application.yaml

server:
port: 8691
spring:
application:
name: admin-server
management:
endpoints:
web:
exposure:
include: ["*"]
endpoint:
health:
show-details: always

  2、Admin Client,为了简单使用,我这里还是通过feign的方式去接入Eureka的服务。

  (1)目录结构和Spring-Cloud之Feign声明式调用-4类似,这里全部写出来,有兴趣可以看下方源码

  

  (2)加入依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--admin-client-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.4</version>
</dependency>
<!--admin-client-->

  (3)启动项没有什么特别的,这里直接编写配置文件application.yaml

server:
port: 8692
spring:
application:
name: admin-client
boot:
admin:
client:
url: ["http://127.0.0.1:8691"] # 配置注册的admin Server服务
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8670/eureka/ # 实际开发中建议使用域名的方式
management:
endpoints:
web:
exposure:
include: ["*"]
endpoint:
health:
show-details: always
logfile:
external
-file: logs/log.log # 这里的配置主要是在admin server中看到日志记录
logging:
path: logs
file: logs/log.log # 日志配置

  3、测试。启动Eureka-Server,Eureka-Client,Admin-Server,Admin-Client。端口分别为:8670、8673、8691、8692。

  (1)Eureka-Server注册效果

  

  (2)Admin-Server效果

  

  三、让Admin-Server通过Eureka注册中心来监控所有服务(这才是重点),这里还加入了Security配置,主要目的是为了安全。

  1、Admin-Server

  (1)所需依赖

        <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

  说明:spring-boot-admin-starter-server的版本选择要慎重,不然会有很多坑。

  (2)编写启动项

package com.cetc;

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; @SpringBootApplication
@EnableAdminServer
@EnableEurekaClient
public class AdminServerApplication { public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}

  (3)编写Security配置,这里也可以参考官网配置:https://codecentric.github.io/spring-boot-admin/2.0.4/#_securing_spring_boot_admin_server

package com.cetc.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{ @Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
       .antMatchers("/assets/**").permitAll()
.anyRequest().authenticated()
.and()
//说明:这里和官网不同的是,因为默认端口为/login,所以我这里直接放开login.html就可以了不用配置loginProcessingUrl
//在说明一点,这里是采用的本地页面的。如果前后端分开,请配具体的登录接口。
.formLogin()
.loginPage("/login.html").permitAll()
.and()
//默认接口/logout,不用配置logoutUrl
.logout()
.logoutSuccessUrl("/login.html")
.and()
//这里必须加入httpBasic,因为Eureka-Server是基于最原始的方式进行验证的。
.httpBasic();
}
}

  (4)编写配置文件

server:
port: 8691
spring:
application:
name: admin-server
security:
user:
name: admin
password: admin # 加入登录密码
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8670/eureka/ # 实际开发中建议使用域名的方式
instance:
metadata-
map:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
management:
endpoints:
web:
exposure:
include: ["*"]
endpoint:
health:
show-details: always # 显示具体详情

  说明:metadata-map,主要用于方向验证使用。

  2、Admin-Client这里不需要修改任何配置,只需要注册配置文件手动注册的配置

server:
port: 8692
spring:
application:
name: admin-client
# boot:
# admin:
# client:
# url: ["http://127.0.0.1:8691"] # 配置注册的admin Server服务
eureka:
client:
service
-url:
defaultZone
: http://127.0.0.1:8670/eureka/ # 实际开发中建议使用域名的方式
management:
endpoints:
web:
exposure:
include: ["*"]
endpoint:
health:
show-details: always
logfile:
external-file: logs/log.log # 这里的配置主要是在admin server中看到日志记录
logging:
path: logs
file: logs/log.log # 日志配置

  3、测试。启动Eureka-Server,Eureka-Client,Admin-Server,Admin-Client。端口分别为:8670、8673、8691、8692。

  (1)Eureka-Server效果

  

  (2)Admin-Server效果

  

  说明:为什么Eureka-Client是INSTANCES DOWN的状态。这里服务其实是正常的,最主要的点在于Eureka-Client没有配置actuator。所以访问不到/acturtor/health接口。

  四、源码地址:https://github.com/lilin409546297/spring-cloud/tree/master/admin

Spring-Boot之Admin服务监控-9的更多相关文章

  1. 如何做自己的服务监控?spring boot 2.x服务监控揭秘

    Actuator是spring boot项目中非常强大一个功能,有助于对应用程序进行监视和管理,通过 restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...

  2. 如何做自己的服务监控?spring boot 1.x服务监控揭秘

    1.准备 下载可运行程序:http://www.mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/ 2.添加服务监控依赖 <d ...

  3. Spring Boot (27) actuator服务监控与管理

    actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...

  4. Spring Cloud第十三篇 | Spring Boot Admin服务监控

    本文是Spring Cloud专栏的第十三篇文章,了解前十二篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Clo ...

  5. SpringBoot系列——admin服务监控

    前言 springboot项目部署起来后,如何实时监控项目的运行状况呢?本文记录使用springboot-admin对服务进行监控. springboot-admin介绍:https://codece ...

  6. 一文读懂 Spring Boot、微服务架构和大数据治理三者之间的故事

    微服务架构 微服务的诞生并非偶然,它是在互联网高速发展,技术日新月异的变化以及传统架构无法适应快速变化等多重因素的推动下诞生的产物.互联网时代的产品通常有两类特点:需求变化快和用户群体庞大,在这种情况 ...

  7. Spring Boot、微服务架构和大数据

    一文读懂 Spring Boot.微服务架构和大数据治理三者之间的故事 https://www.cnblogs.com/ityouknow/p/9034377.html 微服务架构 微服务的诞生并非偶 ...

  8. Spring Boot开启Druid数据库监控功能

    Druid是一个关系型数据库连接池,它是阿里巴巴的一个开源项目.Druid支持所有JDBC兼容的数据库,包括Oracle.MySQL.Derby.PostgreSQL.SQL Server.H2等.D ...

  9. 一文读懂spring boot 和微服务的关系

    欢迎访问网易云社区,了解更多网易技术产品运营经验. Spring Boot 和微服务没关系, Java 微服务治理框架普遍用的是 Spring Cloud. Spring Boot 产生的背景,是开发 ...

  10. 在5分钟内将Spring Boot作为Windows服务启动

    分享优锐课学习笔记~来看一下如何使用Spring Boot创建Windows服务以及通过配置详细信息来快速启动并运行. 最近不得不将Spring Boot应用程序部署为Windows服务,感到惊讶的是 ...

随机推荐

  1. 【Gamma】Scrum Meeting8

    目录 写在前面 进度情况 任务进度表 燃尽图 照片 写在前面 例会时间:6.6 22:30-22:45 例会地点:微信群语音通话 代码进度记录github在这里 进度情况 任务进度表 注:点击链接跳转 ...

  2. [技术博客]采用Qthread实现多线程连接等待

    采用Qthread实现多线程连接等待 ​ 本组的安卓自动化测试软件中,在测试开始前需要进行连接设备的操作,如下图左侧的按钮 ​ ​ 后端MonkeyRunner相关操作的程序中提供了connect() ...

  3. mybatis三个执行器的差别

    myBatis官方对参数"defaultExecutorType"是这样说明的: 有这样三种执行器, SIMPLE是普通的执行器:REUSE执行器会重用预处理语句(prepared ...

  4. 常见 SQL 语句的加锁分析

    参考: https://www.aneasystone.com/archives/2017/12/solving-dead-locks-three.html

  5. Alpine容器中运行go的二进制文件

    Alpine容器中运行go的二进制文件 kuSorZ · 3月之前 · 214 次点击 · 预计阅读时间 1 分钟 · 2分钟之前 开始浏览 原文出处:https://cloud.tencent.co ...

  6. Quartus Prime 与 Modelsim 调试 及do文件使用

    Quartus Prime 与 Modelsim 调试 及do文件使用 2019-06-28 11:12:50 RushBTaotao 阅读数 49更多 分类专栏: IntelFPGA-Softwar ...

  7. android studio如何连接夜神模拟器

    原创 2018-02-05 21:35:03 会飞的鱼儿android 阅读数 16706 文章标签: 夜神模拟器连接夜神模拟器的简单方式 更多 分类专栏: Android   版权声明:本文为博主原 ...

  8. MQTT研究之EMQ:【eclipse的paho之java客户端使用注意事项】

    这里,简单记录一下自己在最近项目中遇到的paho的心得,这里也涵盖EMQX的问题. 1. cleanSession 这个标识,是确保client和server之间是否持久化状态的一个标志,不管是cli ...

  9. 9个PNG透明图片免费下载网站推荐

    9个PNG透明图片免费下载网站推荐 酷站推荐 2017.08.06 13:47 png格式的图片因为去掉了的背景,方便使用在任何颜色的背景,所以对于从事设计师的朋友来说,经常会用到png透明图片.相信 ...

  10. CardUtil算出当前身份证持有者的性别和年龄

    import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util ...