目录
1、redis解压包make报错
2、redis requires Ruby version >= 2.2.2
3、Waiting for the cluster to join...
4、[ERR] Node xxx is not empty. Either the node already knows other no...
编译redis的tar.gz时候,先安装 c++相关包,需要先执行命令 :
yum install gcc-c++安装redis的时候,很多教程都是让直接执行 yum install ruby, 但是Centos7的yum 支持的ruby版本为2.0.0,再执行gem install redis 时,就会报这个错。则需要提升ruby的版本,有如下三种方式(具体可参见http://www.cnblogs.com/ding2016/p/7903147.html):
1)、重新指定安装源(我用了这种方式,比较简单)
yum install centos-release-scl-rh # 会在/etc/yum.repos.d/目录下多出一个CentOS-SCLo-scl-rh.repo源
yum install rh-ruby23 -y # yum安装ruby
scl enable rh-ruby23 bash # 必要一步
ruby -v # 查看安装版本
2)、可以使用 离线下载ruby包的形式安装
3)、先安装rvm,再升级ruby
一定不要用rvm方式安装,坑死了,后面还有很多问题。
[root@localhost src]# ./redis-trib.rb create --replicas 1 192.168.31.220:7001 192.168.31.220:7002 192.168.31.147:7003 192.168.31.147:7004 192.168.31.109:7005 192.168.31.109:7006 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.31.220:7001 192.168.31.147:7003 192.168.31.109:7005 Adding replica 192.168.31.147:7004 to 192.168.31.220:7001 Adding replica 192.168.31.220:7002 to 192.168.31.147:7003 Adding replica 192.168.31.109:7006 to 192.168.31.109:7005 M: 94fbbeba149e6a2173f5bdca67172c146a905895 192.168.31.220:7001 slots:0-5460 (5461 slots) master S: c511fa8328b339f56d4be1b028ecef731ea909f0 192.168.31.220:7002 replicates ce9c7eba97475450332a121843ec3a125efe1dcd M: ce9c7eba97475450332a121843ec3a125efe1dcd 192.168.31.147:7003 slots:5461-10922 (5462 slots) master S: 987d268f8172305942c5b18ead8fafa03d359eef 192.168.31.147:7004 replicates 94fbbeba149e6a2173f5bdca67172c146a905895 M: ca14e60a255922b4e05a02361e8476b4310422d3 192.168.31.109:7005 slots:10923-16383 (5461 slots) master S: eb085c7254ec3a04a3941282c7b465baccea9d4d 192.168.31.109:7006 replicates ca14e60a255922b4e05a02361e8476b4310422d3 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.................................... ........................................................
执行ruby命令组成集群时,集群之间会通过总线端口(节点端口+1000为总线端口,如当前节点的端口为7001则该总线端口为17001)进行通信,若各服务器之前的端口的防火墙没有打开则会一直处理 join 中。需要关闭防火墙,或者打开防火墙端口,一般生产环境最好不要关闭防火墙,则在每台服务器执行命令:
firewall-cmd --zone=public --add-port=7001/tcp --permanent
由于上一步没有打开端口就去执行 ./redis-trib.rb create --replicas 1 命令,后面我直接用 Ctrl + c关闭了上一步,开启端口后,又去执行上面的命令时,就会出现该问题。需要执行以下步骤:
1)、删除每个redis节点的备份文件,数据库文件和集群配置文件
包括appendonly.aof、dump.rdb、node_xxx.conf等信息,需要根据每个节点的 redis.conf 配置文件的配置位置去删除,我这边只删除了dir目录下的文件就ok了,如下:
dir /usr/local/redis-cluster/redis-1/7001 # 文件夹下创建的信息等,也需要进行删除
2)、使用redis-cli 命令为每个节点执行以下命令
先使用命令 ./redis-cli -c -h 192.168.31.1 -p 7001 方式链接到每一个节点,再执行:
flushdb
cluster reset
3)、最后再去执行刚才的 ./redis-trib.rb命令