开启Healthcheck检查redis连接失败导致注册Eureka状态是DOWN

项目中某个微服务开启了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/

猜你喜欢

转载自blog.csdn.net/liubingyu12345/article/details/78930816