spring-boot - Spring Boot执行器: Why is the Health status of Redis cluster not correct?

标签 spring-boot redis spring-data-redis

我有一个使用 Jedis 进行 redis 集群配置的 spring boot 项目。配置文件如下:

application.yml 文件:

enter image description here

RedisClusterConfig.java 文件:

@Configuration

公共(public)类 RedisClusterConfig {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Value("${redis.cluster.host1}") private String HOST1;
@Value("${redis.cluster.port1}") private Integer PORT1;

@Value("${redis.cluster.host2}") private String HOST2;
@Value("${redis.cluster.port2}") private Integer PORT2;

@Value("${redis.cluster.host3}") private String HOST3;
@Value("${redis.cluster.port3}") private Integer PORT3;

@Value("${redis.cluster.host4}") private String HOST4;
@Value("${redis.cluster.port4}") private Integer PORT4;

@Value("${redis.cluster.host5}") private String HOST5;
@Value("${redis.cluster.port5}") private Integer PORT5;

@Value("${redis.cluster.host6}") private String HOST6;
@Value("${redis.cluster.port6}") private Integer PORT6;

@Bean
public JedisCluster jedisCluster() {
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    //Jedis Cluster will attempt to discover cluster nodes automatically
    jedisClusterNodes.add(new HostAndPort(HOST1, PORT1));
    jedisClusterNodes.add(new HostAndPort(HOST2, PORT2));
    jedisClusterNodes.add(new HostAndPort(HOST3, PORT3));

    if(StringUtils.isNotBlank(HOST4)){
        jedisClusterNodes.add(new HostAndPort(HOST4, PORT4));
    }else{
        logger.warn("jedis cluster HOST4 not configured.");
    }

    if(StringUtils.isNotBlank(HOST5)){
        jedisClusterNodes.add(new HostAndPort(HOST5, PORT5));
    }else{
        logger.warn("jedis cluster HOST5 not configured.");
    }

    if(StringUtils.isNotBlank(HOST6)){
        jedisClusterNodes.add(new HostAndPort(HOST6, PORT6));
    }else{
        logger.warn("jedis cluster HOST6 not configured.");
    }
    JedisCluster jc = new JedisCluster(jedisClusterNodes, new JedisPoolConfig());
    return jc;
}

}

使用此配置,一切正常。我可以向 Redis 集群写入数据/从 Redis 集群读取数据。但是当我访问http://localhost:64001/health时获取执行器健康状态,返回结果如下:

{"status":"DOWN","diskSpace":{"status":"UP","total":120031539200,"free":33381117952,"threshold":10485760},"redis":{"status":"DOWN","error":"org.springframework.data.redis.RedisConnectionFailureException: 无法获取 Jedis 连接;嵌套异常为 redis.clients.jedis.exceptions.JedisConnectionException: 无法从池中获取资源"} ,"mongo":{"status":"UP","version":"3.2.3"},"db":{"status":"UP","dataSource1":{"status":"UP","database":"MySQL","hello":1},"dataSource2":{"status":"UP","database":"MySQL","hello":1},"dataSource3":{"状态":"UP","数据库":"MySQL","hello":1}}}

我们可以看到Jedis的错误提示。

顺便说一句,pom.xml中的相关依赖:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.RELEASE</version>
</parent>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

为了让/health 状态恢复到“UP”,我可能会错过任何事情吗?谢谢!

更多信息: 我跟踪启动发现RedisHealthIndicator传递了一个错误的工厂,host=localhost,port=6379,这应该是配置的集群主机和端口?

public RedisHealthIndicator(RedisConnectionFactory connectionFactory) {
    Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
    this.redisConnectionFactory = connectionFactory;
}

最佳答案

最后,我通过重新配置redis解决了问题,如下:

Spring : 雷迪斯: 簇: 节点: - 192.168.0.17:6390 - 192.168.0.17:6391 - 192.168.0.17:6392 - 192.168.0.9:6390 - 192.168.0.9:6391 - 192.168.0.9:6392

关于spring-boot - Spring Boot执行器: Why is the Health status of Redis cluster not correct?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38757483/

相关文章:

node.js - 如何设置带环回的 redis 快速 session 存储?

python - Celery:接收到类型为 <AsyncResult: [hash]> 的未注册任务

MongoDB 缓存或不缓存使用 Redis

spring - 千分尺发送指标为零 - Spring Boot

gradle - 无法开始使用 Spring Boot 和 Gradle

java - 创建 Java Spring Boot 端点以获取 json 形式的对象列表

java - Spring data Jpa 与 Spring Jdbc 用于查找表

redis sismember 检查多用户在线

java - 即使值存在,也无法单独从 Redis 加载值

java - 如何设置在spring boot中使用的redis数据库编号