项目中某个微服务开启了spring健康检查:
eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://localhost:8800/eureka/ #注册中心地址
instance:
hostname: localhost
instance-id: http://localhost:7882
redis: #问题是出在这儿
ip: 192.168.1.123
port: 6379
password: acmed
timeout: 10000
jedis:
pool:
max-active: 100
max-idle: 10
max-wait: 10000
启动项目,该微服务注册到eureka的状态是down,后台无报错。访问http://ip:port/health返回信息中显示jedis获取resource失败(查看健康检查详情要额外设置managementfalse.security.enabled=false)。
原因:heathcheck在项目启动的时候会去检查jdbc,mq,redis等连接情况(假如配置的话),如果任一项连接失败,就会通知eureka当前微服务不可用。
healthcheck检查redis是否连接正常,调用 的是RedisHealthIndicator,而它拿的连接参数是要遵循spring boot配置的,即redis前面有spring前缀。
解决:yml下redis配置项前面加上spring,如下:
spring: #redis配置项要在spring节点下面,具体可看spring boot官方指导文档
redis:
ip: 192.168.1.123
port: 6379
password: acmed
timeout: 10000
jedis:
pool:
max-active: 100
max-idle: 10
max-wait: 10000
如果redis配置不想用spring规则的,可以覆盖重写这个类,参照http://blog.didispace.com/spring-cloud-tips-3/
Spring Boot健康检查相关配置和整理
1.什么是Spring Boot的健康检查,有什么用?
Spring Boot提供了多项组件的健康检查,有利于监控各组件运行状况,但是有时开发者因此会启动不成功,报错等,需要合理配置。
2.Spring Boot项目中都有哪些检查,如何配置相关检查:
2.1首先健康检查引入的包是
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-actuator</artifactid>
</dependency>
2.2相关健康检查相关Indicator
CassandraHealthIndicator 检查Cassandra是否可用
DiskSpaceHealthIndicator 检查磁盘空间是否不足
DataSourceHealthIndicator 检查能否从DataSource获取链接
ElasticsearchHealthIndicator 检查Elasticsearch cluste是否可用
JmsHealthIndicator 检查JMS broker是否可用
MailHealthIndicator 检查mail server是否可用
MongoHealthIndicator 检查Mongo database是否可用
RabbitHealthIndicator 检查Rabbit server是否可用
RedisHealthIndicator 检查Redis server是否可用
SolrHealthIndicator 检查Solr server是否可用
可以看到,有各项外部服务的检查,具体的请浏览官方文档,这里不再赘余
2.3如何关闭/开启健康检查
application.properties里显式设定
//如禁止es的健康检查如下,默认均为开启状态
management.health.elasticsearch.enabled=false
也可以使用*全部禁止
management.health.*.enabled=false
Spring boot Admin禁用redis的健康检查
当前在做项目时,发现引入了redis的包,但实际没有用到,这样导致健康检查的时候,redis那一项是红色,一直是down状态。 经网上查找,增加以下配置即可:
management:
health:
redis:
enabled: false
很多网上说是management.redis.enabled,这个是不对的。