目录
- 一、简介
- 二、架构图
- 三、搭建集群
- 3.1、下载
- 3.2、编译安装
- 3.3、配置文件修改
- 3.4、创建集群
- 四、集群管理工具redis-cli
- 4.1、查看集群信息
- 4.2、检查集群
- 4.3、修复槽错误
- 4.4、重分片
- 4.5、负载均衡
- 4.6、添加节点
- 4.7、删除节点
- 4.8、设置超时
- 4.9、导入数据
- 4.10、重建集群
一、简介
本文今天主要是Redis集群相关的知识,Redis集群是从3.0版本开始引入的功能,本文中的版本是5.0.14我们大概讲下集群的搭建,以及集群命令的用法。
二、架构图
我们来个最简单的集群架构,如下图:
三、搭建集群
3.1、下载
我这里是linux一台服务器上搭建的集群,实际中不建议,非常不安全,这里只是演示,我们应该确保每个redis服务在不同的服务器上。
#下载redis-5.0.14
[root@Alian-ECS ~]# wget http://download.redis.io/releases/redis-5.0.14.tar.gz
#解压压缩包
[root@Alian-ECS ~]# tar -zxvf redis-5.0.14.tar.gz
#复制到部署目录
[root@Alian-ECS ~]# cp -r redis-5.0.14 /usr/local
#进入redis的目录
[root@Alian-ECS ~]# cd /usr/local/redis-5.0.14
[root@Alian-ECS redis-5.0.14]# ll
总用量 288
-rw-r--r-- 1 root root 127554 2月 7 13:59 00-RELEASENOTES
-rw-r--r-- 1 root root 53 2月 7 13:59 BUGS
-rw-r--r-- 1 root root 2381 2月 7 13:59 CONTRIBUTING
-rw-r--r-- 1 root root 1487 2月 7 13:59 COPYING
drwxr-xr-x 6 root root 192 2月 7 14:01 deps
-rw-r--r-- 1 root root 11 2月 7 13:59 INSTALL
-rw-r--r-- 1 root root 151 2月 7 13:59 Makefile
-rw-r--r-- 1 root root 6888 2月 7 13:59 MANIFESTO
-rw-r--r-- 1 root root 20555 2月 7 13:59 README.md
-rw-r--r-- 1 root root 63088 2月 7 13:59 redis.conf
-rwxr-xr-x 1 root root 275 2月 7 13:59 runtest
-rwxr-xr-x 1 root root 280 2月 7 13:59 runtest-cluster
-rwxr-xr-x 1 root root 373 2月 7 13:59 runtest-moduleapi
-rwxr-xr-x 1 root root 281 2月 7 13:59 runtest-sentinel
-rw-r--r-- 1 root root 9710 2月 7 13:59 sentinel.conf
drwxr-xr-x 3 root root 8192 2月 7 14:13 src
drwxr-xr-x 11 root root 182 2月 7 13:59 tests
drwxr-xr-x 8 root root 4096 2月 7 13:59 utils
3.2、编译安装
接下里我们进入到src目录,分别执行编译和安装命令,并拷贝编译后的文件
#进入源码目录
[root@Alian-ECS redis-5.0.14]# cd src
#编译(确保linux上安装有gcc)
[root@Alian-ECS src]# make
#编译安装
[root@Alian-ECS src]# make install
#进入到redis目录
[root@Alian-ECS src]# cd /usr/local/redis-5.0.14
#新建目录
[root@Alian-ECS redis-5.0.14]# mkdir bin
#拷贝复制
[root@Alian-ECS redis-5.0.14]# cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server redis-sentinel /usr/local/redis-5.0.14/bin
#查看拷贝的文件
[root@Alian-ECS redis-5.0.14]# ll bin
总用量 53300
-rwxr-xr-x 1 root root 735 2月 7 14:28 mkreleasehdr.sh
-rwxr-xr-x 1 root root 6018304 2月 7 14:28 redis-benchmark
-rwxr-xr-x 1 root root 10501736 2月 7 14:28 redis-check-aof
-rwxr-xr-x 1 root root 10501736 2月 7 14:28 redis-check-rdb
-rwxr-xr-x 1 root root 6542120 2月 7 14:28 redis-cli
-rwxr-xr-x 1 root root 10501736 2月 7 14:28 redis-sentinel
-rwxr-xr-x 1 root root 10501736 2月 7 14:28 redis-server
3.3、配置文件修改
为了简单,我们把端口定义为7001、7002、7003、7004、7005、7006,我们创建6个文件夹
[root@Alian-ECS redis-5.0.14]# mkdir 7001 7002 7003 7004 7005 7006
[root@Alian-ECS redis-5.0.14]# vim redis.conf
修改如下:
- protected-mode:no(关闭保护模式,不然无法同步)
- port:7001(redis服务的端口)
- daemonize:yes(守护进程)
- pidfile:/usr/local/redis-5.0.14/7001/redis_7001.pid(pid文件)
- logfile:/usr/local/redis-5.0.14/7001/redis_7001.log(日志文件)
- dir:/usr/local/src/redis5.0.0/7001(同步的备份文件目录)
- appendonly:yes(AOF同步)
- cluster-enabled:yes(开启集群)
- cluster-config-file:nodes-7001.conf(集群配置文件服务自动读写)
至此,我们一个服务的配置就改好了,我们把它考到之前创建的6个目录中,然后批量修改即可,如下:
[root@Alian-ECS redis-5.0.14]# cp redis.conf 7001
[root@Alian-ECS redis-5.0.14]# cp redis.conf 7002
[root@Alian-ECS redis-5.0.14]# cp redis.conf 7003
[root@Alian-ECS redis-5.0.14]# cp redis.conf 7004
[root@Alian-ECS redis-5.0.14]# cp redis.conf 7005
[root@Alian-ECS redis-5.0.14]# cp redis.conf 7006
#批量修改为对应的服务需要的配置(比如把7001都替换为7002)
[root@Alian-ECS redis-5.0.14]# sed -i 's/7001/7002/g' 7002/redis.conf
[root@Alian-ECS redis-5.0.14]# sed -i 's/7001/7003/g' 7003/redis.conf
[root@Alian-ECS redis-5.0.14]# sed -i 's/7001/7004/g' 7004/redis.conf
[root@Alian-ECS redis-5.0.14]# sed -i 's/7001/7005/g' 7005/redis.conf
[root@Alian-ECS redis-5.0.14]# sed -i 's/7001/7006/g' 7006/redis.conf
[root@Alian-ECS redis-5.0.14]#
然后我们,把这两个服务都启动起来
[root@Alian-ECS redis-5.0.14]# bin/redis-server 7001/redis.conf
[root@Alian-ECS redis-5.0.14]# bin/redis-server 7002/redis.conf
[root@Alian-ECS redis-5.0.14]# bin/redis-server 7003/redis.conf
[root@Alian-ECS redis-5.0.14]# bin/redis-server 7004/redis.conf
[root@Alian-ECS redis-5.0.14]# bin/redis-server 7005/redis.conf
[root@Alian-ECS redis-5.0.14]# bin/redis-server 7006/redis.conf
[root@Alian-ECS redis-5.0.14]# ps -ef|grep redis
root 2979640 1 0 15:48 ? 00:00:00 bin/redis-server 127.0.0.1:7001 [cluster]
root 2980332 1 0 15:49 ? 00:00:00 bin/redis-server 127.0.0.1:7002 [cluster]
root 2980507 1 0 15:49 ? 00:00:00 bin/redis-server 127.0.0.1:7003 [cluster]
root 2980702 1 0 15:49 ? 00:00:00 bin/redis-server 127.0.0.1:7004 [cluster]
root 2980857 1 0 15:49 ? 00:00:00 bin/redis-server 127.0.0.1:7005 [cluster]
root 2980977 1 0 15:49 ? 00:00:00 bin/redis-server 127.0.0.1:7006 [cluster]
root 2981097 2735921 0 15:49 pts/0 00:00:00 grep --color=auto redis
至此,我们的服务也启动了,不过现在还不是集群模式。
3.4、创建集群
通过redis-cli命令创建集群
redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003
127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
- cluster-replicas 这个参数就是说明副本数,这里是1,也就是每个主节点的从节点数量是1
[root@Alian-ECS bin]# redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 127.0.0.1:7005 to 127.0.0.1:7001
Adding replica 127.0.0.1:7006 to 127.0.0.1:7002
Adding replica 127.0.0.1:7004 to 127.0.0.1:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 5df6e4e6acefc3045d98f1a3207168e8007f6288 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
M: fb0383882cfb2b1e219b822d5f3a46cad8ed624e 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
M: 48b9419d7e772f71273347dc557a3ef07edb67a9 127.0.0.1:7003
slots:[10923-16383] (5461 slots) master
S: 4d40e49d2d8602fb335b16c3cf8c425e7317049e 127.0.0.1:7004
replicates 48b9419d7e772f71273347dc557a3ef07edb67a9
S: 6979395e0eadb9a252ce80f61ed4b3b1ec1cccf0 127.0.0.1:7005
replicates 5df6e4e6acefc3045d98f1a3207168e8007f6288
S: 4822ef8b239c5f3f00c71cca00f7636ba7fa60e3 127.0.0.1:7006
replicates fb0383882cfb2b1e219b822d5f3a46cad8ed624e
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
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 5df6e4e6acefc3045d98f1a3207168e8007f6288 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 4822ef8b239c5f3f00c71cca00f7636ba7fa60e3 127.0.0.1:7006
slots: (0 slots) slave
replicates fb0383882cfb2b1e219b822d5f3a46cad8ed624e
S: 6979395e0eadb9a252ce80f61ed4b3b1ec1cccf0 127.0.0.1:7005
slots: (0 slots) slave
replicates 5df6e4e6acefc3045d98f1a3207168e8007f6288
M: fb0383882cfb2b1e219b822d5f3a46cad8ed624e 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 4d40e49d2d8602fb335b16c3cf8c425e7317049e 127.0.0.1:7004
slots: (0 slots) slave
replicates 48b9419d7e772f71273347dc557a3ef07edb67a9
M: 48b9419d7e772f71273347dc557a3ef07edb67a9 127.0.0.1:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@Alian-ECS bin]#
询问是否确认分配slot的方案,我选择yes
四、集群管理工具redis-cli
4.1、查看集群信息
集群搭建完成后,我们可以通过 cluster 选项的 info 子命令查看集群的相关信息,但是需要提供集群中任意一个节点的地址作为参数。
语法
redis-cli --cluster info ip:port
使用
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (5df6e4e6...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7002 (fb038388...) -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:7003 (48b9419d...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
[root@Alian-ECS redis-5.0.14]#
4.2、检查集群
拥有集群后,我们可以通过 cluster 选项的 check 子命令查看集群 16384 个槽是否全部指派给了主节点,但是需要提供集群中任意一个节点的地址作为参数。
语法
redis-cli --cluster check ip:port
使用
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster check 127.0.0.1:7001
127.0.0.1:7001 (5df6e4e6...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7002 (fb038388...) -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:7003 (48b9419d...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 5df6e4e6acefc3045d98f1a3207168e8007f6288 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 4822ef8b239c5f3f00c71cca00f7636ba7fa60e3 127.0.0.1:7006
slots: (0 slots) slave
replicates fb0383882cfb2b1e219b822d5f3a46cad8ed624e
S: 6979395e0eadb9a252ce80f61ed4b3b1ec1cccf0 127.0.0.1:7005
slots: (0 slots) slave
replicates 5df6e4e6acefc3045d98f1a3207168e8007f6288
M: fb0383882cfb2b1e219b822d5f3a46cad8ed624e 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 4d40e49d2d8602fb335b16c3cf8c425e7317049e 127.0.0.1:7004
slots: (0 slots) slave
replicates 48b9419d7e772f71273347dc557a3ef07edb67a9
M: 48b9419d7e772f71273347dc557a3ef07edb67a9 127.0.0.1:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@Alian-ECS redis-5.0.14]#
比如我们使用 cluster delslots slot [slot] 来撤销对节点槽的指派,则检查就会报错
#撤销对7001节点槽0,1,2,3,4的指派
127.0.0.1:7001> cluster delslots 0 1 2 3 4 5
OK
127.0.0.1:7001> cluster slots
1) 1) (integer) 6
2) (integer) 5460
3) 1) "127.0.0.1"
2) (integer) 7001
3) "5df6e4e6acefc3045d98f1a3207168e8007f6288"
4) 1) "127.0.0.1"
2) (integer) 7005
3) "6979395e0eadb9a252ce80f61ed4b3b1ec1cccf0"
2) 1) (integer) 5461
2) (integer) 10922
3) 1) "127.0.0.1"
2) (integer) 7002
3) "fb0383882cfb2b1e219b822d5f3a46cad8ed624e"
4) 1) "127.0.0.1"
2) (integer) 7006
3) "4822ef8b239c5f3f00c71cca00f7636ba7fa60e3"
3) 1) (integer) 10923
2) (integer) 16383
3) 1) "127.0.0.1"
2) (integer) 7003
3) "48b9419d7e772f71273347dc557a3ef07edb67a9"
4) 1) "127.0.0.1"
2) (integer) 7004
3) "4d40e49d2d8602fb335b16c3cf8c425e7317049e"
127.0.0.1:7001>
我们再次检查如下
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster check 127.0.0.1:7001
127.0.0.1:7001 (5df6e4e6...) -> 1 keys | 5455 slots | 1 slaves.
127.0.0.1:7002 (fb038388...) -> 1 keys | 5462 slots | 1 slaves.
127.0.0.1:7003 (48b9419d...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 2 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 5df6e4e6acefc3045d98f1a3207168e8007f6288 127.0.0.1:7001
slots:[6-5460] (5455 slots) master
1 additional replica(s)
S: 4822ef8b239c5f3f00c71cca00f7636ba7fa60e3 127.0.0.1:7006
slots: (0 slots) slave
replicates fb0383882cfb2b1e219b822d5f3a46cad8ed624e
S: 6979395e0eadb9a252ce80f61ed4b3b1ec1cccf0 127.0.0.1:7005
slots: (0 slots) slave
replicates 5df6e4e6acefc3045d98f1a3207168e8007f6288
M: fb0383882cfb2b1e219b822d5f3a46cad8ed624e 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 4d40e49d2d8602fb335b16c3cf8c425e7317049e 127.0.0.1:7004
slots: (0 slots) slave
replicates 48b9419d7e772f71273347dc557a3ef07edb67a9
M: 48b9419d7e772f71273347dc557a3ef07edb67a9 127.0.0.1:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
[ERR] Nodes don't agree about configuration!
>>> Check for open slots...
>>> Check slots coverage...
[ERR] Not all 16384 slots are covered by nodes.
4.3、修复槽错误
如果是有槽未分配则可以通过 cluster 选项的 fix 命令去修复,比如上面的检查报错了
语法
redis-cli --cluster fix ip:port
使用
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster fix 127.0.0.1:7001
127.0.0.1:7001 (5df6e4e6...) -> 1 keys | 5455 slots | 1 slaves.
127.0.0.1:7002 (fb038388...) -> 1 keys | 5462 slots | 1 slaves.
127.0.0.1:7003 (48b9419d...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 2 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 5df6e4e6acefc3045d98f1a3207168e8007f6288 127.0.0.1:7001
slots:[6-5460] (5455 slots) master
1 additional replica(s)
S: 4822ef8b239c5f3f00c71cca00f7636ba7fa60e3 127.0.0.1:7006
slots: (0 slots) slave
replicates fb0383882cfb2b1e219b822d5f3a46cad8ed624e
S: 6979395e0eadb9a252ce80f61ed4b3b1ec1cccf0 127.0.0.1:7005
slots: (0 slots) slave
replicates 5df6e4e6acefc3045d98f1a3207168e8007f6288
M: fb0383882cfb2b1e219b822d5f3a46cad8ed624e 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 4d40e49d2d8602fb335b16c3cf8c425e7317049e 127.0.0.1:7004
slots: (0 slots) slave
replicates 48b9419d7e772f71273347dc557a3ef07edb67a9
M: 48b9419d7e772f71273347dc557a3ef07edb67a9 127.0.0.1:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
[ERR] Nodes don't agree about configuration!
>>> Check for open slots...
>>> Check slots coverage...
[ERR] Not all 16384 slots are covered by nodes.
>>> Fixing slots coverage...
List of not covered slots:
0,1,2,3,4,5
Slot 0 has keys in 0 nodes:
Slot 1 has keys in 0 nodes:
Slot 2 has keys in 0 nodes:
Slot 3 has keys in 0 nodes:
Slot 4 has keys in 0 nodes:
Slot 5 has keys in 0 nodes:
The following uncovered slots have no keys across the cluster:
2, 1, 0, 5, 3, 4
Fix these slots by covering with a random node? (type 'yes' to accept): yes
>>> Covering slot 2 with 127.0.0.1:7003
>>> Covering slot 1 with 127.0.0.1:7003
>>> Covering slot 0 with 127.0.0.1:7003
>>> Covering slot 5 with 127.0.0.1:7003
>>> Covering slot 3 with 127.0.0.1:7003
>>> Covering slot 4 with 127.0.0.1:7003
[root@Alian-ECS redis-5.0.14]#
4.4、重分片
通过 cluster 选项的 reshard 子命令,用户可以将指定数量的槽从原节点迁移到目标节点
语法
redis-cli --cluster reshard <ip>:<port>
--cluster-from <id> #源节点的ID
--cluster-to <id> #目标节点的ID
--cluster-slots <num> #要迁移的槽的数量
--cluster-yes #直接确认
--cluster-timeout <time> #迁移最大时限
--cluster-pipeline <yes/no> #是否使用流水线
比如:
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster reshard 127.0.0.1:7001 --cluster-from 48b9419d7e772f71273347dc557a3ef07edb67a9 -- cluster-to 5df6e4e6acefc3045d98f1a3207168e8007f6288 --cluster-slots 5
4.5、负载均衡
通过 cluster 选项的 rebalance 子命令,用户在有需要时重新分配各个节点的槽数量(相对均匀),从而让各个节点的负载趋于平衡。
语法
redis-cli --cluster rebalance <ip>:<port>
比如:
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster rebalance 127.0.0.1:7001
4.6、添加节点
通过 cluster 选项的 add-node 子命令,用户可以把新的节点添加到已有的集群当中,用户需要提供新的节点地址以及集群中某个节点的地址即可。
语法
redis-cli --cluster add-node <new-host>:<port> <existing-host>:<port>
上面添加的就是主节点,如果希望添加的是从节点,则添加如下参数
- –cluster-slave
- –cluster-master-id <id>
–cluster-slave表示是从节点,–cluster-master-id表示设置从节点将要复制的主节点的。
4.7、删除节点
当用户不再要集群中的某个节点的时候,可以通过 cluster 选项的 del-node 来移除该节点。
语法
redis-cli --cluster del-node <ip>:<port> <node_id>
这里的ip:port 就是集群的某个节点作为入口,node_id 就是用户要移除的节点ID,比如:
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster del-node 127.0.0.1:7001 4d40e49d2d8602fb335b16c3cf8c425e7317049e
4.8、设置超时
通过 cluster 选项的 set-timeout 子命令,用户可以为集群的所有节点重新设置 cluster-node-timeout 选项的值。
语法
redis-cli --cluster set-timeout <ip>:<port> <milliseconds>
比如:
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster set-timeout 127.0.0.1:7001 30000
4.9、导入数据
通过 cluster 选项的 import 子命令,用户可以将给定单机redis服务器的数据导入集群中。
语法
redis-cli --cluster import <node-host>:<port> # 集群入口的ip地址和端口
--cluster-from <id> <server-host>:<port> # 单机服务的ip地址和端口
--cluster-copy # 使用复制导入
--cluster-replace # 覆盖相同名称的键
比如:
[root@Alian-ECS redis-5.0.14]# bin/redis-cli --cluster import 127.0.0.1:7001 --cluster-from 127.0.0.1:7002 --cluster-copy --cluster-replace
4.10、重建集群
如果我们验证过程,可能不断的分片,添加或者删除节点,搞晕了,想重新构建集群该怎么操作呢?(重建集群操作生产上不要随便搞)
- 停止所有节点的服务
- 删除各个节点下的文件包括(nodes-*.conf、appendonly.aof、dump.rdb、*.log)
- 通过redis-cli工具重新构建集群
具体操作如下:
[root@Alian-ECS redis-5.0.14]# redis-cli -h 127.0.0.1 -p 7001 shutdown
[root@Alian-ECS redis-5.0.14]# redis-cli -h 127.0.0.1 -p 7002 shutdown
[root@Alian-ECS redis-5.0.14]# redis-cli -h 127.0.0.1 -p 7003 shutdown
[root@Alian-ECS redis-5.0.14]# redis-cli -h 127.0.0.1 -p 7004 shutdown
[root@Alian-ECS redis-5.0.14]# redis-cli -h 127.0.0.1 -p 7005 shutdown
[root@Alian-ECS redis-5.0.14]# redis-cli -h 127.0.0.1 -p 7006 shutdown
#删除
[root@Alian-ECS redis-5.0.14]# rm -f ./*/nodes-*.conf ./*/appendonly.aof ./*/dump.rdb ./*/*.log
[root@Alian-ECS bin]# redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
注意:我这里执行的目录是redis的安装目录,子节点目录分别是7001、7002、7003、7004、7005、7006,这里是用/*/表示,实际中,你们根据需要修改目录,或者一个个删除都行。