上一篇博客我们介绍了Redis Sentinel的安装配置,详情可参考链接:Redis Sentinel--安装配置,今天主要做几个简单的测试Case
成都创新互联专注于平阴企业网站建设,响应式网站,商城开发。平阴网站建设公司,为平阴等地区提供建站服务。全流程按需网站策划,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务Redis Sentinel API
ping 正常会返回pong sentinel masters 返回被监视的所有master及状态 sentinel master添加Sentinel
增加一个sentinel很简单,直接配置好sentinel.conf文件,开启一个sentinel即可;
添加时最好一个添加结束后,再添加另外一个,不要同时添加,可以每隔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稍微复杂一点,sentinel永远不会删除一个已经存在过的sentinel,即使它已经与组织失去联系
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节点上,每个隔30s执行
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节点上,每个隔30s执行
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"另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。