Set VIP in Redis-Sentinel's client-reconfig-script

Source: Internet
Author: User
Tags redis cluster install redis

Set VIP in Redis-Sentinel's client-reconfig-script
Set VIP in Redis-Sentinel's client-reconfig-script

When using Redis-Sentinel for redundancy, how can we use VIP in different ways? I think using client-reconfig-script is a feasible method. Let's try it.

Environment
CentOS 6.5 x86_64redis-2.8.9-1.el6.remi.x86_64

Three machines form an available Redis cluster.
The default port is 6379. Redis-sentinel is installed on the three redis instances.

redis1 192.168.0.1/24redis2 192.168.0.2/24redis3 192.168.0.3/24VIP 192.168.0.4/24
Install Redis and Redis-Sentinel

Use yum to install remi and redis 2.8.
Set Reids1 as the Master and copy it to another 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

Set Redis2 and Redis3 as Slave.

redis-cli127.0.0.1:6379> SLAVEOF 192.168.0.1 6379
VIP settings script

This is the script executed during failover.
The following parameters are passed to the script client-reconfig-script.

# The following arguments are passed to the script:##             

If the number of VIP addresses is increased by 6th, it will become a Master. If the number of other VIP addresses is increased, the VIP addresses will be deleted. When failover is used, only ip commands may cause arp problems. Therefore, the arping command is used to throw GRAP. Root permission is required for ip and arping commands. sudo is used to execute commands.

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 = '2017. 168.0.1 '# IPVIP of each Server =' 192. 168.0.4 '# VIPNETMASK = '24' # NetmaskINTERFACE = 'eth0' # interface 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 0 else sudo/sbin/ip addr del $ {VIP}/$ {NETMASK} dev $ {INTERFACE} exit 0 fiexit 1
Redis-Sentinel settings

Start setting up redis-sentonel.
You only need to set the VIP manually for the first time.

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
Conclusion

Then, you can test the failover by kill the master instead of by going down. I think this is a good and easy way to implement it.
Sentinel down-after-milliseconds MySQL master 3000
Redis downtime will be detected in about 3 seconds. In a worse environment, you can try to reduce this value.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.