欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

Spring Boot Admin实践详解

时间:2021-08-08 08:25:18|栏目:JAVA代码|点击:

在Spring Boot Actuator中提供很多像health、metrics等实时监控接口,可以方便我们随时跟踪服务的性能指标。Spring Boot默认是开放这些接口提供调用的,那么就问题来了,如果这些接口公开在外网中,很容易被不法分子所利用,这肯定不是我们想要的结果。在这里我们提供一种比较好的解决方案。

被监控的服务配置

为被保护的http请求添加请求前缀

management:
 context-path: /example-context 
eureka:
 instance:
  status-page-url-path: ${management.context-path}/info 
  health-check-url-path: ${management.context-path}/health

添加请求前缀

Spring Boot Admin在启动的时候会去eureka拉去服务信息,其中health与info需要特殊处理,这两者的地址是根据status-page-url-path和health-check-url-path的值。

zuul网关配置

zuul保护内部服务http接口

zuul:
 ignoredPatterns: /*/example-context/** 

这里之所以不是/example-context/**,由于网关存在项目前缀,需要往前一级,大家可以具体场景具体配置

Spring Boot Admin配置

配置监控的指标参数

spring:< 大专栏 Spring Boot Admin最佳实践/span>
 application:
  name: monitor
 boot:
  admin:
   discovery:
    converter:
     management-context-path: /example-context 
   routes:
    endpoints: env,metrics,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream
   turbine:
    clusters: default
    location: monitor

turbine:
 aggregator:
  clusterConfig: default
 appConfig: monitor-example #<2>
 clusterNameExpression: metadata['cluster']

与应用配置的management.context-path相同

添加需要被监控的应用Service-Id,以逗号分隔

讲解一下,通过创建一个请求前缀,可以在网关处使用前缀的方式将其排除,也就是外网将无法访问这些监控API,同时,内网还是可以进行加前缀的方式进行访问,为Spring Boot Admin提供了支持条件。management还支持port和ip的方式,但这两种方式有局限性,如果在同一台机器上部署多个服务,就会存在端口占用或者其他问题。这种方案还有一个好处,以上配置一旦确定以后,所有服务都不需要进行特殊化处理,可以直接使用。

问答:

问题:Full authentication is required to access this resource

参考链接:https://github.com/joshiste/spring-boot-admin-samples

上一篇:Eclipse 开发java 出现Failed to create the Java Virtual Machine错误解决办法

栏    目:JAVA代码

下一篇:Spring 4 支持的 Java 8 特性

本文标题:Spring Boot Admin实践详解

本文地址:http://www.codeinn.net/misctech/165107.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有