环境:
OS:Centos 7
redis版本:4.0.15
背景:原来是2个节点组成的3主3从的集群,现在想修改为3个节点组成的3组3从的集群
原来的集群部署拓扑:
192.168.56.111:7001
192.168.56.111:7002
192.168.56.111:7003
192.168.56.112:8001
192.168.56.112:8002
192.168.56.112:8003
新的集群部署拓扑(新增了一台机器):
192.168.56.111:7001
192.168.56.111:7002
192.168.56.112:8001
192.168.56.112:8002
192.168.56.113:9001
192.168.56.113:9002
1.停掉原来的集群的进程
192.168.56.111
/usr/local/services/redis/bin/redis-cli -h 192.168.56.111 -a 123456 -p 7001 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.111 -a 123456 -p 7002 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.111 -a 123456 -p 7003 shutdown
192.168.56.112
/usr/local/services/redis/bin/redis-cli -h 192.168.56.112 -a 123456 -p 8001 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.112 -a 123456 -p 8002 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.112 -a 123456 -p 8003 shutdown
2.删除data目录、log目录、pid目录下的文件
data目录
[root@rac01 redis_7001]# cd /home/middle/redis/data/redis_7001
[root@rac01 redis_7001]# rm *
[root@rac01 redis_7001]# cd /home/middle/redis/data/redis_7002
[root@rac01 redis_7002]# rm *
[root@rac01 redis_7001]# cd /home/middle/redis/data/redis_7003
[root@rac01 redis_7003]# rm *
log目录
[root@rac01 logs]# cd /home/middle/redis/logs
[root@rac01 logs]# rm *
pid目录
[root@rac01 run]# cd /home/middle/redis/run
[root@rac01 run]# rm *
另外一个节点也是类似这样操作
3.在新的节点上部署redis
省略
4.无密码验证启动每个节点的相应进程
注释掉配置文件的这两行
##masterauth "123456"
##requirepass "123456"
192.168.56.111
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/7001.conf
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/7002.conf
192.168.56.112
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/8001.conf
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/8002.conf
192.168.56.113
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/9001.conf
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/9002.conf
5.重新创建集群
在其中一个节点上执行即可,我这里是在节点1上执行
/usr/local/services/redis/redis-trib.rb create --replicas 1 192.168.56.111:7001 192.168.56.111:7002 192.168.56.112:8001 192.168.56.112:8002 192.168.56.113:9001 192.168.56.113:9002
6.登录集群查看节点信息
[root@rac01 conf]# /usr/local/services/redis/bin/redis-cli -c -h 192.168.56.111 -p 7001
192.168.56.111:7001> cluster nodes
dc143ebc77e6dafa666faed23bd81a4187b0b178 192.168.56.112:8001@18001 master - 0 1622441515899 3 connected 5461-10922
9d871b91a4d94c04a04626dfe16dfb6d4d0ac1fb 192.168.56.113:9001@19001 master - 0 1622441514393 5 connected 10923-16383
1c1c9f1f4bd82bc289c9e34b758b66ceb2651c47 192.168.56.111:7001@17001 myself,master - 0 1622441513000 1 connected 0-5460
a4539311f8c996c0089ff236265baba062d962dc 192.168.56.111:7002@17002 slave 9d871b91a4d94c04a04626dfe16dfb6d4d0ac1fb 0 1622441514895 5 connected
b637728301742ff6773a6f8f2d544d2c15b5325d 192.168.56.112:8002@18002 slave 1c1c9f1f4bd82bc289c9e34b758b66ceb2651c47 0 1622441515599 4 connected
17a64e68860f445446257541da8978a7861fd055 192.168.56.113:9002@19002 slave dc143ebc77e6dafa666faed23bd81a4187b0b178 0 1622441514393 6 connected
7.停掉集群各节点启用密码验证
/usr/local/services/redis/bin/redis-cli -h 192.168.56.111 -p 7001 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.111 -p 7002 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.112 -p 8001 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.112 -p 8002 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.113 -p 9001 shutdown
/usr/local/services/redis/bin/redis-cli -h 192.168.56.113 -p 9002 shutdown
重新启动
192.168.56.111
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/7001.conf
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/7002.conf
192.168.56.112
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/8001.conf
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/8002.conf
192.168.56.113
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/9001.conf
/usr/local/services/redis/bin/redis-server /home/middle/redis/conf/9002.conf
重新查看集群节点情况
/usr/local/services/redis/bin/redis-cli -c -h 192.168.56.111 -p 7001 -a 123456