脚本如下:
 
 
 
 
 
#!/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 = '103.75.1.30/26';  # 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";
}

mysql高可用架构mha之master_ip_failover脚本的更多相关文章

  1. 【DB宝42】MySQL高可用架构MHA+ProxySQL实现读写分离和负载均衡

    目录 一.MHA+ProxySQL架构 二.快速搭建MHA环境 2.1 下载MHA镜像 2.2 编辑yml文件,创建MHA相关容器 2.3 安装docker-compose软件(若已安装,可忽略) 2 ...

  2. MySQL高可用架构-MHA环境部署记录

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

  3. mysql高可用架构MHA搭建(centos7+mysql5.7.28)

    无论是传统行业,还是互联网行业,数据可用性都是至关重要的,虽然现在已经步入大数据时代,nosql比较流行,但是作为数据持久化及事务性的关系型数据库依然是项目首选,比如mysql. 现在几乎所有的公司项 ...

  4. mysql高可用架构 -> MHA配置VIP漂移-05

    VIP漂移的两种方式 1)通过keepalived的方式,管理虚拟IP的漂移 2)通过MHA自带脚本方式,管理虚拟IP的漂移 MHA脚本方式 虚拟ip漂移的脚本下载地址 -> wget http ...

  5. mysql高可用架构 -> MHA部署-04

    MHA架构图 本次MHA的部署基于GTID复制成功构建,普通主从复制也可以构建MHA架构. 下载所需的软件包 mkdir /server/tools -p //创建存放包的目录 [root@db01 ...

  6. mysql高可用架构 -> MHA配置binlog-server-06

    前期准备 1.准备一台新的mysql实例(db03),GTID必须开启. 2.将来binlog接收目录,不能和主库binlog目录一样 停止mha masterha_stop --conf=/etc/ ...

  7. mysql高可用架构 -> MHA主从复制-03

    GTID复制技术说明 GTID的全称为 global transaction identifier ,可以翻译为全局事务标示符,GTID在原始master上的事务提交时被创建.GTID需要在全局的主- ...

  8. mysql高可用架构 -> MHA简介-01

    作者简介 松信嘉範:MySQL/Linux专家2001年索尼公司入职2001年开始使用oracle2004年开始使用MySQL2006年9月-2010年8月MySQL从事顾问2010年-2012年 D ...

  9. mysql高可用架构 -> MHA环境准备-02

    环境准备 环境检查(三个测试节点的环境都应该是一样的,只有ip不同) [root@db01 bin]# cat /etc/redhat-release //系统版本 CentOS Linux rele ...

随机推荐

  1. Object-C--->Swift之(十一)属性观察者

    属性观察者机制能让程序在属性被赋值时获得运行代码的机会,用来监视属性的除初始化之外的属性值变化,当属性值发生改变时能够对此作出响应 详细包含两个特殊的回调方法: willSet(newValue):被 ...

  2. 深圳MPD大会 讲师演讲稿 2014-10

     深圳MPD大会 讲师演讲稿 2014-10  互联网下的蛋-姜志辉.pdf: http://www.t00y.com/file/76704370 俞炜-互联网研发整形术 终于版.pdf: htt ...

  3. POJ 1300 Door Man(欧拉通路)

    题目描写叙述: 你是一座大庄园的管家. 庄园有非常多房间,编号为 0.1.2.3..... 你的主人是一个心不在 焉的人,常常沿着走廊任意地把房间的门打开.多年来,你掌握了一个诀窍:沿着一个通道,穿 ...

  4. Setup Script in SoapUI - 停止项目运行 (abort project)

    TestSuite需要依赖一个先决条件(比如Login) 当Login失败则立即停止Project运行 在Project的Setup Script的代码如下 import com.eviware.so ...

  5. What is an ISAPI Extension?

    https://www.codeproject.com/Articles/1432/What-is-an-ISAPI-Extension Introduction Unless you have be ...

  6. sqlserver 触发器实例代码

    定义: 何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序.触发器是一个特殊的存储过程. 常见的触发器有三种:分别应用于Insert , Update ...

  7. E20171014-hm

    Sibling   n. 兄弟,姐妹; [生] 同科,同属; [人] 氏族成员;

  8. [Apple开发者帐户帮助]八、管理档案(1)创建开发配置文件

    您可以在开发人员帐户中创建开发配置文件,以便在Xcode中手动签署应用程序时使用. 在开始之前,您需要一个App ID,一个或多个开发证书以及一个或多个已注册的设备.您可以使用Xcode为您管理的Ap ...

  9. ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod

    因为突然要用到cocospod,突然发现在使用pod install的时候出现 -bash: pod: command not found 我去-不知道为什么,然后我就想重新安装下cocospod,在 ...

  10. dialog的各类显示方法

    图1效果:该效果是当按返回按钮时弹出一个提示,来确保无误操作,采用常见的对话框样式. 代码: 创建对话框方法dialog() protected void dialog() {  AlertDialo ...