protected-mode參數是爲了禁止外網訪問redis,若是啓用了,則只可以經過lookback ip(127.0.0.1)訪問Redis,若是外網訪問redis,會報出異常
注意:
若是redis實例配置文件中禁用了bind參數,並將protected-mode設置爲no後,外網訪問redis依然報上述錯誤,由於 sentinel 實例的配置文件中須要增長參數 protected-mode no
redis
quorum的解釋以下:
(1)至少多少個哨兵要一致贊成,master進程掛掉了,或者slave進程掛掉了,或者要啓動一個故障轉移操做
(2)quorum是用來識別故障的,真正執行故障轉移的時候,仍是要在哨兵集羣執行選舉,選舉一個哨兵進程出來執行故障轉移操做
(3)假設有5個哨兵,quorum設置了2,那麼若是5個哨兵中的2個都認爲master掛掉了; 2個哨兵中的一個就會作一個選舉,選舉一個哨兵出來,執行故障轉移; 若是5個哨兵中有3個哨兵都是運行的,那麼故障轉移就會被容許執行服務器
# 語法:sentinel monitor <master-name> <ip> <redis-port> <quorum> # Tells Sentinel to monitor this master, and to consider it in O_DOWN # (Objectively Down) state only if at least <quorum> sentinels agree. # 告訴Sentinel監視這個master,而且考慮它O_DOWN # (僅在客觀上O_DOWN) 狀態 只有在至少 quorum 這個數量的哨兵贊成才能夠。 # Note that whatever is the O_DOWN quorum, a Sentinel will require to # be elected by the majority of the known Sentinels in order to # start a failover, so no failover can be performed in minority. # 請注意,不管quorum數是多少,哨兵都須要這樣作由大多數已知的哨兵 # 選出來啓動故障轉移,所以不能在少數狀況下執行故障轉移。 # Replicas are auto-discovered, so you don't need to specify replicas in # any way. Sentinel itself will rewrite this configuration file adding # the replicas using additional configuration options. # 從機是自動發現的,所以不須要在任何方式指定。哨兵本身將重寫配置文件添加 # 到從機使用的配置文件的配置選項上。 # Also note that the configuration file is rewritten when a # replica is promoted to master. # 注意當從機被指定主機的時候將重寫配置文件 # Note: master name should not include special characters or spaces. # The valid charset is A-z 0-9 and the three characters ".-_". # 注意:主機名稱不該該包含特殊字符或空格。有效的字符集是A-z 0-9和三個字符「.-_」。
(1)、down-after-milliseconds,超過多少毫秒跟一個redis實例斷了鏈接,哨兵就可能認爲這個redis實例掛了
(2)、parallel-syncs,新的master別切換以後,同時有多少個slave被切換到去鏈接新master,從新作同步,數字越低,花費的時間越多
假設你的redis是1個master,4個slave,而後master宕機了,4個slave中有1個切換成了master,剩下3個slave就要掛到新的master上面去這個時候,若是parallel-syncs是1,那麼3個slave,一個一個地掛接到新的master上面去,1個掛接完,並且重新的master sync完數據以後,再掛接下一個,若是parallel-syncs是3,那麼一次性就會把全部slave掛接到新的master上去
(3)、failover-timeout,執行故障轉移的timeout超時時長
ide
# Set the password to use to authenticate with the master and replicas. # Useful if there is a password set in the Redis instances to monitor. # 設置用於主服務器和從機進行身份驗證的密碼。 # 若是要監視的Redis實例中設置了密碼,則很是有用 # Note that the master password is also used for replicas, so it is not # possible to set a different password in masters and replicas instances # if you want to be able to monitor these instances with Sentinel. # 注意,主密碼也用於從機,所以它不可能在主機和從機實例中設置不一樣的密碼 # 若是你想用哨兵來監控這些實例。 # However you can have Redis instances without the authentication enabled # mixed with Redis instances requiring the authentication (as long as the # password set is the same for all the instances requiring the password) as # the AUTH command will have no effect in Redis instances with authentication # switched off. # 並且您能夠在不啓用身份驗證的狀況下使用Redis實例與須要身份驗證的Redis實例混合(只要 # 對於須要密碼的全部實例,密碼集都是相同的在使用身份驗證的Redis實例中),AUTH命令將不起做用。 # 語法:sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
設置成redis.conf中配置的密碼:
上一篇文章已經介紹了主從的搭建這裏就不介紹了,有需求查看上一篇文章
ui
啓動成功而且鏈接到了主機
this
經過下圖可知:主機是172.16.178.2 從機是 172.16.178.3 、172.16.178.4
spa
看到哨兵正在監控着一個主機兩個從機以及三個哨兵
3d
1)、先查詢主機的進程ID
2)、kill -9 70817
此時當前節點只有哨兵了
3)、鏈接當前哨兵,輸入info
這是最小的哨兵配置,若是發生了master-slave故障轉移,或者新的哨兵進程加入哨兵集羣,那麼哨兵會自動更新本身的配置文件
此時主機節點變成了 172.16.178.4 了
4)、鏈接172.16.178.4 上的redis
當前節點爲主機節點,172.16.178.3 爲從節點
5)、從新啓動172.16.178.2主機上的redis
6)、此時再一次鏈接主機
7)、主機set 一個值
8)、1號從機get 主機中設置的key
9)、2號從機get 主機中設置的key
日誌