MHA故障切换脚本master_ip_failover结合VIP:

#!/usr/bin/envperlusestrict;usewarningsFATAL=>'all';useGetopt::Long;my($command,$ssh_user,$orig_master_host,$orig_master_ip,$orig_master_port,$new_master_host,$new_master_ip,$new_master_port,$new_master_user,$new_master_password,$app_vip,$netmask,$interface,);GetOptions('command=s'=>\$command,'ssh_user=s'=>\$ssh_user,'orig_master_host=s'=>\$orig_master_host,'orig_master_ip=s'=>\$orig_master_ip,'orig_master_port=i'=>\$orig_master_port,'new_master_host=s'=>\$new_master_host,'new_master_ip=s'=>\$new_master_ip,'new_master_port=i'=>\$new_master_port,'new_master_user=s'=>\$new_master_user,'new_master_password=s'=>\$new_master_password,'app_vip=s'=>\$app_vip,'netmask=i'=>\$netmask,'interface=s'=>\$interface,);my$ssh_start_vip="sudoipaddradd$app_vipdev$interface";my$ssh_stop_vip="sudoipaddrdelete$app_vipdev$interface";my$ssh_flush_arp="sudoarping-c4-A-I$interface$app_vip";exit&main();submain{print"\n\nINSCRIPTTEST====$ssh_stop_vip==$ssh_start_vip===\n\n";if($commandeq"stop"||$commandeq"stopssh"){my$exit_code=1;eval{print"Disablingtheapp_viponoldmaster:$orig_master_host\n";&stop_vip();$exit_code=0;};if($@){warn"GotError:$@\n";exit$exit_code;}exit$exit_code;}elsif($commandeq"start"){my$exit_code=10;eval{print"Enablingtheapp_viponthenewmaster-$new_master_host\n";&start_vip();$exit_code=0;};if($@){warn$@;exit$exit_code;}exit$exit_code;}elsif($commandeq"status"){print"CheckingtheStatusofthescript..OK\n";#`ssh$ssh_user\@cluster1\"$ssh_start_vip\"`;exit0;}else{&usage();exit1;}}#Asimplesystemcallthatenabletheapp_viponthenewmastersubstart_vip(){`ssh$ssh_user\@$new_master_host\"$ssh_start_vip\"`;`ssh$ssh_user\@$new_master_host\"$ssh_flush_arp\"`;}#Asimplesystemcallthatdisabletheapp_vipontheold_mastersubstop_vip(){return0unless($ssh_user);`ssh$ssh_user\@$orig_master_host\"$ssh_stop_vip\"`;}subusage{print"Usage:master_ip_failover--command=start|stop|stopssh|status--orig_master_host=host--orig_master_ip=ip--orig_master_port=port--new_master_host=host--new_master_ip=ip--new_master_port=port\n";}