#!/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 $vip = '192.168.102.102/24';  # Virtual IP 
my $key = "1"; 
my $ssh_start_vip = "/sbin/ifconfig bond1:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig bond1:$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" ) {

# $orig_master_host, $orig_master_ip, $orig_master_port are passed.
        # If you manage master ip address at global catalog database,
        # invalidate orig_master_ip here.
        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" ) {

# all arguments are passed.
        # If you manage master ip address at global catalog database,
        # activate new_master_ip here.
        # You can also grant write access (create user, set read_only=0, etc) here.
        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"; 
        `ssh $ssh_user\@$orig_master_host \" $ssh_start_vip \"`;
        exit 0;
    }
    else {
        &usage();
        exit 1;
    }
}

# A simple system call that enable the VIP on the new master 
sub start_vip() {
    `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
# A simple system call that disable the VIP on the old_master
sub stop_vip() {
    `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";
}

[MHA]master_ip_failover 测试可以使用的IP 地址切换脚本的更多相关文章

  1. 编写管理IP地址参数脚本(永久性)

    1.用各种命令取出/etc/passwd文件前5行的最后一个字母.(2种) 2.编写管理IP地址参数脚本(永久性) a.只能用sed命令完成 b.提示用户变量赋值(IP.子网掩码.网关.DNS等) c ...

  2. NetSetMan IP地址切换工具

    http://www.netsetman.com/en/freeware NetSetMan NetSetMan是一个网络设置管理器,它可以很容易在6种不同的,视觉结构化的配置之间切换,包括: IP地 ...

  3. TC命令流量控制测试(针对具体IP地址和IP协议)

    这里测试系统为Linux操作系统,通过简单的TC命令来实现对带宽的控制. 1对具体IP地址的流量控制 这里采用iperf来进行带宽的测试,首先在服务器和客户端都安装上iperf软件,通过该软件下的命令 ...

  4. [转]IP动态切换脚本

    因为公司办公室要设置固定IP才行,而家里的IP段和公司是不一样的,家里采用了DHCP机制,这样每次就得改IP设置,很是不方便,就写了这个脚本来动态切换,很流畅的说!WINXP,WIN7测试通过~嘿嘿~ ...

  5. IP自动切换脚本

    @echo off & cls & color 47 & mode con cols=80 lines=25 & title [IP自动切换工具]clsecho. ec ...

  6. 自动设置IP地址bat脚本

    自动获取IP及DNS: netsh interface ip set address name="本地连接" source=dhcpnetsh interface ip set d ...

  7. MySQL MHA 搭建&测试(环境:CentOS7 + MySQL5.7.23)

    MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Face ...

  8. 解析私有IP地址和公网IP地址

    局域网私有IP地址上外网的原理 IP地址分为两部分,网络号和主机号,这种分法应用在私有和公有IP地址上.一个局域网中,为了该局域网的安全,我们应用了私有IP地址,为了和Internet中的其他主机进行 ...

  9. 教你怎样写自定义IP地址算法

    通过IP地址可以看到算法规律,写成自定义IP地址,也可以把IP地址转为自定格式的IP地址.也可以用于加密一些明文数字.起始次方可自定义(以1次方和0次方为例) a.以下写正反算法(以1次方为最小单位) ...

随机推荐

  1. solr6.5.0(windows)教程

    第一步:安装Tomcat8重命名结尾加上solr6(自定义) 第二步: 解压solr,把solr-6.5.0\solr-6.5.0\server\solr-webapp下的webapp文件夹拷贝到to ...

  2. 连接mysql数据库时提示2003 can't connect to MySQL server on ip(10060)的解决办法

    今天部署 JavaWeb 项目到云服务器,突然出现can t connect to MySQL server on ip的问题 经过了一些检查,认为很有可能是防火墙的原因.下面是检查的具体操作: 因为 ...

  3. 关于cin的缓存区影响效果

    1. 当缓冲区中有残留数据时,cin函数会直接去读取这些残留数据而不会请求键盘输入.而且,回车符也会被存入输入缓冲区中. int num{}; while(cin>>num) cout&l ...

  4. SpringMvc请求处理流程与源码探秘

    流程梳理 dispatcherServlet作为前端控制器的主要作用就是接受请求与处理响应. 不过它不是传统意义上的servlet,它在接受到请求后采用转发的方式,将具体工作交给专业人士去做. 参与角 ...

  5. linux学习笔记 yum 在线管理软件包

    -y  如果yum在工作过程中需要使用者响应.这个参数可以直接回答yes #yum list 列出资源库中所有可安装或者可更新的rpm包 #yum perl 列出为perl的包 #yum perl* ...

  6. vue注册和简单使用

      组件的出现就是为了解决页面布局等等一些列的问题. vue中的组件分为两种,全局组件和局部组件. 一  . 注册全局组件 通过Vue.component()创建一个全局组件之后,我们可以在一个通过  ...

  7. Mysql You can change this value on the server by setting the max_allowed_packet' variable. 异常

    MySQL根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会被max_allowed_packet 参数限制掉,导致失败. 查看目前配置, Windows 系统 配置文件为 my ...

  8. STM32——C语言课堂原代码

    指针 /* ============================================================================ Name : Hello.c Au ...

  9. node cluster模块,仿多线程并发调用,

    worker.js var cluster = require('cluster')function fibo(n) { return n == 0 ? 0 : n > 1 ? fibo(n - ...

  10. incomplete type is not allowed ofstream

    错误: incomplete type is not allowed 解决方案: #include<fstream>