• SpringCloud引入SpringBoot Admin


    Spring Boot Admin可以监控和管理Spring Boot,能够将 Actuator 中的信息进行界面化的展示,也可以监控所有 Spring Boot 应用的健康状况,提供警报功能。

    1. 创建SpringBoot工程

    2. 引入相关依赖

    1. <dependency>
    2. <groupId>com.alibaba.cloud</groupId>
    3. <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    4. </dependency>
    5. <dependency>
    6. <groupId>de.codecentric</groupId>
    7. <artifactId>spring-boot-admin-starter-server</artifactId>
    8. <version>2.3.0</version>
    9. </dependency>
    10. <dependency>
    11. <groupId>org.springframework.boot</groupId>
    12. <artifactId>spring-boot-starter-web</artifactId>
    13. </dependency>

    3. 开启SpringBoot Admin服务

    启动类增加@EnableAdminServer注解

    1. @EnableAdminServer
    2. @SpringBootApplication
    3. public class AdminApplication {
    4. public static void main(String[] args) {
    5. SpringApplication.run(AdminApplication.class, args);
    6. }
    7. }

    4. 修改bootstrap.yml

    添加注册中心配置

    1. server:
    2. port: 7001
    3. servlet:
    4. context-path: /e-commerce-admin
    5. spring:
    6. application:
    7. name: e-commerce-admin # 应用名称也是构成 Nacos 配置管理 dataId 字段的一部分 (当 config.prefix 为空时)
    8. cloud:
    9. nacos:
    10. # 服务注册发现
    11. discovery:
    12. enabled: true # 如果不想使用 Nacos 进行服务注册和发现, 设置为 false 即可
    13. server-addr: 192.168.20.135:8848 # nacos 注册中心地址
    14. namespace: 1bc13fd5-843b-4ac0-aa55-695c25bc0ac6
    15. metadata:
    16. management:
    17. context-path: ${server.servlet.context-path}/actuator # 如果配置了context-path,则健康检查需要配置这一项
    18. # 暴露端点,如果开放了所有的端点,确保不要暴露到外网
    19. management:
    20. endpoints:
    21. web:
    22. exposure:
    23. include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 *, 可以开放所有端点
    24. endpoint:
    25. health:
    26. show-details: always

    5. 访问

    http://127.0.0.1:7001/e-commerce-admin

    点击进去后,可以查看到该实例的详细信息

    6. 其他SpringBoot服务加入监控

    POM文件引入依赖

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-actuator</artifactId>
    4. </dependency>

    修改bootstrap.yml文件,增加如下部分

    1. spring:
    2. cloud:
    3. nacos:
    4. discovery:
    5. metadata:
    6. management:
    7. context-path: ${server.servlet.context-path}/actuator
    8. # 暴露端点
    9. management:
    10. endpoints:
    11. web:
    12. exposure:
    13. include: '*'
    14. endpoint:
    15. health:
    16. show-details: always

    启动,然后访问 http://127.0.0.1:7001/e-commerce-admin 即可看到新的应用详细信息

    7. 开启SpringBoot Admin登录认证功能

    参考:https://blog.csdn.net/moxiong3212/article/details/138094893

    在SpringBoot Admin项目中,引入下面的依赖

    1. <!-- 开启登录认证功能 -->
    2. <dependency>
    3. <groupId>org.springframework.boot</groupId>
    4. <artifactId>spring-boot-starter-security</artifactId>
    5. </dependency>

  • 相关阅读:
    微信小程序抓包之路
    猫罐头哪个好?宠物店精选5款口碑好的猫罐头推荐!
    数据结构:红黑树讲解(C++)
    CSDN每日一题学习训练——Python版(N皇后 II、买卖股票的最佳时机 II、编程通过键盘输入每一位运动员)
    中国大数据与实体经济融合发展白皮书2019整理
    Django——视图
    2.zigbee开发,zigbee点亮灯,如何正确使用别人提供的模板文件
    ChatGPT第八讲
    Python教程:global、nonlocal关键字区别与用法
    16位简单ASM题的记录——[HGAME 2022 week1]easyasm
  • 原文地址:https://blog.csdn.net/moxiong3212/article/details/138094862