MHA脚本master_ip_failover.pl(三)
#!/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.133.500/24;
此处为虚拟ip的地址
my $key = '1';
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth0:$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" ) {
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" ) {
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";
exit 0;
}
else {
&usage();
exit 1;
}
}
sub start_vip() {
`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
sub stop_vip() {
return 0 unless ($ssh_user);
`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";
}
MHA脚本master_ip_failover.pl(三)的更多相关文章
- mha && 脚本拉起
ip分布: vip 192.168.238.222 mha_manager 192.168.238.131 监控服务器 master 192.168.238.128 主库GTID复制模式 slave ...
- MySQL MHA之 master_ip_failover.sh脚本
master_ip_failover.sh脚本是用perl编写的,可以在mha-manager源码包中可以找到,下面给出的结合keepalived进行自动切换的脚本: [root@mha script ...
- mysql高可用架构mha之master_ip_failover脚本
脚本如下: #!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use Getopt::Long; my ...
- Shell中调用、引用、包含另一个脚本文件的三种方法
脚本 first (测试示例1) first#!/bin/bashecho 'your are in first file' 方法一:使用source #!/bin/bashecho 'your ar ...
- Shell脚本笔记(三)shell中的数学计算
shell中的数学计算 一.使用方括号 #!/bin/bash a= b= c= res=$[$a * ($c-$b)] echo $res 二.使用(()) +)) ((i=+)) b=$((-*) ...
- Shell脚本编程(三):shell参数传递
我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 实例 以下实例我们向脚本传递三 ...
- loadrunner之WebServices协议脚本编写(三种请求模式)
以天气预报网站为例:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 一.web_service_call模式 步骤如下 ...
- 【shell脚本】将三个数字进行升序排序===numSort.sh
从命令输入三个数字进行升序排序(冒泡排序) 原理:比较两个相邻的元素,将值大的元素交换至右端. 脚本内容: [root@VM_0_10_centos shellScript]# cat numSort ...
- iredmail安装脚本分析(三)---conf/global DISTRO值的来源及操作系统的判断
作者在引入conf/global 文件时,就已经对操作系统的类型进行判断,同时也对DISTRO进行了赋值. 部分代码,如图: 显然文件里的KERNEL_NAME的值就是判断完成的操作系统,具体分析该值 ...
随机推荐
- Java编程基础-变量
1.变量的定义. 变量与常量相对应,变量是在程序运行过程中它的值允许改变的量,变量可以通过变量名访问. 2.Java中的三大变量 (1).类变量.又称为静态变量,在类中定义类的属性时,使用static ...
- thinkphp分页集成
控制器: $User = M('webcase'); // 实例化 User 对象 $list = $User->order('id desc')->page($_GET['p'].', ...
- AFNetworking 一般用法
AFNetworking是一个用于iOS.macOS.watchOS和tvOS的功能强大的网络库.它构建在基础URL加载系统之上,扩展了强大的高级网络抽象,并将其构建为Cocoa.它有一个模块化的架构 ...
- 读懂《HTML5网页开发实例详解》这本书
你还在用Flash嘛?帮主早不用了 乔布斯生前在公开信<Flash之我见>中预言:像HTML 5这样在移动时代中创立的新标准,将会在移动设备上获得胜利. ——国际巨头Google.苹果等都 ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
- Python字符编码补充
字符编码: Python字符编码贯穿Python学习的始终,现在应用的是Python2中字符编码的问题是很多的. 这次是要彻底解决Python字符编码的问题!!! 1 字符编码的发展过程: 1 .AS ...
- NULL Pointer Dereference(转)
0x00 漏洞代码 null_dereference.c: #include <linux/init.h> #include <linux/module.h> #include ...
- Python IDE推荐
八个最佳Python IDE 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Python是一种功能强大.语言简洁的编程语言.本文向大家推荐8个适合pyt ...
- Lucene原理与代码分析
http://www.cnblogs.com/forfuture1978/category/300665.html
- Sass 构建之 7-1模式
Sass 项目结构之7-1模式 7-1模式的结构:7个文件夹,1个文件. 基本上,你需要将所有的部件放进7个不同的文件夹和一个位于根目录的文件(通常用main.scss或者app.scss) 编译时会 ...