您好,登錄后才能下訂單哦!
上一篇博客我們介紹了Redis Sentinel的安裝配置,詳情可參考鏈接:Redis Sentinel--安裝配置,今天主要做幾個簡單的測試Case
Redis Sentinel API
ping 正常會返回pong sentinel masters 返回被監(jiān)視的所有master及狀態(tài) sentinel master <master name> 返回指定的master及狀態(tài) setntinel slaves <master name> 返回slave及狀態(tài) sentinel sentinels <master name> 返回sentinel及狀態(tài) sentinel get-master-addr-by-name mymaster 返回現(xiàn)在的master IP和Port sentinel reset * 清理已經(jīng)移除的master-slave或者sentinel信息 sentinel failover <master name>手動執(zhí)行故障轉(zhuǎn)移 sentinel ckquorum <master name> 返回(OK 3 usable Sentinels. Quorum and failover authorization can be reached) sentinel flushconfig 如果sentinel.conf丟失,可以使用這個命令生成新的配置文件
添加Sentinel
增加一個sentinel很簡單,直接配置好sentinel.conf文件,開啟一個sentinel即可;
添加時最好一個添加結(jié)束后,再添加另外一個,不要同時添加,可以每隔30秒添加一個sentinel;
通過SENTINEL MASTER mastername中的num-other-sentinels來查看是否成功添加sentinel。
[root@sht-sgmhadoopdn-04 redis]# cat sentinel.conf daemonize yes port 26379 logfile "sentinel.log" dir "/usr/local/redis" protected-mode no sentinel myid 79393e76e002cb64db92fb8bcb88d79f2d85a82b sentinel monitor mymaster 172.16.101.59 6379 2 [root@sht-sgmhadoopdn-04 redis]# src/redis-sentinel sentinel.conf 172.16.101.54:26379> sentinel master mymaster 33) "num-other-sentinels" 34) "3"
移除Sentinel
刪除一個sentinel稍微復(fù)雜一點,sentinel永遠不會刪除一個已經(jīng)存在過的sentinel,即使它已經(jīng)與組織失去聯(lián)系
Step:
(1) Stop the Sentinel process of the Sentinel you want to remove.
(2) Send a SENTINEL RESET * command to all the other Sentinel instances (instead of * you can use the exact master name if you want to reset just a single master). One after the other, waiting at least 30 seconds between instances.
(3) Check that all the Sentinels agree about the number of Sentinels currently active, by inspecting the output of SENTINEL MASTER mastername of every Sentinel.
[root@sht-sgmhadoopdn-04 redis]# ps -ef|grep redis root 17510 1 0 18:34 ? 00:00:03 src/redis-sentinel *:26379 [sentinel] [root@sht-sgmhadoopdn-04 redis]# kill -9 17510
在其他的每個sentinel節(jié)點上,每個隔30s執(zhí)行
172.16.101.54:26379> sentinel reset * 172.16.101.55:26379> sentinel reset * 172.16.101.56:26379> sentinel reset * 172.16.101.54:26379> sentinel master mymaster 33) "num-other-sentinels" 34) "2"
移除一個老的master或不可用的slave
[root@sht-sgmhadoopdn-01 redis]# ps -ef|grep redis root 15261 1 0 Aug05 ? 00:05:55 src/redis-server 172.16.101.58:6379 root 19768 19394 0 21:09 pts/2 00:00:00 grep --color=auto redis [root@sht-sgmhadoopdn-01 redis]# kill -9 15261 172.16.101.54:26379> sentinel masters 31) "num-slaves" 32) "2"
在每個sentinel節(jié)點上,每個隔30s執(zhí)行
172.16.101.54:26379> sentinel reset mymaster 172.16.101.55:26379> sentinel reset mymaster 172.16.101.56:26379> sentinel reset mymaster 172.16.101.54:26379> sentinel masters 31) "num-slaves" 32) "1"
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。