[MHA]master_ip_failover 测试可以使用的IP 地址切换脚本

#!/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 ([email protected]) {
            warn "Got Error: [email protected]\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 ([email protected]) {
            warn [email protected];
            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";
}

时间: 2024-08-08 10:21:09

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

IP地址切换脚本

https://mikebeach.org/2012/05/02/how-to-script-a-change-to-a-static-ip-address-or-dhcp-ip-address-in-windows/ netsh interface ipv4 set address name="Local Area Connection" static 10.145.1.249 255.255.255.0 10.145.1.4 netsh interface ip set dns &

抓取kvm虚拟机IP地址功能脚本

这个脚本是利用你前期抓取出来好的IP与mac地址对关系表,然后根据mac地址来找IP地址. 脚本如下: #!/usr/local/python3/bin/python3 import re,os,sys,time mac_add = [] vir_name = sys.argv[1] #打开给定的虚拟机名称的xml文件来查找mac地址 with open('/etc/libvirt/qemu/%s.xml'%vir_name,'r') as f: for line in f: line = li

NetSetMan IP地址切换工具

http://www.netsetman.com/en/freeware NetSetMan NetSetMan是一个网络设置管理器,它可以很容易在6种不同的,视觉结构化的配置之间切换,包括: IP地址(IPv4的和IPv6!) 网关(包括跃点数 Metric) DNS 服务器 WINS 服务器 WiFi 管理 计算机名 工作组 默认打印机 网络驱动器 网卡状态 连接(RAS/DUN/PPP/VPN) DNS 后缀 路由表 SMTP 服务器 Hosts 文件条目 系统设置 MAC 地址 脚本(B

怎么解决电脑/手机上IP地址切换方法!

现如今啊有时候,因工作原因需要不同的IP,这个时候我们应该如何来切换电脑IP呢?许多人会说使用换IP软件啊,那么换IP软件真的可以实现自动切换电脑IP地址吗?让我们一起来验证下.IP简介:生活中我们怎么去修改代理自己电脑和手机的网络IP地址,IP地址是每个联网设备的IP,根据这个IP可以进行网络数据传输,实现上网功能,有些业务及工作需要,要改变下自己的IP地址.怎么快速的修改自己IP呢,教大家轻松简单快速的修改自己IP地址,今天说的是用IP软件快速修改电脑的IP地址.百度搜索兔子IP代理下载软件

IP地址查询脚本

晚上看新闻时无意看到了淘宝IP查询API的信息,然后就顺手写了一个IP地址查询的脚本来分享 先贴出淘宝IP查询API的使用方法,以供读者研究: 1. 请求接口(GET): /service/getIpInfo.php?ip=[ip地址字串] 2. 响应信息: (json格式的)国家 .省(自治区或直辖市).市(县).运营商 3. 返回数据格式: {"code":0,"data":{"ip":"210.75.225.254",&

设置IP地址shell脚本

#!/bin/bash A="IPADDR.*" B="NETMASK.*" C="GATEWAY.*" D="DNS1.*" E="/etc/sysconfig/network-scripts/ifcfg-eth1" F="cat $E | sed -n '/BOOTP/p'" if [ ! "$F" = "BOOTPROTO=dhcp" ] t

自动设置IP地址bat脚本

自动获取IP及DNS: netsh interface ip set address name="本地连接" source=dhcpnetsh interface ip set dnsservers name="本地连接" source=dhcp 设置静态IP及DNS: netsh interface ip set address name="本地连接" static 192.168.1.96 255.255.255.0 192.168.1.1n

添加网卡子接口ip地址shell脚本

#!/bin/bash #author wangning #date 2017-7-15 #qq 1198143315 #Email [email protected] ############################### define color ############################## red="\033[31m" green="\033[32m" yellow="\033[33m" color="\0

搭建DHCP服务实现动态分配IP地址【详解】

搭建DHCP服务实现动态分配IP地址   一:实验内容 DHCP服务器工作原理 使用DHCP为局域网中的机器分配IP地址 使用DHCP为服务器分配固定IP地址   二:实验环境: 服务端:xuegod63  IP:192.168.1.70 客户端:RHEL-6.2-64-71  IP:192.168.1.71 客户端:RHEL-6.2-64-72  IP:192.168.1.72   三:实验步骤 第一块:概述 1:DHCP服务概述: 名称:DHCP  - Dynamic Host Config