Set the VIP in Redis-sentinel's client-reconfig-script script

Source: Internet
Author: User
Tags redis cluster install redis


Set the VIP in Redis-sentinel's client-reconfig-script script


When using Redis-sentinel for redundancy, how to use the VIP in different ways, I think the use of Client-reconfig-script script is a feasible way, let's try.


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


Three machines make up an available Redis cluster.
Port default 6379, in these three Redis, install Redis-sentinel separately.


redis1 192.168.0.1/24
redis2 192.168.0.2/24
redis3 192.168.0.3/24
Redis,redis-sentinel Installation


Use Yum to install Remi, Redis 2.8.
Set REIDS1 as master and copy to other slave.


 
yum install --enablerepo=epel,remi redis -y sed -i "s|bind 127.0.0.1|bind 0.0.0.0|g" /etc/redis.conf
service redis start
chkconfig redis on


Set Redis2, Redis3 as slave.


redis-cli127.0.0.1:6379SLAVEOF 192.168.0.1 6379
VIP Settings Script


This is the script executed at failover.
The parameters shown below are passed to the script Client-reconfig-script.


<master-name><role><state><from-ip><from-port><to-ip><to-port>


The 6th add VIP, will become a master, the other is to delete the VIP. When failover, using only IP commands can produce ARP problems, so use the arping command to throw Grap. Root permission is required when using the IP, arping command, and sudo is used here to execute the command.


vim /var/lib/redis/failover.sh chmod 755 /var/lib/redis/failover.sh chown redis: /var/lib/redis/failover.sh echo -e "redis\tALL=(ALL)\tNOPASSWD:/sbin/ip,NOPASSWD:/sbin/arping" > /etc/sudoers.d/redis
sed -i "s|Defaults.*requiretty|#Defaults\trequiretty|" /etc/sudoers
chmod 440 /etc/sudoers.d/redis

#! / bin / bash

MASTER_IP = $ {6}
MY_IP = ‘192.168.0.1’ # IP of each server itself
VIP = ‘192.168.0.4’ # VIP
NETMASK = ‘24 ’# Netmask
INTERFACE = ‘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
fi
exit 1


Redis-sentinel settings


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


 
vim /etc/redis-sentinel.conf

service redis-sentinel start
chkconfig redis-sentinel on ip addr add 192.168.0.4/24 dev eth0
# sentinel.conf port 26379 logfile /var/log/redis/sentinel.log sentinel monitor mymaster 192.168.0.1 6379 2 sentinel down-after-milliseconds mymaster 3000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 60000 sentinel client-reconfig-script mymaster /var/lib/redis/failover.sh
Conclusion


After that you can try kill master instead of downtime to test failover, which I think is a good and easy way to implement.
Sentinel Down-after-milliseconds MyMaster 3000
Redis downtime is detected in about 3 seconds. In a more hostile environment, you can try to reduce this value.



Original: http://blog.youyo.info/blog/2014/05/24/redis-cluster/
B.com/benweet/stackedit



Set the VIP in Redis-sentinel's client-reconfig-script script


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.