欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

redis實現(xiàn)sentinel哨兵架構的方法

 更新時間:2022年11月12日 08:57:01   作者:gy001  
哨兵是一個分布式系統(tǒng),可以在一個架構中運行多個哨兵(sentinel) 進程,這些進程使用流言協(xié)議(gossip protocols)來接收關于Master主服務器是否下線的信息,這篇文章主要介紹了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

IPredis版本主機名
10.0.0.101redis-5.0.14node1
10.0.0.102redis-5.0.14node2
10.0.0.103redis-5.0.14node3

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基礎學習之管道機制詳析

    Redis基礎學習之管道機制詳析

    這篇文章主要給大家介紹了關于Redis基礎學習之管道機制的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Redis具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-11-11
  • Redis 的 GeoHash詳解

    Redis 的 GeoHash詳解

    這篇文章主要介紹了Redis 的 GeoHash詳解,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11
  • Redis分布式鎖詳細介紹

    Redis分布式鎖詳細介紹

    大家好,本篇文章主要講的是Redis分布式鎖詳細介紹,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • redis啟動報錯Can‘t?open?the?log?file:?No?such?file?or?directory

    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
  • Redis的LRU機制介紹

    Redis的LRU機制介紹

    這篇文章主要介紹了Redis的LRU機制介紹,Redis會按LRU算法刪除設置了過期時間但還沒有過期的key,而對于沒有設置過期時間的key,Redis是永遠保留的,需要的朋友可以參考下
    2015-06-06
  • redis中事務機制及樂觀鎖的實現(xiàn)

    redis中事務機制及樂觀鎖的實現(xiàn)

    這篇文章主要介紹了redis中事務機制及樂觀鎖的相關內容,通過事務的執(zhí)行分析Redis樂觀鎖,具有一定參考價值,需要的朋友可以了解下。
    2017-10-10
  • Redis接口訪問優(yōu)化的方法步驟

    Redis接口訪問優(yōu)化的方法步驟

    本文基于之前的Redis接口訪問進行優(yōu)化,引入了接口防抖功能,通過時間段參數(shù)限制接口調用頻率,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-10-10
  • 詳解Redis中的List是如何實現(xiàn)的

    詳解Redis中的List是如何實現(xiàn)的

    List 的 Redis 中的 5 種主要數(shù)據(jù)結構之一,它是一種序列集合,可以存儲一個有序的字符串列表,順序是插入的順序,本文將給大家介紹了一下Redis中的List是如何實現(xiàn)的,需要的朋友可以參考下
    2024-05-05
  • redis獲取所有key的方法

    redis獲取所有key的方法

    本文主要介紹了redis獲取所有key的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-04-04
  • redis分布式Jedis類型轉換的異常深入研究

    redis分布式Jedis類型轉換的異常深入研究

    這篇文章主要介紹了redis分布式Jedis類型轉換的異常深入研究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-03-03

最新評論