redis實現(xiàn)sentinel哨兵架構的方法
1、redis哨兵(Sentinel)
1.1、redis集群介紹
前面文章講的主從復制集群是無法實現(xiàn)master和slave角色的自動切換的,如果master節(jié)點出現(xiàn)現(xiàn)redis服務異常、主機斷電、磁盤損壞等問題導致master無法使用,而redis主從復制無法實現(xiàn)自動的故障轉移(將slave 自動提升為新master),需要手動修改環(huán)境配置,才能切換到slave redis服務器,另外當單臺Redis服務器性能無法滿足業(yè)務寫入需求的時候,也無法橫向擴展Redis服務的并行寫入性能。
需要解決以上的兩個核心問題:
- master和slave角色的無縫切換,讓業(yè)務無感知從而不影響業(yè)務使用;
- 可橫向動態(tài)擴展Redis服務器,從而實現(xiàn)多臺服務器并行寫入以實現(xiàn)更高并發(fā)的目的。
Redis集群實現(xiàn)的方式:
- 客戶端分片: 由應用決定將不同的KEY發(fā)送到不同的Redis服務器
- 代理分片: 由代理決定將不同的KEY發(fā)送到不同的Redis服務器,代理程序如:codis,twemproxy等
- Redis Cluster
1.2、redis哨兵(Sentinel)的工作原理
Sentinel可以管理多個redis主從集群
Sentinel 進程是用于監(jiān)控redis集群中Master主服務器工作的狀態(tài),在Master主服務器發(fā)生故障的時候,可以實現(xiàn)Master和Slave服務器的切換,保證系統(tǒng)的高可用,此功能在redis2.6+的版本已引用,Redis的哨兵模式到了2.8版本之后就穩(wěn)定了下來。一般在生產環(huán)境也建議使用Redis的2.8版本的以后版本
哨兵(Sentinel) 是一個分布式系統(tǒng),可以在一個架構中運行多個哨兵(sentinel) 進程,這些進程使用流言協(xié)議(gossip protocols)來接收關于Master主服務器是否下線的信息,并使用投票協(xié)議(Agreement Protocols)來決定是否執(zhí)行自動故障遷移,以及選擇哪個Slave作為新的Master
每個哨兵(Sentinel)進程會向其它哨兵(Sentinel)、Master、Slave定時發(fā)送消息,以確認對方是否”活”著,如果發(fā)現(xiàn)對方在指定配置時間(此項可配置)內未得到回應,則暫時認為對方已離線,也就是所謂的”主觀認為宕機” (主觀:是每個成員都具有的獨自的而且可能相同也可能不同的意識),英文名稱:Subjective Down,簡稱SDOWN
有主觀宕機,對應的有客觀宕機。當“哨兵群”中的多數(shù)Sentinel進程在對Master主服務器做出SDOWN 的判斷,并且通過 SENTINEL is-master-down-by-addr 命令互相交流之后,得出的Master Server下線判斷,這種方式就是“客觀宕機”(客觀:是不依賴于某種意識而已經(jīng)實際存在的一切事物),英文名稱是:Objectively Down, 簡稱 ODOWN
通過一定的vote算法,從剩下的slave從服務器節(jié)點中,選一臺提升為Master服務器節(jié)點,然后自動修改相關配置,并開啟故障轉移(failover)
Sentinel 機制可以解決master和slave角色的自動切換問題,但單個 Master 的性能瓶頸問題無法解決,類似于MySQL中的MHA功能
Redis Sentinel中的Sentinel節(jié)點個數(shù)應該為大于等于3且最好為奇數(shù)
客戶端初始化時連接的是Sentinel節(jié)點集合,不再是具體的Redis節(jié)點,但Sentinel只是配置中心不是代理。
Redis Sentinel節(jié)點與普通redis沒有區(qū)別,要實現(xiàn)讀寫分離依賴于客戶端程序
redis 3.0之前版本中,生產環(huán)境一般使用哨兵模式,3.0后推出redis cluster功能,可以支持更大規(guī)模的生產環(huán)境sentinel中的三個定時任務:
1.2.1sentinel中的三個定時任務:
- 每10秒每個sentinel對master和slave執(zhí)行info,發(fā)現(xiàn)slave節(jié)點,確認主從關系。
- 每2秒每個sentinel通過master節(jié)點的channel交換信息(pub/sub)通過sentinel__:hello頻道交互,交互對節(jié)點的“看法”和自身信息
- 每1秒每個sentinel對其他sentinel和redis執(zhí)行ping
1.3、實現(xiàn)哨兵
環(huán)境準備:
準備三臺主機搭建主從集群,再在每個機器上搭建sentinel
IP | redis版本 | 主機名 |
10.0.0.101 | redis-5.0.14 | node1 |
10.0.0.102 | redis-5.0.14 | node2 |
10.0.0.103 | redis-5.0.14 | node3 |
1.3.1、實現(xiàn)哨兵需要先實現(xiàn)一下主從復制的架構
哨兵的前提是已經(jīng)實現(xiàn)了一個redis的主從復制的運行環(huán)境,從而實現(xiàn)一個一主兩從基于哨兵的高可用redis架構
注意: master的配置文件中masterauth和slave都必須相同
主從復制上篇文章已經(jīng)實現(xiàn)了,這里繼續(xù)用上一篇的環(huán)境
#主節(jié)點 [root@master etc]#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.102,port=6379,state=online,offset=14,lag=1 slave1:ip=10.0.0.103,port=6379,state=online,offset=14,lag=0 master_replid:e9310fdb8dd9f91d265d4c9a8621a6879e0262ff master_replid2:0000000000000000000000000000000000000000 master_repl_offset:14 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:14 127.0.0.1:6379> #slave1節(jié)點 [root@slave1 ~]#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.101 master_port:6379 master_link_status:up master_last_io_seconds_ago:8 master_sync_in_progress:0 slave_repl_offset:224 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:e9310fdb8dd9f91d265d4c9a8621a6879e0262ff master_replid2:0000000000000000000000000000000000000000 master_repl_offset:224 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:224 #slave2節(jié)點 [root@slave2 ~]#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.101 master_port:6379 master_link_status:up master_last_io_seconds_ago:7 master_sync_in_progress:0 slave_repl_offset:2016 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:ee9d24063f9d79d698e875634517923d6a9c2a10 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:2016 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:2016
1.3.2、編輯哨兵的配置文件
Sentinel實際上是一個特殊的redis服務器,有些redis指令支持,但很多指令并不支持.默認監(jiān)聽在26379/tcp端口.所有redis節(jié)點使用相同的以下的配置文件.
#這里因為我是源碼編譯安裝的,所以要人源碼的路徑下找到sentinel.conf將其復制到redis安裝的目錄下 [root@master]# cd /usr/local/src/redis-5.0.14[root@master /usr/local/src/redis-5.0.14# 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@master etc]#sed -i "/^#/d" redis-sentinel.conf [root@master etc]#sed -i "/^$/d" redis-sentinel.conf [root@master etc]#vim redis-sentinel.con bind 0.0.0.0 port 26379 daemonize no pidfile /apps/redis/run/redis-sentinel.pid logfile /apps/redis/log/sentinel.log dir /tmp sentinel monitor mymaster 10.0.0.100 6379 2 #mymaster是集群的名稱,此行指定當前mymaster集群中master服務器的地址和端口 #2為法定人數(shù)限制(quorum),即有幾個sentinel認為master down了就進行故障轉移,一般此值是所有sentinel節(jié)點(一般總數(shù)是>=3的 奇數(shù),如:3,5,7等)的一半以上的整數(shù)值,比如,總數(shù)是3,即3/2=1.5,取整為2,是master的ODOWN客觀下線的依據(jù) sentinel auth-pass mymaster wm521314 #mymaster集群中master的密碼,注意此行要在上面行的下面 sentinel down-after-milliseconds mymaster 3000 #(SDOWN)判斷mymaster集群中所有節(jié)點的主觀下線的時間,單位:毫秒,建議3000 sentinel parallel-syncs mymaster 1 #發(fā)生故障轉移后,可以同時向新master同步數(shù)據(jù)的slave的數(shù)量,數(shù)字越小總同步時間越長,但可以減輕新master的負載壓力 sentinel failover-timeout mymaster 180000 #所有slaves指向新的master所需的超時時間,單位:毫秒 sentinel deny-scripts-reconfig yes #禁止修改腳本 [root@master etc]# scp /apps/redis/etc/redis-sentinel.conf 10.0.0.102:/apps/redis/etc/[root@master etc]# scp /apps/redis/etc/redis-sentinel.conf 10.0.0.103:/apps/redis/etc/
三個哨兵服務器的配置都如下:
[root@slave2 etc]#cat redis-sentinel.conf port 26379 daemonize no pidfile /apps/redis/run/redis-sentinel.pid logfile /apps/redis/log/sentinel.log dir /tmp sentinel monitor mymaster 10.0.0.101 6379 2 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes
1.3.2、啟動哨兵
#我這里是編譯安裝,所以在所有節(jié)點生成新的service文件 [root@master ~]#vim /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@master ~]#scp /lib/systemd/system/redis-sentinel.service 10.0.0.102:/lib/systemd/system/ [root@master ~]#scp /lib/systemd/system/redis-sentinel.service 10.0.0.103:/lib/systemd/system/ #在所有節(jié)點修改一下文件的所有者所屬組,不然無法啟動 chown -R redis.redis /apps/redis/ #在所有節(jié)點啟動哨兵 [root@master ~]#systemctl daemon-reload [root@master ~]#systemctl enable --now redis-sentinel.service
1.3.3、驗證哨兵端口
[root@master ~]#ss -nlt State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 511 0.0.0.0:26379 0.0.0.0:* #已經(jīng)啟動,另外兩個節(jié)點同樣查看 LISTEN 0 511 0.0.0.0:6379 0.0.0.0:* LISTEN 0 1024 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 127.0.0.1:6010 0.0.0.0:* LISTEN 0 511 [::]:26379 [::]:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 128 [::1]:6010 [::]:*
1.3.4、查看哨兵日志
[root@master ~]#tail -f /apps/redis/log/sentinel.log #查看主節(jié)點日志 37184:X 04 Nov 2022 23:32:07.023 # Configuration loaded 37184:X 04 Nov 2022 23:32:07.023 # systemd supervision requested, but NOTIFY_SOCKET not found 37184:X 04 Nov 2022 23:32:07.024 * Increased maximum number of open files to 10032 (it was originally set to 1024). 37184:X 04 Nov 2022 23:32:07.024 * Running mode=sentinel, port=26379. 37184:X 04 Nov 2022 23:32:07.032 # Sentinel ID is 2f9b5e2cb38fc5b3db19417b9626f0ebcc3a7120 37184:X 04 Nov 2022 23:32:07.032 # +monitor master mymaster 10.0.0.101 6379 quorum 2 37184:X 04 Nov 2022 23:32:07.033 * +slave slave 10.0.0.102:6379 10.0.0.102 6379 @ mymaster 10.0.0.101 6379 37184:X 04 Nov 2022 23:32:07.036 * +slave slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.101 6379 37184:X 04 Nov 2022 23:32:07.595 * +sentinel sentinel f505346a3640b4942963b26829e5d99a1fa6691e 10.0.0.102 26379 @ mymaster 10.0.0.101 6379 37184:X 04 Nov 2022 23:32:12.779 * +sentinel sentinel b6aebc495fe5d6e81e57ffd5d4f5bef795b3819a 10.0.0.103 26379 @ mymaster 10.0.0.101 6379 #查看從節(jié)點日志 [root@slave1 ~]#tail -f /apps/redis/log/sentinel.log 6376:X 04 Nov 2022 23:31:59.446 # Configuration loaded 6376:X 04 Nov 2022 23:31:59.446 # systemd supervision requested, but NOTIFY_SOCKET not found 6376:X 04 Nov 2022 23:31:59.446 * Increased maximum number of open files to 10032 (it was originally set to 1024). 6376:X 04 Nov 2022 23:31:59.447 * Running mode=sentinel, port=26379. 6376:X 04 Nov 2022 23:31:59.455 # Sentinel ID is f505346a3640b4942963b26829e5d99a1fa6691e 6376:X 04 Nov 2022 23:31:59.455 # +monitor master mymaster 10.0.0.101 6379 quorum 2 6376:X 04 Nov 2022 23:31:59.457 * +slave slave 10.0.0.102:6379 10.0.0.102 6379 @ mymaster 10.0.0.101 6379 6376:X 04 Nov 2022 23:31:59.458 * +slave slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.101 6379 6376:X 04 Nov 2022 23:32:08.989 * +sentinel sentinel 2f9b5e2cb38fc5b3db19417b9626f0ebcc3a7120 10.0.0.101 26379 @ mymaster 10.0.0.101 6379 6376:X 04 Nov 2022 23:32:12.716 * +sentinel sentinel b6aebc495fe5d6e81e57ffd5d4f5bef795b3819a 10.0.0.103 26379 @ mymaster 10.0.0.101 6379
#查看從節(jié)點日志
[root@slave1 ~]#tail -f /apps/redis/log/sentinel.log 6376:X 04 Nov 2022 23:31:59.446 # Configuration loaded 6376:X 04 Nov 2022 23:31:59.446 # systemd supervision requested, but NOTIFY_SOCKET not found 6376:X 04 Nov 2022 23:31:59.446 * Increased maximum number of open files to 10032 (it was originally set to 1024). 6376:X 04 Nov 2022 23:31:59.447 * Running mode=sentinel, port=26379. 6376:X 04 Nov 2022 23:31:59.455 # Sentinel ID is f505346a3640b4942963b26829e5d99a1fa6691e 6376:X 04 Nov 2022 23:31:59.455 # +monitor master mymaster 10.0.0.101 6379 quorum 2 6376:X 04 Nov 2022 23:31:59.457 * +slave slave 10.0.0.102:6379 10.0.0.102 6379 @ mymaster 10.0.0.101 6379 6376:X 04 Nov 2022 23:31:59.458 * +slave slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.101 6379 6376:X 04 Nov 2022 23:32:08.989 * +sentinel sentinel 2f9b5e2cb38fc5b3db19417b9626f0ebcc3a7120 10.0.0.101 26379 @ mymaster 10.0.0.101 6379 6376:X 04 Nov 2022 23:32:12.716 * +sentinel sentinel b6aebc495fe5d6e81e57ffd5d4f5bef795b3819a 10.0.0.103 26379 @ mymaster 10.0.0.101 6379
1.3.5、當前sentinel狀態(tài)
[root@slave1 ~]#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.101:6379,slaves=2,sentinels=3
1.3.6、驗證數(shù)據(jù)是否同步
[root@master ~]#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> set k1 v1 OK 127.0.0.1:6379> set k2 v2 OK [root@slave1 ~]#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> get k1 "v1" [root@slave2 ~]#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> get k1 "v1"
1.3.7、制造Redis Master節(jié)點故障故障轉移并查看其過程
#停掉master節(jié)點的redis服務來模擬節(jié)點故障 [root@master ~]#killall redis-server #這時候查看日志發(fā)現(xiàn)主節(jié)點已經(jīng)變成了10.0.0.102機器 [root@master ~]#tail -f /apps/redis/log/sentinel.log 800:X 06 Nov 2022 14:36:38.502 # -sdown sentinel b6aebc495fe5d6e81e57ffd5d4f5bef795b3819a 10.0.0.103 26379 @ mymaster 10.0.0.101 6379 800:X 06 Nov 2022 14:36:38.604 # -sdown slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.101 6379 800:X 06 Nov 2022 15:21:26.435 # +sdown master mymaster 10.0.0.101 6379 800:X 06 Nov 2022 15:21:26.500 # +new-epoch 1 800:X 06 Nov 2022 15:21:26.501 # +vote-for-leader f505346a3640b4942963b26829e5d99a1fa6691e 1 800:X 06 Nov 2022 15:21:27.019 # +config-update-from sentinel f505346a3640b4942963b26829e5d99a1fa6691e 10.0.0.102 26379 @ mymaster 10.0.0.101 6379 800:X 06 Nov 2022 15:21:27.019 # +switch-master mymaster 10.0.0.101 6379 10.0.0.102 6379 800:X 06 Nov 2022 15:21:27.019 * +slave slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.102 6379 800:X 06 Nov 2022 15:21:27.019 * +slave slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.102 6379 800:X 06 Nov 2022 15:21:30.032 # +sdown slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.102 6379 #查看各節(jié)點sentinel信息 [root@master ~]#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.102:6379,slaves=2,sentinels=3 #故障轉移后的sentinel配置文件會被自動修改 [root@slave1 ~]#grep "^[a-Z]" /apps/redis/etc/redis-sentinel.conf bind 0.0.0.0 port 26379 daemonize no pidfile "/apps/redis/run/redis-sentinel.pid" logfile "/apps/redis/log/sentinel.log" dir "/tmp" sentinel myid f505346a3640b4942963b26829e5d99a1fa6691e sentinel deny-scripts-reconfig yes sentinel monitor mymaster 10.0.0.102 6379 2 #這里發(fā)現(xiàn)主節(jié)點已經(jīng)變成10.0.0.102 sentinel down-after-milliseconds mymaster 3000 sentinel auth-pass mymaster 123456 sentinel config-epoch mymaster 1 protected-mode no supervised systemd sentinel leader-epoch mymaster 1 sentinel known-replica mymaster 10.0.0.101 6379 sentinel known-replica mymaster 10.0.0.103 6379 sentinel known-sentinel mymaster 10.0.0.103 26379 b6aebc495fe5d6e81e57ffd5d4f5bef795b3819a sentinel known-sentinel mymaster 10.0.0.101 26379 2f9b5e2cb38fc5b3db19417b9626f0ebcc3a7120 sentinel current-epoch 1 #進入redis查看現(xiàn)在info replication信息 [root@slave1 ~]#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:1 slave0:ip=10.0.0.103,port=6379,state=online,offset=905513,lag=0 master_replid:2824cc99085826d751e848cd7b04c9f4abc398cb master_replid2:488fa34f2c093be4886741a38323dd1a0ecf9e03 master_repl_offset:905648 second_repl_offset:537903 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:905648 [root@slave2 ~]#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.102 master_port:6379 master_link_status:up master_last_io_seconds_ago:0 master_sync_in_progress:0 slave_repl_offset:901300 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:2824cc99085826d751e848cd7b04c9f4abc398cb master_replid2:488fa34f2c093be4886741a38323dd1a0ecf9e03 master_repl_offset:901300 second_repl_offset:537903 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:564 repl_backlog_histlen:900737
1.3.8、查看選舉新主的過程日志監(jiān)測
[root@slave2 ~]#tail -f /apps/redis/log/sentinel.log 798:X 06 Nov 2022 15:21:26.509 # +sdown master mymaster 10.0.0.101 6379 798:X 06 Nov 2022 15:21:26.534 # +new-epoch 1 798:X 06 Nov 2022 15:21:26.535 # +vote-for-leader f505346a3640b4942963b26829e5d99a1fa6691e 1 798:X 06 Nov 2022 15:21:26.609 # +odown master mymaster 10.0.0.101 6379 #quorum 3/2 798:X 06 Nov 2022 15:21:26.609 # Next failover delay: I will not start a failover before Sun Nov 6 15:27:27 2022 798:X 06 Nov 2022 15:21:27.053 # +config-update-from sentinel f505346a3640b4942963b26829e5d99a1fa6691e 10.0.0.102 26379 @ mymaster 10.0.0.101 6379 798:X 06 Nov 2022 15:21:27.053 # +switch-master mymaster 10.0.0.101 6379 10.0.0.102 6379 798:X 06 Nov 2022 15:21:27.053 * +slave slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.102 6379 798:X 06 Nov 2022 15:21:27.053 * +slave slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.102 6379 798:X 06 Nov 2022 15:21:30.094 # +sdown slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.102 6379
1.3.9、恢復故障的原master重新加入redis集群
#重新其他原master的redis服務,會發(fā)現(xiàn)會自動指向新的master [root@master ~]#systemctl restart redis #在原master上觀察狀態(tài) [root@master ~]#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.102 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:942522 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:2824cc99085826d751e848cd7b04c9f4abc398cb master_replid2:0000000000000000000000000000000000000000 master_repl_offset:942522 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:936383 repl_backlog_histlen:6140 [root@master ~]#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.102:6379,slaves=2,sentinels=3 #再回到新master節(jié)點觀察狀態(tài) [root@slave1 ~]#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.103,port=6379,state=online,offset=976915,lag=0 slave1:ip=10.0.0.101,port=6379,state=online,offset=977185,lag=0 master_replid:2824cc99085826d751e848cd7b04c9f4abc398cb master_replid2:488fa34f2c093be4886741a38323dd1a0ecf9e03 master_repl_offset:977185 second_repl_offset:537903 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:977185 #在新主查看一下日志 [root@slave1 ~]#tail -f /apps/redis/log/sentinel.log 786:X 06 Nov 2022 15:21:27.030 * +slave-reconf-sent slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.101 6379 786:X 06 Nov 2022 15:21:27.580 * +slave-reconf-inprog slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.101 6379 786:X 06 Nov 2022 15:21:27.639 # -odown master mymaster 10.0.0.101 6379 786:X 06 Nov 2022 15:21:28.621 * +slave-reconf-done slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.101 6379 786:X 06 Nov 2022 15:21:28.672 # +failover-end master mymaster 10.0.0.101 6379 786:X 06 Nov 2022 15:21:28.672 # +switch-master mymaster 10.0.0.101 6379 10.0.0.102 6379 786:X 06 Nov 2022 15:21:28.672 * +slave slave 10.0.0.103:6379 10.0.0.103 6379 @ mymaster 10.0.0.102 6379 786:X 06 Nov 2022 15:21:28.672 * +slave slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.102 6379 786:X 06 Nov 2022 15:21:31.738 # +sdown slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.102 6379 786:X 06 Nov 2022 15:54:28.253 # -sdown slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.102 6379
到此這篇關于redis實現(xiàn)sentinel哨兵架構的文章就介紹到這了,更多相關redis哨兵架構內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
redis啟動報錯Can‘t?open?the?log?file:?No?such?file?or?d
這篇文章主要介紹了redis啟動報錯Can‘t?open?the?log?file:?No?such?file?or?directory問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11