Redis主从复制中的问题
Redis的高可用
sentinel是Redis的高可用方案,一个分布式系统结构,其中包括若干个sentinel节点和梳个Redis数据节点,每个sentinel节点对Redis的数据节点进行监控和其他的sentinel节点进行监控,但其他节点不可用时,需要半数以上的sentinel节点确认,并由发现的sentinel节点完成自动化故障转移的工作。
主机点故障,无法接续主从复制
每个sentinel通过定期监控发现主节点故障
多个sentinel节点对主节点的故障达成一致
选举出的sentinel节点执行故障转移
**故障转移后整个Redis sentinel的括扑关系
三个定时监控任务
下线
故障转移
需要三个Redis实例,三台sentinel实例
6379,6380,6381 == master,slave1,slave2
26379,26380,26381 == sentinel...
安装并部署Redis
[root@localhost ~]# hostname redis [root@localhost ~]# bash [root@redis ~]# iptables -F [root@redis ~]# systemctl stop firewalld [root@redis ~]# setenforce 0
初识化Redis实例的配置文件
[root@redis utils]# sed -i '/^bind 127.0.0.1$/s/127.0.0.1/192.168.200.21/g' /etc/redis/6379.conf [root@redis utils]# sed -i '/protected-mode/s/yes/no/g' /etc/redis/6379.conf [root@redis utils]# sed -i '/daemonize/s/no/yes/g' /etc/redis/6379.conf [root@redis utils]# sed -i '/requirepass/s/foobared/123456/g' /etc/redis/6379.conf [root@redis utils]# sed -i '/requirepass 123456/s/^#//g' /etc/redis/6379.conf [root@redis utils]# sed -i '/^bind 127.0.0.1$/s/127.0.0.1/192.168.200.21/g' /etc/redis/6380.conf [root@redis utils]# sed -i '/protected-mode/s/yes/no/g' /etc/redis/6380.conf [root@redis utils]# sed -i '/daemonize/s/no/yes/g' /etc/redis/6380.conf [root@redis utils]# sed -i '/requirepass/s/foobared/123456/g' /etc/redis/6380.conf [root@redis utils]# sed -i '/requirepass 123456/s/^#//g' /etc/redis/6380.conf [root@redis utils]# sed -i '/^bind 127.0.0.1$/s/127.0.0.1/192.168.200.21/g' /etc/redis/6381.conf [root@redis utils]# sed -i '/protected-mode/s/yes/no/g' /etc/redis/6381.conf [root@redis utils]# sed -i '/daemonize/s/no/yes/g' /etc/redis/6381.conf [root@redis utils]# sed -i '/requirepass/s/foobared/123456/g' /etc/redis/6381.conf [root@redis utils]# sed -i '/requirepass 123456/s/^#//g' /etc/redis/6381.conf [root@redis utils]# netstat -lnptu | grep redis tcp 0 0 192.168.200.21:6379 0.0.0.0:* LISTEN 6796/redis-server 1 tcp 0 0 192.168.200.21:6380 0.0.0.0:* LISTEN 8092/redis-server 1 tcp 0 0 192.168.200.21:6381 0.0.0.0:* LISTEN 8102/redis-server 1 [root@redis ~]# redis-cli -h 192.168.200.21 -a 123456 -p 6379 ping PONG [root@redis ~]# redis-cli -h 192.168.200.21 -a 123456 -p 6380 ping PONG [root@redis ~]# redis-cli -h 192.168.200.21 -a 123456 -p 6381 ping PONG
主从集群配置
[root@master ~]# vim /etc/redis/6379.conf 451 min-slaves-to-write 2 #设置slave节点数量 452 min-slaves-max-lag 10 #超时时间 [root@master ~]# vim /etc/redis/6379.conf(6380.conf) 282 slaveof 192.168.200.21 6379 289 masterauth 123456 [root@redis ~]# rm -rf /var/run/redis_6379.pid [root@redis ~]# rm -rf /var/run/redis_6380.pid [root@redis ~]# rm -rf /var/run/redis_6381.pid [root@redis ~]# /etc/init.d/redis_6379 start Starting Redis server... [root@redis ~]# /etc/init.d/redis_6380 start Starting Redis server... [root@redis ~]# /etc/init.d/redis_6381 start Starting Redis server... [root@redis ~]# netstat -lnptu | grep redis tcp 0 0 192.168.200.21:6379 0.0.0.0:* LISTEN 6796/redis-server 1 tcp 0 0 192.168.200.21:6380 0.0.0.0:* LISTEN 8092/redis-server 1 tcp 0 [root@localhost ~]# redis-cli -h 192.168.200.21 -a 123456 -p 6379 192.168.200.21:6379> info replication # Replication role:master connected_slaves:2 min_slaves_good_slaves:2 slave0:ip=192.168.200.21,port=6380,state=online,offset=95,lag=0 slave1:ip=192.168.200.21,port=6381,state=online,offset=95,lag=0 master_replid:ad230de635d1606d7c37095e52c4571c01de53ff master_replid2:0000000000000000000000000000000000000000 master_repl_offset:95 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:95
配置Redis sentinel集群