redis集群搭建中遇到的一些问题

redis单机模式启动后,修改完配置文件,使用如下命令建立redis集群:html

sudo ./src/redis-trib.rb create --replicas 1 ip1:6379 ip2:6379 ip3:6379

结果报错:node

>>> Creating cluster
[ERR] Sorry, can't connect to node ip1:6379

在网上查找资料发现,可能有如下几种缘由:redis

1.ruby的版本过低。sql

2.关闭redis的保护模式。缓存

3.redis的配置文件中bind的ip须要时外网ip,127.0.0.1不行,确保外网能telnet通。ruby

4.在将redis写入注册表时,开启了redis的密码模式,也会致使这个问题,须要关闭密码模式。bash

以上几种方法对应完了,这个错误就没有了。服务器

 

接着报了第二个错:app

[ERR] Node ip2:6379 is not configured as a cluster node.

缘由是第二台redis服务器没有开启集群模式,修改第二台服务器的redis的配置文件:nosql

cluster-enabled yes

appendonly yes

 

 

修改完了以后,重启第二台redis服务时报了这个错:

14652:M 21 Feb 18:26:50.758 # Sorry, the cluster configuration file nodes.conf is already used by a different Redis Cluster node.
Please make sure that different nodes use different cluster configuration files.

改变这台redis的配置文件指向的nodes.conf文件便可。

 

再记录几个redis下经常使用的命令:

#查看redis版本
./src/redis-server -v   

#启动redis服务
sudo ./src/redis-server ./redis.config

#中止redis服务的两种方式:
#第一种:
sudo ./src/redis-cli -h 127.0.0.1 -p 6379 shutdown
#第二种:
#进入redis-cli,而后用shutdown命令中止

#查看集群状况:
redis-cli -h ip -p 6379 cluster nodes

#查看集群信息:
172.30.1.160:6379> cluster nodes

#添加节点:
redis-trib.rb add-node --slave --master-id 08525dd167adbfe4b11b8b8e598efde2de11f31e slaveIp:6380 masterIp:6379 

 

 

redis集群会常常出错,使用cluster nodes命令和redis-trid.rb check命令查询到的集群状态信息不对,删掉节点以后,在集群状态信息中还有记录,各类办法都没办法解决问题,好在是实验环境,就干掉整个集群,从新装了。集群的缓存信息会存在三种文件里:node.conf配置文件,dump.rdb,appendonly.aof。删掉三个文件,从新建立集群便可。 

 

 

建立集群中还报过这个错误,删除了三种缓存文件仍是不行,最后登入每一个节点用flushall和cluster reset命令解决了。

/usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis/client.rb:113:in `call': ERR Slot 12182 is already busy (Redis::CommandError)
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2556:in `method_missing'
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2555:in `method_missing'
from ./src/redis-trib.rb:212:in `flush_node_config'
from ./src/redis-trib.rb:776:in `flush_nodes_config'
from ./src/redis-trib.rb:775:in `each'
from ./src/redis-trib.rb:775:in `flush_nodes_config'
from ./src/redis-trib.rb:1296:in `create_cluster_cmd'
from ./src/redis-trib.rb:1696:in `send'
from ./src/redis-trib.rb:1696

 

建立集群的时候,一直卡在Waiting for the cluster to join.....这一步,先删除三种文件:node.conf配置文件,dump.rdb,appendonly.aof;再把iptables关闭:sudo service iptables stop

 

转载请标明出处: http://www.cnblogs.com/gaojiang/p/6427693.html 

 

 

再附几个查找资料过程当中发现几篇比较好的帖子:

从集群的原理到搭建,讲的比较透彻:

http://shift-alt-ctrl.iteye.com/blog/2284890

主要讲了对redis集群的一些操做命令:

http://blog.51yip.com/nosql/1726.html

分析了搭建集群可能出错的缘由:

https://my.oschina.net/u/2277929/blog/727734

相关文章
相关标签/搜索