现在的位置: 首页 > 编程语言 > 正文

SpringBootAdmin实践详解

2020年02月13日 编程语言 ⁄ 共 1519字 ⁄ 字号 评论关闭

在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: monitorturbine: 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

以上就是本次介绍的全部知识点,感谢大家对我们的支持。

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

以上就上有关SpringBootAdmin实践详解的相关介绍,要了解更多Spring,Boot,Admin内容请登录学步园。

抱歉!评论已关闭.