redis高可用 哨兵(Sentinel),主从复制架构
Posted y_zilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis高可用 哨兵(Sentinel),主从复制架构相关的知识,希望对你有一定的参考价值。
sentinel进程是用于监控redis集群中master主服务器工作的状态,在master主服务器发生故障的时候,可以实现master和slave服务器的切换,保证系统的高可用
sentinel中的三个定时任务
每10秒每个sentinel对master和slave执行info
发现slave节点
确认主从关系每2秒每个sentinel通过master节点的channel交换信息(pub/sub)
通过sentinel_:hello频道交互
交互对节点的“看法”和自身信息每1秒每个sentinel对其他sentinel和redis执行ping
哨兵的准备实现主从复制架构
哨兵的前提是已经实现了一个redis的主从复制的运行环境,从而实现一个一主两从基于哨兵的高可用redis架构
注意:master的配置文件中masterauth和slave都必须相同
1、准备主从环境配置
#在所有主从环境配置
主节点:
[root@cent8_yzl_10 ~]# vim /apps/redis/etc/redis.conf
bind 0.0.0.0
masterauth 123456
requirepass 123456
从节点:
[root@cent8_yzl_20 ~]#vim /apps/redis/etc/redis.conf
bind 0.0.0.0
masterauth 123456
requirepass 123456
replicaof 10.0.0.10 6379
master服务器状态
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.0.0.20,port=6379,state=online,offset=12528,lag=0
slave1:ip=10.0.0.30,port=6379,state=online,offset=12528,lag=1
master_failover_state:no-failover
master_replid:a9574022a359f05c706fbbb1af6aa5f819b906de
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:12528
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:12528
127.0.0.1:6379>
slave
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:10.0.0.10
master_port:6379
master_link_status:up
master_last_io_seconds_ago:5
master_sync_in_progress:0
slave_repl_offset:12668
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:a9574022a359f05c706fbbb1af6aa5f819b906de
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:12668
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:12668
127.0.0.1:6379>
编辑哨兵的配置文件
sentinel配置
sentinel实际上是一个特殊的redis服务器,有些redis指令支持,但很多指令并不支持,默认监听在26379/tcp端口
哨兵可以不和redis服务器部署在一起,但一般部署在一起以节约成本
#如果是编译安装,在源码目录有sentinel.conf,复制到安装目录即可,如:/apps/redis/etc/sentinel.conf
[root@cent8_yzl_10 ~]# cd /usr/local/src/redis-6.2.2
[root@cent8_yzl_10 redis-6.2.2]# ls
00-RELEASENOTES CONTRIBUTING INSTALL README.md runtest-cluster sentinel.conf TLS.md
BUGS COPYING Makefile redis.conf runtest-moduleapi src utils
CONDUCT deps MANIFESTO runtest runtest-sentinel tests
[root@cent8_yzl_10 redis-6.2.2]# cp sentinel.conf /apps/redis/etc/redis-sentinel.conf
[root@cent8_yzl_10 redis-6.2.2]# cd /apps/redis/etc/
[root@cent8_yzl_10 etc]# ls
redis.conf redis-sentinel.conf
[root@cent8_yzl_10 etc]# grep -vE "^#|^$" /apps/redis/etc/redis-sentinel.conf
port 26379
daemonize no
pidfile /var/run/redis-sentinel.pid
logfile ""
dir /tmp #工作目录
sentinel monitor mymaster 127.0.0.1 6379 2
#mymaster是集群的名称,此行指定当前mymaster集群中master服务器的地址和端口
#2为法定人数限制(quorum),即有几个sentinel认为master down了就进行故障转移,一般此值是所有sentinel节点(一般总数是>=3的奇数,如3.5.7等)的一半以上的整数值,总数是3,即3/2=1.5,取值为2,是master的ODOWN客观下线的依据
sentinel auth-pass mymaster 123456
#mymaster集群中master的密码,注意此行要在上面行的下面
sentinel down-after-milliseconds mymaster 30000
#(SDOWN)判断mymaster集群中所有节点的主观下线的时间,单位:毫秒,建议3000
acllog-max-len 128
sentinel parallel-syncs mymaster 1
#发生故障转移后,可以同时向新master同步数据的slave的数量,数字越小总同步时间越长,但可以减轻新master的负载压力
sentinel failover-timeout mymaster 180000
#所有slaves指向新的master所需的超时时间,单位:毫秒
sentinel deny-scripts-reconfig yes
#禁止修改脚本
SENTINEL resolve-hostnames no
SENTINEL announce-hostnames no
[root@cent8_yzl_10 etc]#
2、三个哨兵服务器的配置都如下
[root@cent8_yzl_10 ~]# grep -vE "^#|^$" /apps/redis/etc/redis-sentinel.conf
port 26379
daemonize no
pidfile "/apps/redis/run/redis-sentinel.pid"
logfile "/apps/redis/log/redis-sentinel.log"
dir /tmp
sentinel monitor mymaster 10.0.0.10 6379 2 #修改此行
sentinel auth-pass mymaster 123456 #增加此行
sentinel down-after-milliseconds mymaster 3000 #修改此行
acllog-max-len 128
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
SENTINEL resolve-hostnames no
SENTINEL announce-hostnames no
[root@cent8_yzl_10 ~]# scp /apps/redis/etc/redis-sentinel.conf 10.0.0.20:/apps/redis/etc/
redis-sentinel.conf 100% 14KB 6.0MB/s 00:00
[root@cent8_yzl_10 ~]# scp /apps/redis/etc/redis-sentinel.conf 10.0.0.30:/apps/redis/etc/
redis-sentinel.conf 100% 14KB 5.3MB/s 00:00
[root@cent8_yzl_10 ~]#
3、编译安装在所有节点生成service文件
[root@cent8_yzl_10 ~]# cat /lib/systemd/system/redis-sentinel.service
[Unit]
Description=Redis Sentinel
After=network.target
[Service]
ExecStart=/apps/redis/bin/redis-sentinel /apps/redis/etc/redis-sentinel.conf --supervised systemd
ExecStop=/bin/kill -s QUIT $MAINPID
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
[root@cent8_yzl_10 ~]#
[root@cent8_yzl_10 ~]# scp /lib/systemd/system/redis-sentinel.service 10.0.0.20:/lib/systemd/system/
[root@cent8_yzl_10 ~]# scp /lib/systemd/system/redis-sentinel.service 10.0.0.30:/lib/systemd/system/
#注意所有节点的目录权限,否则无法启动服务
[root@cent8_yzl_10 ~]# chown -R redis.redis /apps/redis/
#验证哨兵端口
[root@cent8_yzl_10 ~]# systemctl daemon-reload
[root@cent8_yzl_10 ~]# systemctl enable --now redis-sentinel.service
Created symlink /etc/systemd/system/multi-user.target.wants/redis-sentinel.service → /usr/lib/systemd/system/redis-sentinel.service.
[root@cent8_yzl_10 ~]# systemctl status redis-sentinel.service
● redis-sentinel.service - Redis Sentinel
Loaded: loaded (/usr/lib/systemd/system/redis-sentinel.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2021-07-01 03:54:47 EDT; 19s ago
Main PID: 6054 (redis-sentinel)
Tasks: 5 (limit: 23537)
Memory: 1.9M
CGroup: /system.slice/redis-sentinel.service
└─6054 /apps/redis/bin/redis-sentinel *:26379 [sentinel]
Jul 01 03:54:47 cent8_yzl_10.yzil.xyz systemd[1]: Started Redis Sentinel.
[root@cent8_yzl_10 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 511 0.0.0.0:26379 0.0.0.0:*
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 511 [::]:26379 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
[root@cent8_yzl_10 ~]#
4、确保每个哨兵主机myid不同,三台哨兵服务器都要重启
[root@cent8_yzl_10 ~]# grep "sentinel myid" /apps/redis/etc/redis-sentinel.conf
sentinel myid e9432e92acd3ccb3c95852faac90c79fcd078ef4
[root@cent8_yzl_20 ~]# grep "sentinel myid" /apps/redis/etc/redis-sentinel.conf
sentinel myid 73ac287a33dd20115ec6d2cbd00fdd4228f41400
[root@cent8_yzl_30 ~]# grep "sentinel myid" /apps/redis/etc/redis-sentinel.conf
sentinel myid 659b6e2264f7318f082e3bc4467ab19c9941ea36
5、查看哨兵的配置文件
[root@cent8_yzl_10 ~]# grep -vE "^#|^$" /apps/redis/etc/redis-sentinel.conf
port 26379
daemonize no
pidfile "/apps/redis/run/redis-sentinel.pid"
logfile "/apps/redis/log/redis-sentinel.log"
dir "/tmp"
sentinel monitor mymaster 10.0.0.10 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 3000
acllog-max-len 128
sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no
#以下内容自动生成
protected-mode no
supervised systemd
user default on nopass ~* &* +@all
sentinel myid e9432e92acd3ccb3c95852faac90c79fcd078ef4
#此行自动生成必须唯一,修改此值需重启redis和sentinel服务
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
sentinel known-replica mymaster 10.0.0.30 6379
sentinel known-replica mymaster 10.0.0.20 6379
sentinel known-sentinel mymaster 10.0.0.30 26379 659b6e2264f7318f082e3bc4467ab19c9941ea36
sentinel known-sentinel mymaster 10.0.0.20 26379 73ac287a33dd20115ec6d2cbd00fdd4228f41400
[root@cent8_yzl_10 ~]#
6、查看哨兵日志
master的哨兵日志
[root@cent8_yzl_10 ~]# tail -f /apps/redis/log/redis-sentinel.log
6054:X 01 Jul 2021 03:54:47.501 # Configuration loaded
6054:X 01 Jul 2021 03:54:47.502 * Increased maximum number of open files to 10032 (it was originally set to 1024).
6054:X 01 Jul 2021 03:54:47.502 * monotonic clock: POSIX clock_gettime
6054:X 01 Jul 2021 03:54:47.503 * Running mode=sentinel, port=26379.
6054:X 01 Jul 2021 03:54:47.505 # Sentinel ID is e9432e92acd3ccb3c95852faac90c79fcd078ef4
6054:X 01 Jul 2021 03:54:47.505 # +monitor master mymaster 10.0.0.10 6379 quorum 2
6054:X 01 Jul 2021 03:54:47.506 * +slave slave 10.0.0.20:6379 10.0.0.20 6379 @ mymaster 10.0.0.10 6379
6054:X 01 Jul 2021 03:54:47.508 * +slave slave 10.0.0.30:6379 10.0.0.30 6379 @ mymaster 10.0.0.10 6379
6054:X 01 Jul 2021 03:56:34.423 * +sentinel sentinel 73ac287a33dd20115ec6d2cbd00fdd4228f41400 10.0.0.20 26379 @ mymaster 10.0.0.10 6379
6054:X 01 Jul 2021 03:57:25.378 * +sentinel sentinel 659b6e2264f7318f082e3bc4467ab19c9941ea36 10.0.0.30 26379 @ mymaster 10.0.0.10 6379
slave的哨兵日志
[root@cent8_yzl_20 ~]# tail -f /apps/redis/log/redis-sentinel.log
1975:X 01 Jul 2021 15:56:32.369 # Configuration loaded
1975:X 01 Jul 2021 15:56:32.370 * Increased maximum number of open files to 10032 (it was originally set to 1024).
1975:X 01 Jul 2021 15:56:32.370 * monotonic clock: POSIX clock_gettime
1975:X 01 Jul 2021 15:56:32.370 * Running mode=sentinel, port=26379.
1975:X 01 Jul 2021 15:56:32.373 # Sentinel ID is 73ac287a33dd20115ec6d2cbd00fdd4228f41400
1975:X 01 Jul 2021 15:56:32.373 # +monitor master mymaster 10.0.0.10 6379 quorum 2
1975:X 01 Jul 2021 15:56:32.375 * +slave slave 10.0.0.20:6379 10.0.0.20 6379 @ mymaster 10.0.0.10 6379
1975:X 01 Jul 2021 15:56:32.377 * +slave slave 10.0.0.30:6379 10.0.0.30 6379 @ mymaster 10.0.0.10 6379
1975:X 01 Jul 2021 15:56:33.475 * +sentinel sentinel e9432e92acd3ccb3c95852faac90c79fcd078ef4 10.0.0.10 26379 @ mymaster 10.0.0.10 6379
1975:X 01 Jul 2021 15:57:25.359 * +sentinel sentinel 659b6e2264f7318f082e3bc4467ab19c9941ea36 10.0.0.30 26379 @ mymaster 10.0.0.10 6379
7、当前sentinel状态
#在sentinel状态中尤其是最后一行,涉及到masterIP是多少,有几个slave,有几个sentinels,必须是符合全部服务器数量
[root@cent8_yzl_10 ~]# redis-cli -a 123456 -p 26379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Warning: AUTH failed
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.10:6379,slaves=2,sentinels=3
127.0.0.1:26379>
#两个slave,三个sentinel服务器,如果sentinels值不符合,检查myid可能冲突
8、停止redis master节点测试故障转移
[root@cent8_yzl_10 ~]# killall redis-server
查看各节点上哨兵信息
[root@cent8_yzl_20 ~]# redis-cli -a 123456 -p 26379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Warning: AUTH failed
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.20:6379,slaves=2,sentinels=3
127.0.0.1:26379>
故障转移时sentinel的信息
[root@cent8_yzl_10 ~]# tail -f /apps/redis/log/redis-sentinel.log
6121:X 01 Jul 2021 04:27:27.002 # +sdown master mymaster 10.0.0.10 6379
6121:X 01 Jul 2021 04:27:27.077 # +new-epoch 1
6121:X 01 Jul 2021 04:27:27.082 # +vote-for-leader 659b6e2264f7318f082e3bc4467ab19c9941ea36 1
6121:X 01 Jul 2021 04:27:28.090 # +odown master mymaster 10.0.0.10 6379 #quorum 3/2
6121:X 01 Jul 2021 04:27:28.090 # Next failover delay: I will not start a failover before Thu Jul 1 04:33:27 2021
6121:X 01 Jul 2021 04:27:28.198 # +config-update-from sentinel 659b6e2264f7318f082e3bc4467ab19c9941ea36 10.0.0.30 26379 @ mymaster 10.0.0.10 6379
6121:X 01 Jul 2021 04:27:28.198 # +switch-master mymaster 10.0.0.10 6379 10.0.0.20 6379
6121:X 01 Jul 2021 04:27:28.198 * +slave slave 10.0.0.30:6379 10.0.0.30 6379 @ mymaster 10.0.0.20 6379
6121:X 01 Jul 2021 04:27:28.198 * +slave slave 10.0.0.10:6379 10.0.0.10 6379 @ mymaster 10.0.0.20 6379
6121:X 01 Jul 2021 04:27:31.272 # +sdown slave 10.0.0.10:6379 10.0.0.10 6379 @ mymaster 10.0.0.20 6379
9、故障转移后的redis配置文件会被自动修改
#故障转移后redis.conf中的replicaof行的master IP会被修改
[root@cent8_yzl_30 ~]# grep ^replicaof /apps/redis/etc/redis.conf
replicaof 10.0.0.20 6379
#哨兵配置文件的sentinel monitor IP同样也会被修改
[root@cent8_yzl_20 ~]# grep "^[a-Z]" /apps/redis/etc/redis-sentinel.conf
port 26379
daemonize no
pidfile "/apps/redis/run/redis-sentinel.pid"
logfile "/apps/redis/log/redis-sentinel.log"
dir "/tmp"
sentinel monitor mymaster 10.0.0.20 6379 2 #自动修改此行
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 3000
acllog-max-len 128
sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no
protected-mode no
supervised systemd
user default on nopass sanitize-payload ~* &* +@all
sentinel myid 73ac287a33dd20115ec6d2cbd00fdd4228f41400
sentinel config-epoch mymaster 1
sentinel leader-epoch mymaster 1
sentinel current-epoch 1
sentinel known-replica mymaster 10.0.0.30 6379
sentinel known-replica mymaster 10.0.0.10 6379
sentinel known-sentinel mymaster 10.0.0.30 26379 659b6e2264f7318f082e3bc4467ab19c9941ea36
sentinel known-sentinel mymaster 10.0.0.10 26379 e9432e92acd3ccb3c95852faac90c79fcd078ef4
[root@cent8_yzl_30 ~]# grep "^[a-Z]" /apps/redis/etc/redis-sentinel.conf
port 26379
daemonize no
pidfile "/apps/redis/run/redis-sentinel.pid"
logfile "/apps/redis/log/redis-sentinel.log"
dir "/tmp"
sentinel monitor mymaster 10.0.0.20 6379 2 #自动修改此行
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 3000
acllog-max-len 128
sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no
protected-mode no
supervised systemd
user default on nopass sanitize-payload ~* &* +@all
sentinel myid 659b6e2264f7318f082e3bc4467ab19c9941ea36
sentinel config-epoch mymaster 1
sentinel leader-epoch mymaster 1
sentinel current-epoch 1
sentinel known-replica mymaster 10.0.0.30 6379
sentinel known-replica mymaster 10.0.0.10 6379
sentinel known-sentinel mymaster 10.0.0.20 26379 73ac287a33dd20115ec6d2cbd00fdd4228f41400
sentinel known-sentinel mymaster 10.0.0.10 26379 e9432e92acd3ccb3c95852faac90c79fcd078ef4
10、当前redis状态
#新的master状态
[root@cent8_yzl_20 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master #提升为master
connected_slaves:1
slave0:ip=10.0.0.30,port=6379,state=online,offset=282288,lag=1
master_failover_state:no-failover
master_replid:3a166a0cc7a7bae93371e392329c96479d31dc6d
master_replid2:cda27191263e9c04cf9bd37dbea0dd9ac7b8f4f1
master_repl_offset:282288
second_repl_offset:137338
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:157
repl_backlog_histlen:282132
127.0.0.1:6379>
另一个slave指向新的master
[root@cent8_yzl_30 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:10.0.0.20 #指向新的master
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:297548
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:3a166a0cc7a7bae93371e392329c96479d31dc6d
master_replid2:cda27191263e9c04cf9bd37dbea0dd9ac7b8f4f1
master_repl_offset:297548
second_repl_offset:137338
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:297548
127.0.0.1:6379>
11、恢复故障的原master重新加入redis集群
[root@cent8_yzl_10 ~]# systemctl start redis
[root@cent8_yzl_10 ~]# grep replicaof /apps/redis/etc/redis.conf
#sentinel会自动修改下面的行指向新的master
replicaof 10.0.0.20 6379
在原master上观察状态
[root@cent8_yzl_10 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:10.0.0.20
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:366822
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:3a166a0cc7a7bae93371e392329c96479d31dc6d
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:366822
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:332913
repl_backlog_histlen:33910
127.0.0.1:6379>
[root@cent8_yzl_10 ~]# redis-cli -p 26379
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.20:6379,slaves=2,sentinels=3
127.0.0.1:26379>
观察master上状态和日志
[root@cent8_yzl_20 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.0.0.30,port=6379,state=online,offset=392008,lag=0
slave1:ip=10.0.0.10,port=6379,state=online,offset=392008,lag=0
master_failover_state:no-failover
master_replid:3a166a0cc7a7bae93371e392329c96479d31dc6d
master_replid2:cda27191263e9c04cf9bd37dbea0dd9ac7b8f4f1
master_repl_offset:392008
second_repl_offset:137338
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:157
repl_backlog_histlen:391852
127.0.0.1:6379>
[root@cent8_yzl_20 ~]# tail -f /apps/redis/log/redis-sentinel.log
2029:X 01 Jul 2021 16:27:28.182 * +slave slave 10.0.0.10:6379 10.0.0.10 6379 @ mymaster 10.0.0.20 6379
2029:X 01 Jul 2021 16:27:31.215 # +sdown slave 10.0.0.10:6379 10.0.0.10 6379 @ mymaster 10.0.0.20 6379
2029:X 01 Jul 2021 16:43:48.679 # -sdown slave 10.0.0.10:6379 10.0.0.10 6379 @ mymaster 10.0.0.20 6379
2029:X 01 Jul 2021 16:43:58.696 * +convert-to-slave slave 10.0.0.10:6379 10.0.0.10 6379 @ mymaster 10.0.0.20 6379
12、sentinel运维
手动让主节点下线
sentinel failover <masterName>
手动故障转移
[root@cent8_yzl_10 ~]# vim /apps/redis/etc/redis.conf
replica-priority 10 #指定优先级,值越小sentinel会优先将之选为新的master,默认值为100
[root@cent8_yzl_10 ~]# systemctl restart redis
[root@cent8_yzl_10 ~]# redis-cli -p 26379
127.0.0.1:26379> sentinel failover mymaster
OK
127.0.0.1:26379>
[root@cent8_yzl_10 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.0.0.30,port=6379,state=online,offset=739804,lag=1
slave1:ip=10.0.0.20,port=6379,state=online,offset=739804,lag=1
master_failover_state:no-failover
master_replid:ad01265f74988c0af05e0b16f180fc8f26c09111
master_replid2:3a166a0cc7a7bae93371e392329c96479d31dc6d
master_repl_offset:739951
second_repl_offset:554628
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:544826
repl_backlog_histlen:195126
127.0.0.1:6379>
以上是关于redis高可用 哨兵(Sentinel),主从复制架构的主要内容,如果未能解决你的问题,请参考以下文章