使用Sentinel机制实现Redis高可用主从复制(5)

6732:X 23 Jan 01:35:31.759 # -sdown slave 192.168.1.11:6379 192.168.1.11 6379 @ mymaster 192.168.1.12 6379
6732:X 23 Jan 01:35:41.740 * +convert-to-slave slave 192.168.1.11:6379 192.168.1.11 6379 @ mymaster 192.168.1.12 6379

[root@station12 ~]#tail -f redis_6379.log

7846:M 23 Jan 01:35:42.083 * Slave 192.168.1.11:6379 asks for synchronization
7846:M 23 Jan 01:35:42.083 * Full resync requested by slave 192.168.1.11:6379
7846:M 23 Jan 01:35:42.083 * Starting BGSAVE for SYNC with target: disk
7846:M 23 Jan 01:35:42.084 * Background saving started by pid 7859
7859:C 23 Jan 01:35:42.095 * DB saved on disk
7859:C 23 Jan 01:35:42.095 * RDB: 6 MB of memory used by copy-on-write
7846:M 23 Jan 01:35:42.177 * Background saving terminated with success
7846:M 23 Jan 01:35:42.178 * Synchronization with slave 192.168.1.11:6379 succeeded

5、查看故障转移之后redis和sentinel配置文件的变化

5.1、首先查看三台redis的redis.conf文件

因为模拟1.11服务器的redis-server宕机而后又重新开启,所以sentinel机制rewrite了redis.conf文件,如下:

[root@station11 ~]# vim /etc/redis/redis.conf

# Generated by CONFIG REWRITE
slaveof 192.168.1.12 6379

rewrite机制在1.11的redis.conf末尾添加了如上2行,表示指向1.12这台新的master

查看1.12的redis.conf文件,你会发现原来的参数slaveof 192.168.1.11 6379 已经消失了!

查看1.13的redis.conf文件,如下:

slaveof 192.168.1.12 6379 

由原来的指向192.168.1.11变成了指向新的master 192.168.1.12

6、查看三台redis的sentinel.conf文件

1.11上的sentinel.conf文件:

#cat sentinel.conf
port 26379
sentinel monitor mymaster 192.168.1.12 6379 1  #已经由原来的192.168.1.11变成了192.168.1.12
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 192.168.1.11 6379
sentinel known-slave mymaster 192.168.1.13 6379
sentinel known-sentinel mymaster 192.168.1.12 26479 7c000aa564ed603eeefd031333ebc2c916597ec6
sentinel known-sentinel mymaster 192.168.1.13 26579 a78518e4955d3602c61e212be0cbdc378daa3cdc
  #后边的字符串是sentinel启动时候为每一台redis生成的唯一标识

1.12上的sentinel.conf

#cat sentinel.conf
port 26479
sentinel monitor mymaster 192.168.1.12 6379 1
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 192.168.1.13 6379
sentinel known-slave mymaster 192.168.1.11 6379
sentinel known-sentinel mymaster 192.168.1.13 26579 a78518e4955d3602c61e212be0cbdc378daa3cdc
sentinel known-sentinel mymaster 192.168.1.11 26379 17c9ee07632d60c4c0aa75a853bbda93966caa22

1.13上的sentinel.conf

#cat sentinel.conf
port 26579
sentinel monitor mymaster 192.168.1.12 6379 1
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 192.168.1.11 6379
sentinel known-slave mymaster 192.168.1.13 6379
sentinel known-sentinel mymaster 192.168.1.12 26479 7c000aa564ed603eeefd031333ebc2c916597ec6
sentinel known-sentinel mymaster 192.168.1.11 26379 17c9ee07632d60c4c0aa75a853bbda93966caa22

下面关于Redis的文章您也可能喜欢,不妨参考下:

Ubuntu 14.04下Redis安装及简单测试

Redis主从复制基本配置

Redis高可用方案深入解析 

Ubuntu 14.04安装Redis与简单配置

Ubuntu 16.04环境中安装PHP7.0 Redis扩展

CentOS 7.0 安装Redis 3.2.1详细过程和使用常见问题

Ubuntu 16.04环境中安装PHP7.0 Redis扩展

Ubuntu 15.10下Redis集群部署文档

Redis实战 中文PDF

CentOS 7下Redis的安装与配置

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8bb540c36180276257f85fb9f486a5ab.html