spring-boot-admin 的整合使用(单体项目)

介绍

Spring Boot Admin提供了很多服务治理方面的功能,利用它能节省我们很多在治理服务方面的时间和精力Spring Boot Admin提供了如下功能(包括但不限于):

显示健康状态及详细信息,如JVM和内存指标、数据源指标、缓存指标
跟踪并下载日志文件
查看jvm系统-和环境属性
查看Spring启动配置属性
方便loglevel管理
查看线程转储
视图http-traces
查看http端点
查看计划任务
查看和删除活动会话(使用spring-session)
状态更改通知(通过电子邮件、Slack、Hipchat…)
状态变化的事件日志(非持久性)
……(and more !)

一、环境配置

因为我是单体项目 server + client 直接放一起整合了,

  • springboot 2.2.0 ,
  • spring-boot-admin 2.2.2 ( 用boot 对应的 2.2.0 应该好点, 目前没问题就先不管了 )

1、maven 依赖

  <!-- actuator 监控中心 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
       <!-- spring-boot-admin ,必须有 actuator监控中心 -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.2.2</version>
        </dependency>

2、yml - actuator 监控, 配置spring-boot-admin使用

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

3、yml - spring-boot-admin配置

spring:
  ## spring-boot-admin 配置
  boot:
    admin:
      ## admin 服务端访问地址
      context-path: /bootAdmin/
      ## admin 客户端连接服务端
      client:
        # 为了显示客户端的ip否则是以主机名显示的,这样需要添加hosts影射。
        instance:
          prefer-ip: true
        url: http://localhost:${server.port}/${spring.boot.admin.context-path}/
        #username: admin
        #password: admin@12345

4、yml - spring-boot-admin 实时日志配置

filePath 为自己的 logback配置 , 主要是 logging.file , spring-boot-admin 会自动读取对应的文件

## logback日志输出
logging:
  # 日志目录, 线上请配置linux 绝对路径 如:/usr/local/work/xijia2/logs
  filePath: logs
  # 配置日志路径即可实时输出到 spring-boot-admin 日志管理
  file: src/main/resources/static/log/xijia.log

5、启动类添加注解

@EnableAdminServer

二、效果展示

主页

在这里插入图片描述

系统信息

在这里插入图片描述

环境配置

在这里插入图片描述

日志

在这里插入图片描述

部署配置,线上的实时输出文件

logging.file = /usr/local/work/xijia2/log.txt

在这里插入图片描述

  • 个人开源项目(通用后台管理系统)–> https://gitee.com/wslxm/spring-boot-plus2 , 喜欢的可以看看

  • 本文到此结束,如果觉得有用,动动小手点赞或关注一下呗,将不定时持续更新更多的内容…,感谢大家的观看!

猜你喜欢

转载自blog.csdn.net/qq_41463655/article/details/109152670