哨兵機制
識別掛掉的主節點
quorum(法定人數)
是判定主節點不能訪問所需要的最少哨兵數量
執行失效備援perform a failover
其中一個哨兵需要被選為救援的領導,並被授權執行救援,而這需要過半數的哨兵同意
So for example if you have 5 Sentinel processes, and the quorum for a given master set to the value of 2, this is what happens:
- If two Sentinels agree at the same time about the master being unreachable, one of the two will try to start a failover.
- If there are at least a total of three Sentinels reachable, the failover will be authorized and will actually start.
In practical terms this means during failures Sentinel never starts a failover if the majority of Sentinel processes are unable to talk (aka no failover in the minority partition).
一主一從哨兵
+----+ +----+
| M1 |-------| R1 |
| S1 | | S2 |
+----+ +----+
Configuration: quorum = 1
如果M1掛掉,R1會成為主節點,因為兩個哨兵可以就M1的失效達成一致,而且可以授權救援。表面上這樣可以工作,但是請看下面這種情況。
如果M1所在的機器直接停掉,同時S1就停止工作。這樣的話S2就不能授權救援,整個系統就不可用了。
要注意的是,失效救援是需要過半數的哨兵同意。同時如果上圖只在一邊執行救援,並且沒有授權,會非常危險:
+----+ +------+
| M1 |----//-----| [M1] |
| S1 | | S2 |
+----+ +------+
上面的配置了兩個主節點(完美對稱)(假設S2可以沒有授權進行救援)。
客戶端可能無限期地往兩邊寫入數據,當網絡恢復時並不能知道哪邊的配置是對的。
所以至少請在配置三個哨兵在三個不同的機器上。
