脚本如下:
 
 
 
 
 
#!/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. 第8章 处理ISDN故障

    第8章 处理ISDN故障 一.ISDN基本原理 二.常见ISDN故障 ISDN问题分成3类:配置不当的路由器.物理线缆和ISDN协议.配置不当的交换机. 1.配置不当的路由器 配置不当由于不同原因:t ...

  2. Live555研究之中的一个 源码编译

                                                Live555研究之中的一个 源代码编译 Live555 是一个为流媒体提供解决方式的跨平台的C++开源项目,它 ...

  3. word2vec 中的数学原理具体解释(六)若干源代码细节

      word2vec 是 Google 于 2013 年开源推出的一个用于获取 word vector 的工具包,它简单.高效,因此引起了非常多人的关注.因为 word2vec 的作者 Tomas M ...

  4. 【CODEFORCES】 D. CGCDSSQ

    D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  5. Linux下的应用程序开机自启动

    Linux下的应用程序开机自启动,目前我知道的有2种: 1.将启动语句写到/etc/rc.local 2.在init.d放置启动脚本 第一种,很简单,直接写进去就行,比如说: /db/mongodb/ ...

  6. Configuration.SectionGroups

    对于一个空的配置文件,默认自带的sectiongroups 默认有10个section节点 1 ConfigurationSectionGroupName=system.runtime.seriali ...

  7. Java 下的函数对象

    1. 举例 如我们要创建一个对大小写敏感的,按照字母序排序的 Set,我们需要向 Set 的构造器传入 String.CASE_INSENTIVE_ORDER 的比较器: Set<String& ...

  8. P2657 [SCOI2009]windy数 数位dp

    数位dp之前完全没接触过,所以NOIP之前搞一下.数位dp就是一种dp,emm……用来求解区间[L,R]内满足某个性质的数的个数,且这个性质与数的大小无关. 在这道题中,dp[i][j]代表考虑了i位 ...

  9. 60.extjs-布局 (在column布局中使用fieldset 和 在fieldset中使用column布局)

    转自:https://blog.csdn.net/snn1410/article/details/8817821/ 在标准的html中,需要把输入项都放到fieldset中,一次来显示分组结构.虽然E ...

  10. handbook/CentOS/使用免费SSL证书让网站支持HTTPS访问.md