在Redis-Sentinel的client-reconfig-script脚本中设置VIP
来源:互联网 发布:java怎么驱动图像 编辑:程序博客网 时间:2024/06/11 04:18
在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/24
Redis,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.0.0.1:6379> SLAVEOF 192.168.0.1 6379
VIP设置脚本
这个是在failover时执行的脚本。
如下所示的参数会传递给脚本client-reconfig-script。
# The following arguments are passed to the script:## <master-name> <role> <state> <from-ip> <from-port> <to-ip> <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='eth0' # 接口if [ ${MASTER_IP} = ${MY_IP} ]; then sudo /sbin/ip addr add ${VIP}/${NETMASK} dev ${INTERFACE} sudo /sbin/arping -q -c 3 -A ${VIP} -I ${INTERFACE} exit 0else sudo /sbin/ip addr del ${VIP}/${NETMASK} dev ${INTERFACE} exit 0fiexit 1
Redis-Sentinel设置
开始设置redis-sentonel。
你只需在第一次手工设置VIP。
vim /etc/redis-sentinel.confservice redis-sentinel startchkconfig redis-sentinel onip addr add 192.168.0.4/24 dev eth0
# sentinel.confport 26379logfile /var/log/redis/sentinel.logsentinel monitor mymaster 192.168.0.1 6379 2sentinel 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的宕机。在更恶劣的环境,可以尝试减小这个值。
原文:http://blog.youyo.info/blog/2014/05/24/redis-cluster/
b.com/benweet/stackedit
0 0
- 在Redis-Sentinel的client-reconfig-script脚本中设置VIP
- 在Redis-Sentinel的client-reconfig-script脚本中设置VIP
- Redis & Sentinel 安装脚本
- Redis中sentinel集群的搭建
- spring中配置Redis的sentinel
- redis-sentinel集群(k8s脚本)
- redis的Sentinel 系统
- Redis的Sentinel
- [转]Redis 的 Sentinel
- redis的sentinel
- Redis 的 Sentinel 文档
- redis的哨兵Sentinel
- Redis 的 Sentinel 文档
- 【16-Redis的Sentinel】
- Redis 的 Sentinel 文档
- CentOS6 脚本自动安装redis sentinel
- Redis Sentinel的信息同步
- Redis Sentinel的脑裂
- 一些项目——二维数组的置换
- linux内核调试: eclipse + qemu 组合
- Java基础知识笔记
- Android视频播放项目总结之 使用第三方Vitamio库,开发万能播放器(三)
- python破解教程一 破解211高校BBS论坛的用户密码
- 在Redis-Sentinel的client-reconfig-script脚本中设置VIP
- IOS的生命周期
- C语言面试题_2015.4.28
- 天声人語 20150501
- 日经春秋 20150501
- source insight中添加.S文件
- UILabel设置不同的字体颜色
- 日经社説 20150501 過去にも言及した米議会演説
- 日经社説 20150501 日米の金融政策は幅広い視野で判断を