wilbertzhou的专栏

在Redis-Sentinel的client-reconfig-script脚本中设置VIP

当使用Redis-Sentinel做冗余时,,如何以不同方式使用VIP,我认为使用client-reconfig-script脚本是一种可行方法,让我们试试。

环境CentOS 6.5 x86_64redis-2.8.9-1.el6.remi.x86_64

三台机器构成一个可用的Redis集群。 端口默认6379,在这三台Redis中,分别安装redis-sentinel。

redis1 192.168.0.1/24redis2 192.168.0.2/24redis3 192.168.0.3/24VIP 192.168.0.4/24Redis,Redis-Sentinel 安装

使用yum安装remi, redis 2.8。 设置Reids1作为Master,复制到其他Slave。

yum install –enablerepo=epel,remi redis -ysed -i “s|bind 127.0.0.1|bind 0.0.0.0|g” /etc/redis.confservice redis startchkconfig redis on

设置Redis2, Redis3作为Slave。

redis-cli127> 6379VIP设置脚本

这个是在failover时执行的脚本。 如下所示的参数会传递给脚本client-reconfig-script。

# The following arguments are passed to the script:## > > <to-port>

第6个增加VIP,将成为一个Master,其它的则删除VIP。在failover时,仅仅使用ip命令可能会产生arp问题,因此使用arping命令来抛出GRAP。在使用ip、arping命令时需要root权限,这里使用sudo来执行命令。

vim /var/lib/redis/failover.shchmod 755 /var/lib/redis/failover.shchown redis: /var/lib/redis/failover.shecho -e “redis\tALL=(ALL)\tNOPASSWD:/sbin/ip,NOPASSWD:/sbin/arping” > /etc/sudoers.d/redissed -i “s|Defaults.*requiretty|#Defaults\trequiretty|” /etc/sudoerschmod 440 /etc/sudoers.d/redis#!/bin/bashMASTER_IP=${6}MY_IP=’192.168.0.1′ # 每个Server本身的IPVIP=’192.168.0.4’# VIPNETMASK=’24’# NetmaskINTERFACE=[ /sbin/arping -q -c /sbin/ip addr del Redis-Sentinel设置

开始设置redis-sentonel。 你只需在第一次手工设置VIP。

vim /etc/redis-sentinel.confservice redis-sentinel startchkconfig redis-sentinel onip addr add /24 dev eth0# sentinel.confport 26379logfile /var/log/redis/sentinel.logsentinel monitor mymaster sentinel down-after-milliseconds mymaster 3000sentinel parallel-syncs mymaster 1sentinel failover-timeout mymaster 60000sentinel client-reconfig-script mymaster /var/lib/redis/failover.sh结论

之后你可以尝试kill master而不是宕机来测试failover,我认为这是个比较好且容易实现的方法。 sentinel down-after-milliseconds mymaster 3000 大约在3秒左右会检测到redis的宕机。在更恶劣的环境,可以尝试减小这个值。

原文: b.com/benweet/stackedit

造物之前,必先造人。

wilbertzhou的专栏

相关文章:

你感兴趣的文章:

标签云: