1、停止主Redis(模仿主机挂掉)
/usr/local/redis6/bin/redis-cli -a "dianshang" -h 192.168.x.x -p 7020 shutdown
2、将从Redis 设成主Redis
/usr/local/redis6/bin/redis-cli -a "dianshang" -h 192.168.x.x -p 7010 slaveof NO ONE
3、查看从节点role: 已经变成master,或者 set 一个数据是否成功
/usr/local/redis6/bin/redis-cli -a "dianshang" -h 192.168.x.x -p 7010 info replication
4、原来的主redis恢复正常了(7020端口),要重新切换回去,将现在的主redis的数据进行保存(7010 端口)
4.1)/usr/local/redis6/bin/redis-cli -a "dianshang" -h 192.168.x.x -p 7010 save
4.2)将现在(7010端口)的主redis根目录下dump.rdb文件拷贝覆盖到原来主redis(7020端口)的根目录
cp -a /var/redis/7010/dump.rdb /var/redis/7020/dump.rdb
4.3) 启动原来的主redis(7020端口)
/usr/local/redis6/bin/redis-server /etc/redis6/node-7020.conf
4.4)从 7010端口节点切换主节点为(7020端口节点)
/usr/local/redis6/bin/redis-cli -a "dianshang" -h 192.168.x.x -p 7010 slaveof 192.168.x.x 7020
4.5)再次查看7010端口节点详细信息已经变为slave 节点
/usr/local/redis6/bin/redis-cli -a "dianshang" -h 192.168.x.x -p 7010 info replication
标签:Redis,redis6,redis,192.168,7020,切换,local,主从,7010 From: https://www.cnblogs.com/zbhlinux/p/17341737.html