The double master here is not 2 all at the same time on the application open write, just the same moment only 1 MySQL open to write, another as slave accept the data from the master synchronization, when Master hung off, through keepalived VIP transfer, Turn slave into master to create a highly available environment
The master configuration for keepalived is as follows
Vrrp_script MyCheck {script "/usr/local/keepalived/shutdown.sh" Interval 2 # Check every 2 seconds Weight 2 # default Prio: +2 if connect ok}global_defs { router_id nodea}vrrp_i Nstance vi_1 {State BACKUP interface eth1 virtual_router_id 151 priority 201 Advert_int 1 Nopreempt Authentication { Auth_type pass auth_pass pass } virtual_ipaddress { 192.168.0.100 } track_script { MyCheck }}
The slave configuration is as follows:
Vrrp_script MyCheck { script "/usr/local/keepalived/shutdown.sh" interval 2 # Check every 2 seconds Weight 2 # default Prio: +2 if connect ok}global_defs { router_id nodeb}vrrp_instance vi_1 {State BACKUP Interface eth1 virtual_router_id 151 priority Advert_int 1 nopreempt Authentication { Auth_type pass auth_pass pass } virtual_ipaddress { 192.168.0.100 } Track_ Script { MyCheck }}
A few points to note:
1. Configured as nopreempt to indicate non-preemption, that is, master is resumed by a suspended state, and does not preempt the Vip,slave side to continue to provide services
2. Since nopreempt is supported only in backup, the above master and slave are configured as backup
3.VIP transfer will only occur if the keepalived hangs (not necessarily, and so on), that is, the machine is down, but the MySQL itself hangs up and cannot cause the keepalived to hang, so to detect whether MySQL hangs
4. By detecting MySQL occupied ports, such as 3306 is not difficult to rigorous, to detect the existence of MySQL process is not very rigorous, the best way should be to execute MySQL command as follows:
Mysql-uroot-proot-h 192.168.0.47--connect_timeout=5-e "SELECT 1;"
5. Sometimes even if the keepalived process is gone, but the VIP still exists, through the Ipconfig may not see the VIP, you can pass
Ip-o-F inet Addr Show
You can see that the VIP is still there.
So for the sake of insurance, better add:
IP addr del 192.168.0.100 dev eth1
ThatRemove VIP
6. Data synchronization The block can rely on MySQL itself, you can also use Ali's otter to synchronize
See
http://my.oschina.net/dxqr/blog/524795
Https://github.com/alibaba/otter
MySQL uses keepalived to build dual master