最近在搭建Redis高性能集群时,报如下错误
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" redis.clients.jedis.exceptions.JedisNoReachableClusterNodeException: No reachable node in cluster
at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnection(JedisSlotBasedConnectionHandler.java:61)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:78)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:102)
at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:25)
at redis.clients.jedis.JedisCluster.set(JedisCluster.java:112)
at com.rpc.demo.XXX.main(XXX.java:30)
Process finished with exit code 1
根据错误提示
第一,需要导入slf4j的jar包和依赖包
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.3</version> </dependency>
第二,导入jar包以后,还报
Exception in thread "main" redis.clients.jedis.exceptions.JedisNoReachableClusterNodeException: No reachable node in cluster这个错误?
这是为什么呢?
测试原代码是
package com.rpc.demo.util;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;
/**
⦁ 访问redis集群
⦁ @author zsf
⦁
*/
public class RedisCluster
{
public static void main(String[] args) throws IOException {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("192.168.213.131", 8001));
jedisClusterNode.add(new HostAndPort("192.168.213.131", 8002));
jedisClusterNode.add(new HostAndPort("192.168.213.131", 8003));
jedisClusterNode.add(new HostAndPort("192.168.213.131", 8004));
jedisClusterNode.add(new HostAndPort("192.168.213.131", 8005));
jedisClusterNode.add(new HostAndPort("192.168.213.131", 8006));
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(100);
config.setMaxIdle(10);
config.setTestOnBorrow(true);
JedisCluster jedisCluster = new JedisCluster(jedisClusterNode, 6000, 10,
config);
System.out.println(jedisCluster.set("student", "zsf"));
System.out.println(jedisCluster.set("age", "18"));
System.out.println(jedisCluster.get("student"));
System.out.println(jedisCluster.get("age"));
jedisCluster.close();
}
}
试了网上好多方法,都不行,这是什么原因呢?
试了试,能不能拼通吧,ping 192.168.213.131,能拼通!
突然想起,是不是192.168.213.131这台机器上防火墙,没有放开端口啊?机器上安装是centos7,于是把防火墙直接关了。
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# firewall-cmd --state
然后再运行,居然好了!
本文详细解析了在搭建Redis高性能集群过程中遇到的连接失败问题,包括SLF4J日志框架配置错误及JedisNoReachableClusterNodeException异常的解决方法,通过正确引入依赖、配置防火墙等步骤,最终成功实现集群的稳定连接。
3508

被折叠的 条评论
为什么被折叠?



