上一篇博客我們介紹了redis Sentinel的安裝配置,詳情可參考鏈接:Redis Sentinel--安裝配置,今天主要做幾個(gè)簡(jiǎn)單的測(cè)試Case
成都創(chuàng)新互聯(lián)公司網(wǎng)絡(luò)公司擁有十余年的成都網(wǎng)站開(kāi)發(fā)建設(shè)經(jīng)驗(yàn),1000+客戶(hù)的共同信賴(lài)。提供網(wǎng)站設(shè)計(jì)、做網(wǎng)站、網(wǎng)站開(kāi)發(fā)、網(wǎng)站定制、賣(mài)鏈接、建網(wǎng)站、網(wǎng)站搭建、成都響應(yīng)式網(wǎng)站建設(shè)公司、網(wǎng)頁(yè)設(shè)計(jì)師打造企業(yè)風(fēng)格,提供周到的售前咨詢(xún)和貼心的售后服務(wù)
Redis Sentinel API
ping 正常會(huì)返回pong sentinel masters 返回被監(jiān)視的所有master及狀態(tài) sentinel master返回指定的master及狀態(tài) setntinel slaves 返回slave及狀態(tài) sentinel sentinels 返回sentinel及狀態(tài) sentinel get-master-addr-by-name mymaster 返回現(xiàn)在的master IP和Port sentinel reset * 清理已經(jīng)移除的master-slave或者sentinel信息 sentinel failover 手動(dòng)執(zhí)行故障轉(zhuǎn)移 sentinel ckquorum 返回(OK 3 usable Sentinels. Quorum and failover authorization can be reached) sentinel flushconfig 如果sentinel.conf丟失,可以使用這個(gè)命令生成新的配置文件
添加Sentinel
增加一個(gè)sentinel很簡(jiǎn)單,直接配置好sentinel.conf文件,開(kāi)啟一個(gè)sentinel即可;
添加時(shí)最好一個(gè)添加結(jié)束后,再添加另外一個(gè),不要同時(shí)添加,可以每隔30秒添加一個(gè)sentinel;
通過(guò)SENTINEL MASTER mastername中的num-other-sentinels來(lái)查看是否成功添加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
刪除一個(gè)sentinel稍微復(fù)雜一點(diǎn),sentinel永遠(yuǎn)不會(huì)刪除一個(gè)已經(jīng)存在過(guò)的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
在其他的每個(gè)sentinel節(jié)點(diǎn)上,每個(gè)隔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"
移除一個(gè)老的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"
在每個(gè)sentinel節(jié)點(diǎn)上,每個(gè)隔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"