连接redis集群报错: no reachable node in cluster

今天在连接redis集群时遇到个问题,试了很多方案也没解决。
就是连接redis集群老是报错: no reachable node in cluster。
后来改了一些参数,就可以调通了。
废话不多说,直接上解决步骤:
1.先确保redis集群现在已经安装完成了,那就先重启redis节点,至少重启一半以上的redis节点,例子1:
重启 redis节点:
redis-cli -h 192.168.51.xxx -p 7000 -a redis@123 shutdown
//这里ip换成你自己的内网ip,
// -a 表示用什么账户,密码连接redis
cd /usr/local/7000/
redis-server redis.conf &

2.再次在linux控制台尝试连接redis节点
连接 redis 节点,查询数据:
redis-cli -c -h 192.168.51.xxx -p 7000 -a redis@123
keys *
quit

3.测试是否可以连上这个 redis 节点 的端口:
telnet 192.168.51.208 7003
telnet 192.168.51.208 17003

4.检查防火墙,代理端口映射,是否已经打开了redis使用的端口号,必须放行

5.使用 RedisDesktopManager
下载: http://www.downza.cn/soft/210734.html
安装该redis客户端,测试链接redis的ip和端口号,看看到底是不是能连上redis集群

6.使用连接成功的 ip,端口号
在代码中输入以下测试代码,测试redis集群是否可以正常的使用了

 
public class Test {
	  public static void main(String[] args) throws Exception { 
		  testRedisCluster ( null ) ;
	    }

	//连接 redisCluster(集群模式)
	static JedisCluster cluster ;
	public static void testRedisCluster( ApplicationContext app  ) {
		JedisPoolConfig poolConfig = new JedisPoolConfig();
		// 最大连接数
		poolConfig.setMaxTotal(10000);
		// 最大空闲数
		poolConfig.setMaxIdle(1000);
		// 最大允许等待时间,如果超过这个时间还未获取到连接,则会报JedisException异常:
		// Could not get a resource from the pool
		poolConfig.setMaxWaitMillis(3000);
		poolConfig.setTestOnBorrow(true);
		Set<HostAndPort> nodes = new LinkedHashSet<HostAndPort>();
		nodes.add(new HostAndPort("192.168.51.xxx" ,7000 ));//换自己的内网IP
		nodes.add(new HostAndPort("192.168.51.xxx" ,7001 ));
		nodes.add(new HostAndPort("192.168.51.xxx" ,7002 ));
		nodes.add(new HostAndPort("192.168.51.xxx" ,7003 ));
		nodes.add(new HostAndPort("192.168.51.xxx" ,7004 ));
		nodes.add(new HostAndPort("192.168.51.xxx" ,7005 ));
//		cluster = new JedisCluster(nodes, poolConfig  );//		cluster = new JedisCluster(nodes, 5000 , 1000);  //		cluster = new JedisCluster( nodes, 2000, 5, 8, "redis@123", new GenericObjectPoolConfig() );//		cluster.auth("redis@123") ;
//		cluster = app.getBean(JedisCluster.class) ;
		cluster = new JedisCluster( nodes, 3000, 3000, 8, "redis@123", poolConfig );
		String name = cluster.get("name");
		System.out.println(name);
		cluster.set("age", "18");
		System.out.println(cluster.get("age"));
		try {
			cluster.close();
		} catch ( Exception e) {
			e.printStackTrace();
		}
	}
}

7.大功告成!
感觉有用的伙伴点下关注或者赞嘛,谢谢了。有什么不足也欢迎大家指出。
(
另外附带上linux两个常用指令:
linux查看磁盘剩余空间: df -lh
linux查ip: ifconfig -a
)

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值