1. 程式人生 > >Redis-3.2.1主從故障測試例項 及出現sdown後沒有出現try-failover 或者出現 failover-abort-not-elected 解決方法

Redis-3.2.1主從故障測試例項 及出現sdown後沒有出現try-failover 或者出現 failover-abort-not-elected 解決方法

Redis-3.2.1主從故障測試例項 配置檔案如下:

Rdis 例項1配置檔案 r1.conf :(預設為master)


port 6379
masterauth mypwd
requirepass mypwd
protected-mode yes
bind 192.168.98.136

Rdis 例項2配置檔案 r2.conf :

port 6380
masterauth mypwd
requirepass mypwd
protected-mode yes
bind 192.168.98.136
slaveof 192.168.98.136 6379

Rdis 例項3配置檔案 r3.conf :

port 6381
masterauth mypwd
requirepass mypwd
protected-mode yes
bind 192.168.98.136
slaveof 192.168.98136 6379

Rdis sentinel 哨兵1配置檔案 s1.conf;

port 26379
sentinel monitor mymaster 192.168.98.136 6379 1
sentinel auth-pass mymaster mypwd
sentinel down-after-milliseconds mymaster 15000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 80000
bind 192.168.98.136
protected-mode yes

Rdis sentinel 哨兵1配置檔案 s1.conf;

port 26380
sentinel monitor mymaster 192.168.98.136 6379 1
sentinel auth-pass mymaster mypwd
sentinel down-after-milliseconds mymaster 15000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 80000
bind 192.168.92.136
protected-mode yes

首次依次啟動 Rdis例項r1.conf  r2.conf r3.conf  和sentienl例項s1.conf s2.conf

然後停掉master r1, 測試宕機後的主從切換如下:

[email protected]:~$ redis-sentinel s1.conf
9127:X 22 Aug 23:27:50.999 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
9127:X 22 Aug 23:27:50.999 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
9127:X 22 Aug 23:27:50.999 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.1 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
 |    `-._   `._    /     _.-'    |     PID: 9127
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

9127:X 22 Aug 23:27:51.000 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9127:X 22 Aug 23:27:51.003 # Sentinel ID is 26f43074868559a81927040f04d8afd6be4d7d2b
9127:X 22 Aug 23:27:51.003 # +monitor master mymaster 192.168.92.136 6379 quorum 1
9127:X 22 Aug 23:27:51.004 * +slave slave 192.168.98.136:6380 192.168.92.136 6380 @ mymaster 192.168.98.136 6379
9127:X 22 Aug 23:27:51.005 * +slave slave 192.168.98.136:6381 192.168.92.136 6381 @ mymaster 192.168.98.136 6379
9127:X 22 Aug 23:27:59.017 * +sentinel sentinel 73d21ad0584a4ce628c9aa5cc0653eda169b9080 192.168.98.136 26380 @ mymaster 192.168.98.136 6379
9127:X 22 Aug 23:28:18.366 # +new-epoch 1
9127:X 22 Aug 23:28:18.367 # +vote-for-leader 73d21ad0584a4ce628c9aa5cc0653eda169b9080 1
9127:X 22 Aug 23:28:18.417 # +sdown master mymaster 192.168.98.136 6379
9127:X 22 Aug 23:28:18.417 # +odown master mymaster 192.168.98.136 6379 #quorum 1/1
9127:X 22 Aug 23:28:18.417 # Next failover delay: I will not start a failover before Mon Aug 22 23:30:58 2016
9127:X 22 Aug 23:28:19.465 # +config-update-from sentinel 73d21ad0584a4ce628c9aa5cc0653eda169b9080 192.168.98.136 26380 @ mymaster 192.168.98.136 6379
9127:X 22 Aug 23:28:19.465 # +switch-master mymaster 192.168.92.136 6379 192.168.92.136 6381
9127:X 22 Aug 23:28:19.465 * +slave slave 192.168.92.136:6380 192.168.98.136 6380 @ mymaster 192.168.98.136 6381
9127:X 22 Aug 23:28:19.465 * +slave slave 192.168.92.136:6379 192.168.98.136 6379 @ mymaster 192.168.98.136 6381

如果停掉master 後,sentinel 顯示足夠數量的 sdown 後,沒有出現odown或try-failover,則檢查密碼等配置是否正確

如果停掉master後,試圖切換的時候出現 failover-abort-not-elected

1)如果redis例項沒有配置

protected-mode yes
bind 192.168.98.136

則在sentinel 配置檔案加上

protected-mode no

即可

2)如果redis例項有配置

protected-mode yes
bind 192.168.98.136

則在sentinel 配置檔案加上

protected-mode yes
bind 192.168.98.136

即可