1)重启之前先修改redis.conf配置文件,添加连接主服务的认证密码即可
[root@localhost ~]# vim /app/redis/etc/redis.conf
masterauth 123456
2)在重启host1的redis服务
[root@localhost ~]# redis-server /app/redis/etc/redis.conf
3)查看其所处的状态,可以看到被切换的从服务
127.0.0.1:6379> info replication
#Replication
role:slave
master_host:192.168.1.106 #主服务指向host2
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:1829345
slave_priority:100
slave_read_only:1
……
……
9.在查看host2被提升为新的主后的连接状态
127.0.0.1:6379> info replication
#Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.110,port=6379,state=online,offset=1854211,lag=0
slave1:ip=192.168.1.9,port=6379,state=online,offset=1854072,lag=1
master_replid:7c8eb18c7c05b8f2d9f29028d016f9c40e8c2ce0
master_replid2:a8efce354ba8249ff264dcba60ac21030253b829
master_repl_offset:1854211
second_repl_offset:63848
……
……
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx