MHA故障切换脚本master_ip_failover结合VIP
admin
2023-05-18 03:21:46
0

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

#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Getopt::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 = "sudo ip addr add $app_vip dev $interface";
my $ssh_stop_vip = "sudo ip addr delete $app_vip dev $interface";
my $ssh_flush_arp = "sudo arping -c 4 -A -I $interface $app_vip";
exit &main();
sub main {
    print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";
    if ( $command eq "stop" || $command eq "stopssh" ) {
        my $exit_code = 1;
        eval {
            print "Disabling the app_vip on old master: $orig_master_host \n";
            &stop_vip();
            $exit_code = 0;
        };
        if ($@) {
            warn "Got Error: $@\n";
            exit $exit_code;
        }
        exit $exit_code;
    }
    elsif ( $command eq "start" ) {
        my $exit_code = 10;
        eval {
            print "Enabling the app_vip  on the new master - $new_master_host \n";
            &start_vip();
            $exit_code = 0;
        };
        if ($@) {
            warn $@;
            exit $exit_code;
        }
        exit $exit_code;
    }
    elsif ( $command eq "status" ) {
        print "Checking the Status of the script.. OK \n";
        #`ssh $ssh_user\@cluster1 \" $ssh_start_vip \"`;
        exit 0;
    }
    else {
        &usage();
        exit 1;
    }
}
# A simple system call that enable the app_vip on the new master
sub start_vip() {
    `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
    `ssh $ssh_user\@$new_master_host \" $ssh_flush_arp \"`;
}
# A simple system call that disable the app_vip on the old_master
sub stop_vip() {
     return 0  unless  ($ssh_user);
    `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
}
sub usage {
    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";
}


相关内容

热门资讯

广西一大楼遭雷击,电光直贯楼顶   金城江百旺桥附近楼宇遭雷击  避雷针“接招”未伤人员 电梯“躺枪”停运待修5月15日6时54分,...
伊朗宣布5月19日起恢复股票市... 当地时间16日,伊朗证券交易组织表示,伊朗股票市场将于5月19日起恢复交易。伊朗证券交易组织负责交易...
联合国秘书长欢迎黎以延长停火 新华社联合国5月16日电(记者尚绪谦)联合国秘书长发言人办公室16日说,秘书长古特雷斯欢迎黎巴嫩与以...
如何让“彩礼”回归于“礼”?一... 黄河水浇灌出的宁夏红寺堡是中国最大的生态移民安置区,宁南八县的乡音在此交汇,对美好生活的期盼与发展中...
原创 外... 外星翻译官的翻车现场:地球语言真的太难了! 银河系翻译官协会(假想机构)最近发布了一份年度报告,总...
首飞成功!已突破大重量载荷发射... 科技日报记者 付毅飞 实习生 张城辉 记者从蓝箭航天获悉,5月14日11时0分,朱雀二号改进型遥五运...
京东携手MAXHUB共推AI智... PChome消息,近日,京东与智能会议平板领域领军品牌MAXHUB正式签署战略合作协议,标志着双方战...
29个智能气象站启动业务试运行 本报北京5月15日电(记者李红梅)记者从中国气象局获悉:北京密云等29个智能气象站已于近日启动业务试...
广西一载15人车辆坠河,10人... 记者从广西环江毛南族自治县相关方面获悉,据初步了解,5月16日21时30分许,一辆汽车在环江县洛阳镇...
iOS 26.5更新苹果地图两... 苹果地图是iOS 26.5此次更新中获得新功能的应用之一。以下是地图用户需要了解的最新变化。 推荐...