#!/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. bootstrapTable

    一个详细的教程 table参数 bootstrap table使用总结 BootstrapTable使用实例 事件event 事件函数的用法: 方法1 $('#table').bootstrapTab ...

  2. Codeforces 948D Perfect Security 【01字典树】

    <题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...

  3. POJ2387 Til the Cows Come Home【Kruscal】

    题目链接>>> 题目大意: 谷仓之间有一些路径长度,然后要在这些谷仓之间建立一些互联网,花费的成本与长度成正比,,并且要使这些边连起来看的像一课“树”,然后使成本最大 解题思路: 最 ...

  4. Pandas学习1 --- 数据载入

    import numpy as np import pandas as pd 数据加载 首先,我们需要将收集的数据加载到内存中,才能进行进一步的操作.pandas提供了非常多的读取数据的函数,分别应用 ...

  5. 躲不掉的 lambda 表达式

    lambda 表达式是 Java8 的新特性,虽说都发布很久了,但是不到万不得已是肯定不会研究这个的,现在就是那不得不学习的时候了. 本文主要说一下什么 lambda 表达式.Java 中为什么要有 ...

  6. Java Lambda基础——Function, Consumer, Predicate, Supplier, 及FunctionalInterface接口

    这几个接口经常与Lambda结合使用,网上当然也有很多介绍,不过有些过于繁琐,有些又偏简单,秉着实用主义精神,今天这里折中一下,把介绍的内容分为两部分,第一部分相当于TLDR,总结几个"口诀 ...

  7. 【可靠性】Mysql 5.7 降低了半同步复制-数据丢失的风险

    如果你的生产线开启了半同步复制,那么对数据的一致性会要求较高,但在MySQL5.5/5.6里,会存在数据不一致的风险.有这么一个场景,客户端提交了一个事务,master把binlog发送给slave, ...

  8. 练习七 Procedure中使用DDL

    1 在存储过程中使用ddl语句有如下异常: create or replace procedure test_create_table (Table_Name in VARCHAR2, column_ ...

  9. Xamarin SQLite教程Xamarin.iOS项目添加引用

    Xamarin SQLite教程Xamarin.iOS项目添加引用 使用直接方式访问SQLite数据库,需要将System.Data和Mono.Data.SQlite库导入到创建的项目中.下面将分别讲 ...

  10. SQL——用FOR XML Path完成字符串的聚合