脚本如下:
 
 
 
 
 
#!/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. Android MTP 文件浏览Demo

    本apk实现了MTP文件浏览的简单功能. 通过Demo apk能够浏览连接到当前设备上的MTP设备上的文件. Demo路径:http://download.csdn.net/detail/sailin ...

  2. oracle约束总结(not null/unique/primary key/foreign key/check)

    约束(constraint):对创建的表的列属性.字段进行的限制. 诸如:not null/unique/primary key/foreign key/check 作用范围:         ①列级 ...

  3. (转)C++ CListCtrl使用技巧的摘抄

    转:http://blog.csdn.net/sanshao27/article/details/1888315 1. CListCtrl 风格 LVS_ICON: 为每个item显示大图标      ...

  4. 两种Linux下非交互式命令的实现

    一.概述 在Linux环境,有多种实现自己主动化的脚本语言.如Shell.Python.Perl.Tcl等. Shell语言因与Shell外壳结合紧密,是最常见的实现自己主动化的脚本语言. 同一时候, ...

  5. Java进程堆外内存(off heap)大小

    一.使用ByteBuffer.allocateDirect分配的off heap内存大小 本机进程 在Jvisualvm中安装 Mbeans插件.然后查看java.nio/BufferPool/dir ...

  6. Android---58---初学GPS定位

    GPS英文是Global Positioning System 全球定位系统的简称. Android为GPS功能支持专门提供了一个LocationManager,位置管理器.全部GPS定位相关的服务. ...

  7. HDOJ 题目2475 Box(link cut tree去点找祖先)

    Box Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  8. poj 1190 生日蛋糕 , 强剪枝

    题意: 制作一个体积为Nπ(N<=10000)的M(M<=20)层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆 ...

  9. ORACLE 11G 怎样改动 awr 的保留期限小于8天

     ORACLE 11G 怎样改动 awr 的保留期限小于8天 Oracle Database 11g 默认具备一个系统定义的Moving Window Baseline,该基线相应于 AWR 保留 ...

  10. HDU 5446 CRT+Lucas+快速乘

    Unknown Treasure Problem Description On the way to the next secret treasure hiding place, the mathem ...