gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 06:11:13 27 4
gpt4 key购买 nike

我有一个使用 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 集群写入/读取数据。但是当我访问 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"“数据库”:“MySQL”,“你好”:1},“数据源2”:{“状态”:“UP”,“数据库”:“MySQL”,“你好”:1},“数据源3”:{“status":"UP","database":"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传递了一个错误的factory,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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com