Redis的主从同步手动执行故障切换

1.准备三个redis配置文件,通过端口的区分,启动三个redis数据库实例,然后配置主从复制.

# a6371.conf
port 6371
daemonize yes
pidfile /data/6371/redis.pid
loglevel notice
logfile "/data/6371/redis.log"
dbfilename 6371.rdb
dir /data/6371
# a6372.conf
#通过命令快速生成配置文件
sed "s/6373/6371/g" redis-6373.conf > redis-6371.conf 
# 启动Redis客户端
[root@localhost redis-4.0.10]# redis-cli -p 6371
# 指明主库的身份IP和端口
127.0.0.1:6371> slaveof 127.0.0.1 6373
# a6373.conf
#通过命令快速生成配置文件
sed "s/6373/6372/g" redis-6373.conf > redis-6372.conf 
# 启动Redis客户端
[root@localhost redis-4.0.10]# redis-cli -p 6372
# 指明主库的身份IP和端口
127.0.0.1:6371> slaveof 127.0.0.1 6373

2.启动三个数据库实例,检测redis主从同步方案

检查redis数据库信息,主从状态的命令
# 检查数据库信息
redis-cli -p 6371 info
# 检查数据库主从信息
redis-cli -p 6371 info replication

3.redis主从赋值,故障手动切换.

杀死6373的主库实例
[root@localhost redis-4.0.10]# !ps
ps -ef|grep red
root      14257      1  0 08:43 ?        00:00:02 redis-server *:6371
root      14264      1  0 08:43 ?        00:00:01 redis-server *:6372
root      14314      1  0 09:00 ?        00:00:00 redis-server *:6373
root      14319  14028  0 09:00 pts/0    00:00:00 grep --color=auto red
[root@localhost redis-4.0.10]# kill 14319

4.登录a6371.conf,通过命令,去掉自己的从库身份,等待连接.

5.登录a6372.conf,通过命令,生成新的主人

6.查看新的主人及连接数

7.检查是否实现主从同步了,主库写入数据,从库检查数据

猜你喜欢

转载自www.cnblogs.com/apollo1616/p/10212441.html