脚本如下:
 
 
 
 
 
#!/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. POJ 2104 K-th Number(区间第k大数)(平方切割,归并树,划分树)

    题目链接: http://poj.org/problem? id=2104 解题思路: 由于查询的个数m非常大.朴素的求法无法在规定时间内求解. 因此应该选用合理的方式维护数据来做到高效地查询. 假设 ...

  2. [Vue @Component] Pass Props Between Components with Vue Slot Scope & renderless component

    Components with slots can expose their data by passing it into the slot and exposing the data using  ...

  3. jq 地区(省市县区)联动菜单

    <pre name="code" class="html"><pre name="code" class="ph ...

  4. 京东电商API

    大家好~~2016年了~转眼过去三年了...一年没有更新博客了.. ..在上一年里,遇到了几个好哥们,一起写程序一起装逼,以下给大家讲述一下工作上遇到的技术问题,由于这个我開始弄的时候也比較麻烦,不知 ...

  5. android 请求网络异步载入

    /** * 封装ProecssDialog对话框 * */ public class LoadDialog extends ProgressDialog { private String title ...

  6. 极客标签互动课程系列 - Javascript生成SVG动画素描特效

    课程描写叙述:在这个课程中,我们将介绍SVG.而且介绍怎样使用javascript来控制SVG生成素描动画效果 课程地址:http://www.gbtags.com/gb/gbliblist/21.h ...

  7. 记录 mysql sql limit 0,100问题

    某个场景分页查询出第一页的数据,, limit 0,100  第一页 limit 100,100 第二页 limit 200,100 第三页 select * from user limit 0,10 ...

  8. C++中的继承与虚函数各种概念

    虚继承与一般继承 虚继承和一般的继承不同,一般的继承,在目前大多数的C++编译器实现的对象模型中,派生类对象会直接包含基类对象的字段.而虚继承的情况,派生类对象不会直接包含基类对象的字段,而是通过一个 ...

  9. Android应用资源

    Java刚開始学习的人直接在Java源代码使用"hello" 和123 类型的字符串和整型.但时间长了就会忘记当初定义的原因,有经验的或许会定义字符串常量ResultSet.TYP ...

  10. Execution Order In a Test Plan

    1.Config Element 2.Pre  Processors 3.Timer 4.Sampler 5.Post Processors 6.Assertions 7.Listener