Reputation: 1308
I have a spring boot project with redis cluster configuration using Jedis. The config files are as follows:
application.yml file:
RedisClusterConfig.java file:
@Configuration
public class 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;
}
}
With this config, everything works fine. I can write/read data to/from the redis cluster. But when I access http://localhost:64001/health to get the actuator health status, it returns the result as follows:
{"status":"DOWN","diskSpace":{"status":"UP","total":120031539200,"free":33381117952,"threshold":10485760},"redis":{"status":"DOWN","error":"org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool"},"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":{"status":"UP","database":"MySQL","hello":1}}}
We can see the error hints about Jedis.
BTW, the related dependencies in 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>
Is there any thing I may miss to get the /health status back to "UP"? Thanks!
More info: I traced the startup and found that the RedisHealthIndicator passed a wrong factory with host=localhost and port=6379, which should be the configured cluster hosts and ports?
public RedisHealthIndicator(RedisConnectionFactory connectionFactory) {
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
this.redisConnectionFactory = connectionFactory;
}
Upvotes: 2
Views: 11657
Reputation: 1308
Finally, I got the problem solved by re-config the redis as follows:
spring:
redis:
cluster:
nodes:
- 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
Upvotes: 2