Keepalived official Chinese Documentation: LVS + keepalived Chinese application doc -March 16, 2010.
keepalived implementation of the VRRP protocol, from the routing level to achieve VIP switching, can completely avoid similar heartbeat brain crack problem. Can be very nice to implement master-slave, master preparation, mutual preparation solutions, especially the stateless business, the state of business will need to take extra effort.
Since MySQL can use keepalived very good to do the master-slave switch, Redis nature will have a kind of learning.
The Redis master-slave implementation is completely non-MySQL mature, only available, according to the author planning the corresponding improvement needs, such as 3.0 later. After the test master is not so completely unreliable. The main problem is that you need to re-synchronize the synchronization when the connection is disconnected, and if you do so frequently it will have a significant performance impact on the primary service. But in reality, the master-slave machine is often required to be placed in a cabinet with the same Exchange equipment, the network flash is very low, and the master-slave synchronization in the number of synchronous large cases, the need to adjust the buffer is large enough, otherwise it is easy to cause disconnection.
The following switching logic is implemented: A B two Machines
1. A, b start in turn, a for the main, b for from
2. Master A hangs up and B takes over the business as the main
3.A up, as from Slaveof B
4.B hang up, A cut back to the main
will be a full master, you can achieve master-slave, read and write separation can also be a machine on multiple instances half master, half from, to achieve mutual backup, two machines at the same time take over the business, a downtime after the business is concentrated on a platform.
There are two roles in keepalived: Master (one), Backup (multiple), if you set one for master, but Master hangs up again, it is inevitable that the business will switch again again, which is unacceptable for stateful services. The solution is that two machines are set to backup, and the high priority backup is set to NOPREEMT not preempted.
Installation is relatively simple:
Dependencies Required: Openssl-devel (Libssl-dev in Ubuntu), Popt-devel (Libpopt-dev in Ubuntu), Redheat.
Profile Default path:/etc/keepalived/keepalived.conf You can also specify the path manually, but note that you manually specify that you need to use an absolute path.
Run with keepalived-d to start 3 daemons: A parent process, a check health check, and a vrrp,-d write log/var/log/message
The configuration is as follows:
Master:
! configuration file for keepalivedglobal_defs { router_id test }vrrp_script chk_redis { script "/etc/keepalived/scripts/ redis_check.sh 127.0.0.1 7001 " interval 2 timeout 2 fall 3}vrrp_script chk_redis2 { script "/etc/keepalived/scripts/redis_check.sh 127.0.0.1 7002 " interval 2 timeout 2 fall 3}vrrp_instance redis { state backup # Master is also configured as Slave interface wlan0} virtual_ router_id 51 priority 150 nopreempt # not preemption, note plus advert_int 1 authentication { auth_type pass auth_ pass lulu } virtual_ipaddress { 192.168.1.144 } track_script { chk_redis } notify_master "/etc/keepalived/scripts/redis_master_slave.sh 127.0.0.1 192.168.1.126 7001 " notify_backup "/etc/keepalived/scripts/redis_backup_ slave.sh 127.0.0.1 192.168.1.126 7001 " notify_fault /etc/keepalived /scripts/redis_fault.sh notify_stop /etc/keepalived/scripts/redis_stop.sh }vrrp_instance redis2 { state BACKUP interface wlan0 } virtual_router_id 50 priority 150 advert_int 1 nopreempt authentication { auth_type PASS auth_pass lulu } virtual_ipaddress { 192.168.1.145 } track_script { chk_ Redis2 } notify_master "/etc/keepalived/scripts/redis_master_slave.sh 127.0.0.1 192.168.1.126 7002 " notify_backup "/etc/keepalived/scripts/ redis_backup_slave.sh 127.0.0.1 192.168.1.126 7002 " notify_fault / etc/keepalived/scripts/redis_fault.sh notify_stop /etc/keepalived/scripts/ redis_stop.sh }
prepare:
! configuration file for keepalivedglobal_defs { router_id test }vrrp_script chk_redis { script "/etc/keepalived/scripts/ redis_check.sh 127.0.0.1 7001 " interval 2 timeout 2 fall 3}vrrp_script chk_redis2 { script "/etc/keepalived/scripts/redis_check.sh 127.0.0.1 7002" interval 2 timeout 2 fall 3}vrrp_instance redis { state BACKUP interface wlan0 } virtual_ router_id 51 priority 100 &Nbsp;advert_int 1 authentication { auth_type PASS auth_pass test } virtual_ipaddress { 192.168.1.144 } track_script { chk_redis } notify_master "/etc/keepalived/scripts/redis _master_slave.sh 127.0.0.1 192.168.1.126 7001 " notify_backup "/etc/ keepalived/scripts/redis_backup_slave.sh 127.0.0.1 192.168.1.126 7001 " notify_fault /etc/keepalived/scripts/redis_fault.sh notify_stop /etc/ keepalived/scripts/redis_stop.sh }vrrp_instance redis2 { state backup interface wlan0 } virtual_router_id 50 advert_int 1 priority 100 authentication { auth_type PASS auth_pass test } virtual_ipaddress { 192.168.1.145 } track_script { chk_redis2 } notify_master "/etc/keepalived/scripts/redis_master_slave.sh 127.0.0.1 192.168.1.126 7002 " notify_backup "/etc/keepalived/scripts/redis_backup_slave.sh 127.0.0.1 192.168.1.126 7002 " notify_fault /etc/keepalived/scripts/redis_fault.sh notify_stop /etc/keepalived/scripts/redis_stop.sh }
Additional scripts are shown in the attachment: Http://files.cnblogs.com/lulu/scripts.rar
Using keepalived to achieve Redis master-slave high Availability