1.简介

Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的开源软件。Spring Boot Admin 分为 Server 端和 Client 端,Spring Boot Admin UI部分使用AngularJs将数据展示在前端。

2.工程架构

  • Eureka Server:服务注册中心,端口为8761。
  • Admin Server:用于对微服务系统进行统一的监控和管理。
  • Admin Clinet:客户端集成Admin。

3.构建Admin Server

新建Spring Boot工程,取名为 admin-server 其完整依赖为:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>admin-server</artifactId><version>0.0.1-SNAPSHOT</version><name>admin-server</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><spring-cloud.version>Dalston.RELEASE</spring-cloud.version></properties><dependencies><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-server-ui</artifactId><version>1.5.1</version></dependency><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-server</artifactId><version>1.5.1</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><!-- 管理界面与JMX-Beans交互 --><dependency><groupId>org.jolokia</groupId><artifactId>jolokia-core</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>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

配置application.yml,设置 management.security.enabled=false 关闭安全验证,设置Spring Boot Admin默认开启的节点.

eureka:client:service-url:defaultZone: http://localhost:8761/eureka/
server:port: 5000
spring:application:name: admin-serverboot:admin:routes:endpoints: env,metrics,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream
management:security:enabled: false
logging:file: "logs/boot-admin-sample.log"

在 resources 目录下建一个 logback-spring.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration><include resource="org/springframework/boot/logging/logback/base.xml"/><jmxConfigurator/>
</configuration>

注解 @EnableAdminServer 开启Admin Server的功能.

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

这样Spring Boot Admin工程创建完毕!

4.构建Admin Client

新建Spring Boot工程,取名为 admin-client,其完整依赖为:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>admin-client</artifactId><version>0.0.1-SNAPSHOT</version><name>admin-server</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><spring-cloud.version>Dalston.RELEASE</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.jolokia</groupId><artifactId>jolokia-core</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>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

配置 application.yml 文件,设置日志输出路径,并关闭 Actuator 模块的安全验证。

eureka:client:service-url:defaultZone: http://localhost:8761/eureka/
server:port: 8762
spring:application:name: admin-client
management:security:enabled: false
logging:file: "logs/boot-admin-client.log"

在程序的启动类上加上 @EnableEurekaClient 注解,开启EurekaClient功能.

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

5.启动程序

依次启动 eureka-server、admin-server 和 admin-client 工程,在浏览器访问 admin-server 的主页 http://localhost:5000/,浏览器显示界面如图:

"JOURNAL"选项为服务注册、下线、剔除的时间线。

6.添加安全登录界面

Spring Boot Admin 提供了登录界面的组件,并且和 Spring Boot Security 相结合,需要用户登录才能访问。

引入依赖

<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-server-ui-login</artifactId><version>1.5.0</version>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>

在工程的application.yml中做以下配置,创建一个 security 的 user 用户,它的用户名为 admin ,密码为 123456,。通过 eureka.instance.metadate-map 配置带上该 security 的 user 用户信息。

security:user:name: adminpassword: 123456
eureka:instance:metadata-map:user.name: adminuser.password: 123456

然后,在程序中配置 Spring Boot Security,写 SecurityConfig 的配置类,给静态资源加上 permitAll() 方法,除上述以外的资源访问需要权限认证,另外这些资源不支持 CSFR(跨站请求伪造),所以禁用掉 CSFR,最后需要开启 Http 的额基本认证,即 httpBasic() 方法。

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {// Page with login form is served as /login.html and does a POST on /loginhttp.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();// The UI does a POST on /logout on logouthttp.logout().logoutUrl("/logout");// The ui currently doesn't support csrfhttp.csrf().disable();// Requests for the login page and the static assets are allowedhttp.authorizeRequests().antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**").permitAll();// ... and any other request needs to be authorizedhttp.authorizeRequests().antMatchers("/**").authenticated();// Enable so that the clients can authenticate via HTTP basic for registeringhttp.httpBasic();}}

重新启动 admin-server 工程,在浏览器中访问 http://localhost:5000/,输入用户名admin,密码为123456,登录即可。

参考方志朋《深入理解Spring Cloud与微服务构建》

转载于:https://www.cnblogs.com/yueshutong/p/10272494.html

SpringCloud(8)微服务监控Spring Boot Admin相关推荐

  1. 《深入理解 Spring Cloud 与微服务构建》第十五章 微服务监控 Spring Boot Admin

    <深入理解 Spring Cloud 与微服务构建>第十五章 微服务监控 Spring Boot Admin 文章目录 <深入理解 Spring Cloud 与微服务构建>第十 ...

  2. 服务监控 Spring Boot Actuator 介绍

    服务监控 Spring Boot Actuator 介绍 1. 概述 在本文中,我们将介绍Spring Boot Actuator.首先介绍一些Actuator的基础知识,然后详细讨论Spring B ...

  3. java小马哥百度网盘_思否编程(小马哥):Java 微服务实践 - Spring Boot / Spring Cloud全套,完整版下载 - VIPC6资源网...

    小马哥 Java 微服务实践 – Spring Boot 系列 pptx segmentfault-lessons-master 03Java 微服务实践 – Spring Boot 系列(三)Web ...

  4. java小马哥mercyblitz,小马哥 Java 微服务实践 - Spring Boot 系列

    资源介绍 教程名称:小马哥 Java 微服务实践 - Spring Boot 系列 教程目录: 03Java 微服务实践 - Spring Boot 系列(三)Web篇(中) 04Java 微服务实践 ...

  5. 微服务之spring Boot+MyBatis-Plus +mysql框架

    小白也会搭建spring Boot+MyBatis-Plus +mysql框架 一.新建一个微服务模块cloud-user 1. 搭建步骤 二.编码 1.新建UserController类 2.新建U ...

  6. (转)构建微服务:Spring boot 入门篇

    转自: Spring Boot(一):入门篇 - 纯洁的微笑 - 博客园 : 什么是Spring Boot Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 S ...

  7. Java微服务之Spring Boot on Docker,java开发面试笔试题

    我总结出了很多互联网公司的面试题及答案,并整理成了文档,以及各种学习的进阶学习资料,免费分享给大家. 扫描二维码或搜索下图红色VX号,加VX好友,拉你进[程序员面试学习交流群]免费领取.也欢迎各位一起 ...

  8. 全球数据一致性,事务,微服务和Spring Boot / Tomcat / Jetty

    我们通常会构建需要一起执行以下几项操作的应用程序:调用后端(微)服务,写入数据库,发送JMS消息等.但是,如果在调用其中之一时出错,会发生什么情况?远程资源,例如,在调用Web服务后,如果数据库插入失 ...

  9. 构建微服务:Spring boot 入门篇

    Spring官方网站本身使用Spring框架开发,随着功能以及业务逻辑的日益复杂,应用伴随着大量的XML配置文件以及复杂的Bean依赖关系.随着Spring 3.0的发布,Spring IO团队逐渐开 ...

最新文章

  1. 奥巴马女儿要上哈佛了!从小给女儿定下了五条规矩! 2017-08-07 07:35 哈佛/美国 转载授权请回复“转载“ 文:益美传媒|编辑:Angela 奥巴马曾说自己最骄傲的一件事,就是即使在长
  2. 单机和分布式场景下,有哪些流控方案?
  3. React开发(136):ant design学习指南之form中动态form新增删除
  4. 48.检测对象是否为空
  5. [转帖]每天看一遍,释怀所有难过
  6. linux分区文件 pe,关于linux的磁盘和分区的操作(一)
  7. 谷歌用AI诊断早期肺癌超越人类医生,登上Nature子刊
  8. 禁用安全模式小方法!!~
  9. JAVA音频转换MP3转AMR互转
  10. python画密度散点图_实战Pyhton中matplotlib箱线图的绘制(matplotlib双轴图、箱线图、散点图以及相关系数矩阵图)...
  11. iOS之HealthKit使用
  12. 计算机系单身率排行榜,2020中国高校单身率排行榜出炉!附:单身率特别高的专业...
  13. thx是什么意思_thx是什么意思?
  14. 记录下生活:ETC卡充值(上海)
  15. 【AI框架】MMDetection3D 使用指南
  16. 万全r680g7配置raid_联想万全r680g7服务器系统用户手册v1.2
  17. 墙裂推荐6本适用于所有Java程序员阅读书籍
  18. 【Java程序设计】实验七 网络通信
  19. 【C语言】C语言从入门到精通|第1章 C语言概述—自学笔记
  20. 【java基础知识】——jdk和jre的区别

热门文章

  1. 002_JavaScript的历史
  2. 001_日志系统的架构模型
  3. java 小坑_关于Java子父类关系的小坑
  4. 英雄多少钱steam_¥50元到手蓝宝石显卡?玩转GTAV轻松CSGO英雄联盟帧数144fps
  5. Kotlin极简教程:第4章 基本数据类型与类型系统
  6. Mysql基础运维及复制架构——PRIT非完整恢复
  7. 上古卷轴5python_基于Python-Flask的权限管理5:字典管理
  8. android 定位服务 耗电吗,关于Android的定位服务
  9. 取消管理员取得所有权_win7管理员取得所有权批处理 - 卡饭网
  10. LetCode: 5. 最长回文子串