首页 > 其他分享 >附件文件-master_ip_failover.sh

附件文件-master_ip_failover.sh

时间:2023-03-26 19:01:18浏览次数:41  
标签:ip failover host vip sh master ssh new my

#!/usr/bin/env perl

#  Copyright (C) 2011 DeNA Co.,Ltd.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#  Foundation, Inc.,
#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

## Note: This is a sample script and is not complete. Modify the script based on your environment.
#!/usr/bin/env perl
#!/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
);

#my $gateway = '10.77.133.1';
my $vip  = shift;
#my $bcast = '10.77.133.255';
#my $netmask = '255.255.255.0';
my $interface = 'ens33';
my $key = shift;
#my $ssh_start_vip = "sudo /sbin/ifconfig $interface:$key $vip netmask $netmask && sudo /sbin/arping -f -q -c 5 -w 5 -I $interface -s $vip  -U $gateway";
my $ssh_stop_vip = "sudo /sbin/ifconfig $interface:$key down";

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,
);

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 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 VIP - $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";
        exit 0;
    }
    else {
        &usage();
        exit 1;
    }
}

sub start_vip() {
    my $bcast  = `ssh $ssh_user\@$new_master_host sudo /sbin/ifconfig | grep 'Bcast' | head -1 | awk '{print \$3}' | awk -F":" '{print \$2}'`;
    chomp $bcast;
    my $gateway  = `ssh $ssh_user\@$new_master_host sudo /sbin/route -n  | grep 'UG' | awk '{print \$2}'`;
    chomp $gateway;
    my $netmask  = `ssh $ssh_user\@$new_master_host sudo /sbin/ifconfig | grep 'Bcast' | head -1 | awk '{print \$4}' | awk -F":" '{print \$2}'`;
    chomp $netmask;
    my $ssh_start_vip = "sudo /sbin/ifconfig $interface:$key $vip broadcast $bcast netmask $netmask && sudo /sbin/arping -f -q -c 5 -w 5 -I $interface -s $vip  -U $gateway";
    print "=======$ssh_start_vip=================\n";
    `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
sub stop_vip() {
    my $ssh_user = "admin";
    print "=======$ssh_stop_vip==================\n";
    `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";
}

标签:ip,failover,host,vip,sh,master,ssh,new,my
From: https://blog.51cto.com/zwl28/6150704

相关文章

  • Linux中/etc下面passwd和shadow文件介绍
    1./etc/passwd  1.(1)用户名:用户登录时使用的名称,通常由字母、数字和符号组成,用户名必须是唯一的(2) 口令: Linux系统中的用户口令经加密后都保存在/etc/ shadow......
  • DX Shadow Map
    前言​ 目前我们以所学的渲染方式还不能表现出阴影,因此本篇将介绍阴影贴图原理、存在的问题、如何解决这些问题、实现例子阴影贴图原理思想:光源看不到而摄像机可以看......
  • sharding-jdbc使用注意事项
    1使用原则 1)单表数据量达到5000万以上,考虑使用分库分表方案分表 2)读写分离可以考虑使用2列设计规范 1)主键使用bigint类型,使用雪花算法生成 2)禁止使用外键 ......
  • IntelliWeb 中嵌入Silverlight/Flash方法
       简介:intelliWeb是基于构件、Ajax、RichClient技术的J2EE应用快速开发平台。   嵌入Silverlight/Flash方法很简单,把ActiveX放到e:Page里面就可以了  下面我......
  • 【A-005】基于SSH的校园网上订餐系统(含论文)
    开发环境:Eclipse/MyEclipse、Tomcat8、Jdk1.8数据库:MySQL项目介绍:为了顺应时代潮流的发展,便捷人民的生活,提高群众的生活质量,本系统应运而生。在了解了相关线上网上订餐......
  • Vmware UEFI装Windows8 Image type X64 is not support by this IA32 shell
      挂载ISO后,跟着启动虚拟机,会见到显示"unsuccessfulEFInetwork"  输入bootiaX86.EFI;回车 "ImagetypeIA32isnotsupportedbythisX64shell"或者:......
  • wine 安装photoshop CS4和flash builder 4 方法
    我的home文件夹是 /home/luozhuang请根据自己实际情况修改.wine这些都是隐藏文件请根据需要修改文件浏览器显示隐藏文件安装photoshopCS4:需要自己安装atmlib.dll......
  • Linux中/etc下面passwd和shadow文件介绍
    Linux/etc/passwd内容Linux系统中的/etc/passwd文件,是系统用户配置文件,存储了系统中所有用户的基本信息,并且所有用户都可以对此文件执行读操作。[root@localhost~]#......
  • K8s CrashLoopBackOff 如何排障?
    什么是CrashLoopBackOff CrashLoopBackOff是在k8s中较常见的一种Pod异常状态,最直接的表述,集群中的Pod在不断的重启挂掉,一直循环,往往Pod运行几秒钟因为程序异......
  • C#/.NET Core跨平台分布式微服务/DDD领域驱动架构设计VIP实战
    阿笨NET课程详情腾讯课堂官网 https://abennet.ke.qq.com/【报名请咨询老师扣扣:422159763】 ......