Windows版本redis高可用方案探究 (3)

同时启动完会自动在哨兵的配置文件中生成一些配置,完整的redis-sentinel-28481.conf配置如下

dir "F:\\Study\\redis\\redis-sentinel" logfile "sentinel.28481.txt" port 28481 sentinel myid 48693b2911456ef3da6ebfd14d1adf46e76fbb8b sentinel monitor master 127.0.0.1 28381 2 sentinel down-after-milliseconds master 5000 sentinel failover-timeout master 30000 # Generated by CONFIG REWRITE sentinel auth-pass master test1 sentinel config-epoch master 11 sentinel leader-epoch master 11 sentinel known-slave master 127.0.0.1 28382 sentinel known-slave master 127.0.0.1 28380 sentinel known-sentinel master 127.0.0.1 28482 ce50397a76e2e3ca165ce407859cbc94d7caf504 sentinel known-sentinel master 127.0.0.1 28483 162c66f370550a9926b794abecfb431cf3f8bcc9 sentinel current-epoch 11

启动后会为哨兵生成一个id,同时会记录一些关键信息。

主从自动切换

将主redis关闭,让哨兵自动切换主从。
哨兵24381日志

[22332] 05 Jan 12:34:49.286 # +sdown master master 127.0.0.1 28380 [22332] 05 Jan 12:34:49.295 # +new-epoch 16 [22332] 05 Jan 12:34:49.296 # +vote-for-leader ce50397a76e2e3ca165ce407859cbc94d7caf504 16 [22332] 05 Jan 12:34:49.363 # +odown master master 127.0.0.1 28380 #quorum 3/2 [22332] 05 Jan 12:34:49.363 # Next failover delay: I will not start a failover before Sat Jan 05 12:35:49 2019 [22332] 05 Jan 12:34:50.397 # +config-update-from sentinel ce50397a76e2e3ca165ce407859cbc94d7caf504 127.0.0.1 28482 @ master 127.0.0.1 28380 [22332] 05 Jan 12:34:50.397 # +switch-master master 127.0.0.1 28380 127.0.0.1 28382 [22332] 05 Jan 12:34:50.397 * +slave slave 127.0.0.1:28381 127.0.0.1 28381 @ master 127.0.0.1 28382 [22332] 05 Jan 12:34:50.397 * +slave slave 127.0.0.1:28380 127.0.0.1 28380 @ master 127.0.0.1 28382 [22332] 05 Jan 12:34:55.442 # +sdown slave 127.0.0.1:28380 127.0.0.1 28380 @ master 127.0.0.1 28382

哨兵24382日志

[8760] 05 Jan 12:34:49.237 # +sdown master master 127.0.0.1 28380 [8760] 05 Jan 12:34:49.292 # +odown master master 127.0.0.1 28380 #quorum 2/2 [8760] 05 Jan 12:34:49.292 # +new-epoch 16 [8760] 05 Jan 12:34:49.292 # +try-failover master master 127.0.0.1 28380 [8760] 05 Jan 12:34:49.293 # +vote-for-leader ce50397a76e2e3ca165ce407859cbc94d7caf504 16 [8760] 05 Jan 12:34:49.296 # 162c66f370550a9926b794abecfb431cf3f8bcc9 voted for ce50397a76e2e3ca165ce407859cbc94d7caf504 16 [8760] 05 Jan 12:34:49.296 # 48693b2911456ef3da6ebfd14d1adf46e76fbb8b voted for ce50397a76e2e3ca165ce407859cbc94d7caf504 16 [8760] 05 Jan 12:34:49.394 # +elected-leader master master 127.0.0.1 28380 [8760] 05 Jan 12:34:49.394 # +failover-state-select-slave master master 127.0.0.1 28380 [8760] 05 Jan 12:34:49.470 # +selected-slave slave 127.0.0.1:28382 127.0.0.1 28382 @ master 127.0.0.1 28380 [8760] 05 Jan 12:34:49.470 * +failover-state-send-slaveof-noone slave 127.0.0.1:28382 127.0.0.1 28382 @ master 127.0.0.1 28380 [8760] 05 Jan 12:34:49.541 * +failover-state-wait-promotion slave 127.0.0.1:28382 127.0.0.1 28382 @ master 127.0.0.1 28380 [8760] 05 Jan 12:34:50.341 # +promoted-slave slave 127.0.0.1:28382 127.0.0.1 28382 @ master 127.0.0.1 28380 [8760] 05 Jan 12:34:50.341 # +failover-state-reconf-slaves master master 127.0.0.1 28380 [8760] 05 Jan 12:34:50.396 * +slave-reconf-sent slave 127.0.0.1:28381 127.0.0.1 28381 @ master 127.0.0.1 28380 [8760] 05 Jan 12:34:51.380 * +slave-reconf-inprog slave 127.0.0.1:28381 127.0.0.1 28381 @ master 127.0.0.1 28380 [8760] 05 Jan 12:34:51.446 # -odown master master 127.0.0.1 28380 [8760] 05 Jan 12:34:52.393 * +slave-reconf-done slave 127.0.0.1:28381 127.0.0.1 28381 @ master 127.0.0.1 28380 [8760] 05 Jan 12:34:52.468 # +failover-end master master 127.0.0.1 28380 [8760] 05 Jan 12:34:52.468 # +switch-master master 127.0.0.1 28380 127.0.0.1 28382 [8760] 05 Jan 12:34:52.469 * +slave slave 127.0.0.1:28381 127.0.0.1 28381 @ master 127.0.0.1 28382 [8760] 05 Jan 12:34:52.469 * +slave slave 127.0.0.1:28380 127.0.0.1 28380 @ master 127.0.0.1 28382 [8760] 05 Jan 12:34:57.562 # +sdown slave 127.0.0.1:28380 127.0.0.1 28380 @ master 127.0.0.1 28382

哨兵24383日志

[26484] 05 Jan 12:34:49.161 # +sdown master master 127.0.0.1 28380 [26484] 05 Jan 12:34:49.294 # +new-epoch 16 [26484] 05 Jan 12:34:49.295 # +vote-for-leader ce50397a76e2e3ca165ce407859cbc94d7caf504 16 [26484] 05 Jan 12:34:50.284 # +odown master master 127.0.0.1 28380 #quorum 3/2 [26484] 05 Jan 12:34:50.284 # Next failover delay: I will not start a failover before Sat Jan 05 12:35:49 2019 [26484] 05 Jan 12:34:50.397 # +config-update-from sentinel ce50397a76e2e3ca165ce407859cbc94d7caf504 127.0.0.1 28482 @ master 127.0.0.1 28380 [26484] 05 Jan 12:34:50.397 # +switch-master master 127.0.0.1 28380 127.0.0.1 28382 [26484] 05 Jan 12:34:50.397 * +slave slave 127.0.0.1:28381 127.0.0.1 28381 @ master 127.0.0.1 28382 [26484] 05 Jan 12:34:50.397 * +slave slave 127.0.0.1:28380 127.0.0.1 28380 @ master 127.0.0.1 28382 [26484] 05 Jan 12:34:55.437 # +sdown slave 127.0.0.1:28380 127.0.0.1 28380 @ master 127.0.0.1 28382

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzwjzw.html