简介

Spring Boot Admin 用于监控基于 Spring Boot 的应用,它是在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI。

参考手册地址:http://codecentric.github.io/spring-boot-admin/2.1.1/

Spring Boot Admin 是由服务端Server和客户端Client组成

  • 服务端
    • 1.创建一个springboot工程并添加以下依赖

       1 <dependencies>
      2 <dependency>
      3 <groupId>org.springframework.boot</groupId>
      4 <artifactId>spring-boot-starter-web</artifactId>
      5 </dependency>
      6
      7 <dependency>
      8 <groupId>de.codecentric</groupId>
      9 <artifactId>spring-boot-admin-server</artifactId>
      10 <version>2.1.1</version>
      11 </dependency>
      12
      13 <dependency>
      14 <groupId>de.codecentric</groupId>
      15 <artifactId>spring-boot-admin-server-ui</artifactId>
      16 <version>2.1.1</version>
      17 </dependency>
      18
      19 <dependency>
      20 <groupId>org.springframework.boot</groupId>
      21 <artifactId>spring-boot-starter-security</artifactId>
      22 </dependency>
      23 </dependencies>
    • 2.重写权限控制类(非必要)
       1 @Configuration
      2 public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
      3 private final String adminContextPath;
      4
      5 public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
      6 this.adminContextPath = adminServerProperties.getContextPath();
      7 }
      8
      9 @Override
      10 protected void configure(HttpSecurity http) throws Exception {
      11 SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
      12 successHandler.setTargetUrlParameter("redirectTo");
      13 successHandler.setDefaultTargetUrl(adminContextPath + "/monitor");
      14
      15 http.authorizeRequests()
      16 .antMatchers(adminContextPath + "/assets/**").permitAll()
      17 .antMatchers(adminContextPath + "/login").permitAll()
      18 .anyRequest().authenticated()
      19 .and()
      20 .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
      21 .logout().logoutUrl(adminContextPath + "/logout").and()
      22 .httpBasic().and()
      23 .csrf()
      24 .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
      25 .ignoringAntMatchers(
      26 adminContextPath + "/instances",
      27 adminContextPath + "/actuator/**"
      28 );
      29 }
      30 }
       1 @EnableWebSecurity
      2 public class WebSecurityConfig implements WebMvcConfigurer {
      3
      4 @Bean
      5 public UserDetailsService userDetailsService() throws Exception {
      6 InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
      7 manager.createUser(User.withDefaultPasswordEncoder().username("root").password("root").roles("administrator").build());
      8 return manager;
      9 }
      10 }
    • 3.启动类添加注解@EnableAdminServer
      1 @SpringBootApplication
      2 @EnableAdminServer
      3 public class AdminServerApplication{
      4
      5 public static void main(String[] args) {
      6 SpringApplication.run(AdminServerApplication.class, args);
      7 }
      8 }
    • 4.配置application.yml
      1 server:
      2 port: 8081
      3
      4 spring:
      5 boot:
      6 admin:
      7 context-path: monitor
    • 5.浏览器访问该项目
  • 客户端
    • 1.在需要被监控的应用里面添加如下依赖(注意版本号要与server端相同)

      1 <dependency>
      2 <groupId>de.codecentric</groupId>
      3 <artifactId>spring-boot-admin-starter-client</artifactId>
      4 <version>2.1.1</version>
      5 </dependency>
    • 2.编辑配置文件(详细属性配置参考手册)
      1 spring.boot.admin.client.url = http://localhost:8081/admin-server/monitor
      2 spring.boot.admin.client.username = root
      3 spring.boot.admin.client.password = root
      4 spring.boot.admin.client.instance.service-base-url=http://localhost:8080
      5 spring.boot.admin.client.instance.name = dida
      6
      7 management.endpoints.web.exposure.include = *
      8 management.endpoint.health.show-details = ALWAYS
  • 刷新服务端

问题记录

  按照上面的操作,我把公司的一个项目配置成了客户端。在我的win10系统电脑上面运行这两个程序是没有问题的。但是当实际部署在linux服务器上面的时候就遇到了问题:我把springbootAdmin的server端部署到了linux服务器(服务器1),把要监控的项目部署到了另一台Linux服务器(服务器2),这两台服务器处于同一个局域网内。运行这两个项目,发现程序server端能够发现这个我的client项目,但是client项目一直处于断开状态。

错误日志

WARN  de.codecentric.boot.admin.client.registration.ApplicationRegistrator.register Line:115 - Failed to register application as Application
(name=dida, managementUrl=http://www.xxx.com:8081/dida/actuator, healthUrl=http://www.xxx.com:8081/dida/actuator/health,serviceUrl=http://www.xxx.com:8081/dida)
at spring-boot-admin ([http://admin.xxx.com:8080/monitor/instances]): 404 null. Further attempts are logged on DEBUG level

经过多次尝试,发现spring.boot.admin.client.url 该项目配置应该配置ip地址 http://172.18.0.188:8080/monitor,而不是域名。

INFO  de.codecentric.boot.admin.client.registration.ApplicationRegistrator.register Line:98 - Application registered itself as 2449779efa06

日志显示注册成功。

待补充 ... ...

 

SpringBoot Admin应用监控搭建的更多相关文章

  1. 关于SpringBoot Admin server 监控注意事项

    当你导入了依赖 <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-bo ...

  2. 使用SpringBoot Admin监控SpringCloud微服务

    spring-boot admin的github地址:https://github.com/codecentric/spring-boot-admin 本文基于SpringCloud的环境和配置上增加 ...

  3. Springboot监控之二:Spring Boot Admin对Springboot服务进行监控

    概述 Spring Boot 监控核心是 spring-boot-starter-actuator 依赖,增加依赖后, Spring Boot 会默认配置一些通用的监控,比如 jvm 监控.类加载.健 ...

  4. 【Springboot】用Springboot Admin监控你的微服务应用

    1 简介 目前,微服务大行其道,各大小公司争相学习模仿,把单体应用拆得七零八落.服务多了,运行的实例多了,给运维人员的压力就更大了.如果有十几个应用,单单做Health Check就已经够费时间的了. ...

  5. Spring-Boot之Admin服务监控-9

    一.Spring Boot Admin用于管理和监控一个或者多个Spring Boot程序.Spring Boot Admin分为Server端和Client 端,Client端可以通过向Http S ...

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

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

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

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

  8. 实战SpringBoot Admin

    长话短说哦,直接查看下文吧 目录 声明 先锋 前提 SpringBoot Admin 介绍 服务端的搭建 客户端的搭建 参数的指南 尾声 声明 见名知意,实战SpringBoot Admin,实战!实 ...

  9. LNMP+zabbix分布式监控搭建及版本升级

    LNMP+zabbix分布式监控搭建需要组件:gcc gcc-c++ openssl* pcre pcre-devel gd gd-devel libjpeg-devel libpng-devel l ...

随机推荐

  1. PA防火墙抓包结果显示重传(re-transmission)

    问题起因: 部分内网服务器调用外网站点抓取图片时出现缓慢及超时现象. 由于是由内向外方向的访问,且通过的应用层设备只有防火墙:而且用其他网段测试机测试的时候发现并没有上述访问缓慢或超时. 从防火墙抓包 ...

  2. java类里的成员变量是自身的对象问题

    今晚看单例模式饿汉时想到一个问题:假如java类里的成员变量是自身的对象,则新建该类对象时内存中怎么分配空间,我感觉似乎死循环了.于是上网搜索了下,哈哈,果然有人早就思考过这个问题了,站在巨人的肩膀上 ...

  3. 动态代理+静态代理+cglib代理 详解

    代理定义:代理(Proxy):是一种设计模式,提供了对目标对象另外的访问方式;即通过代理对象访问目标对象.好处是:可以在目标对象实现的基础上,增强额外的功能操作,即扩展目标对象的功能. 动态代理+静态 ...

  4. Codeforces Round #316 (Div. 2) D. Tree Requests(dsu)

    题目链接 题意:对于m次询问 求解以vi为根节点 深度为hi的的字母能不能组合成回文串. 思路:暴力dsu找一边 简直就是神技! #include<bits/stdc++.h> #defi ...

  5. AtCoder Beginner Contest 168

    比赛链接:https://atcoder.jp/contests/abc168/tasks A - ∴ (Therefore) 题意 给出一个由数字组成的字符串 $s$,要求如下: 如果 $s$ 以 ...

  6. HDU -1506 Largest Rectangle in a Histogram&&51nod 1158 全是1的最大子矩阵 (单调栈)

    单调栈和队列讲解:传送门 HDU -1506题意: 就是给你一些矩形的高度,让你统计由这些矩形构成的那个矩形面积最大 如上图所示,如果题目给出的全部是递增的,那么就可以用贪心来解决 从左向右依次让每一 ...

  7. Codeforces Round #582 (Div. 3) F. Unstable String Sort

    传送门 题意: 你需要输出一个长度为n的字符序列(由小写字母组成),且这个字符串中至少包含k个不同的字符.另外题目还有要求:给你两个长度为p和q的序列,设字符序列存在s中 那么就会有s[Pi]< ...

  8. 2020ICPC&#183;小米 网络选拔赛第一场 J.Matrix Subtraction (贪心,二维差分)

    题意:给一个\(nXm\)的矩阵,可以选取\(aXb\)的子矩阵,使子矩阵中的所有元素减一,问最后是否能使矩阵中所有元素变为\(0\). 题解:首先贪心,我们看最左上角的元素,如果\(g[1][1]\ ...

  9. Uva 12436 Rip Van Winkle's Code

    Rip Van Winkle was fed up with everything except programming. One day he found a problem whichrequir ...

  10. javascript——function类型(this关键字)

    如果不用分组的话,当用exec检测rar的时候会错误 结果: Function: 返回值为三(不推荐)