VIP漂移的两种方式

1)通过keepalived的方式,管理虚拟IP的漂移

2)通过MHA自带脚本方式,管理虚拟IP的漂移

MHA脚本方式

虚拟ip漂移的脚本下载地址 -> wget http://download.driverzeng.com/master_ip_failover

如果是wget下载的脚本,需要转换格式:   [root@db03 mha]#  dos2unix master_ip_failover

脚本内容如下

[root@db03 ~]# cat /usr/local/bin/master_ip_failover
#!/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 = '10.0.0.55/24';
my $key = '0';
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";
}

编辑脚本

#根据配置文件中脚本路径编辑
[root@mysql-db03 ~]# vim /etc/mha/master_ip_failover #修改以下几行内容
my $vip = '10.0.0.55/24';
my $key = '';
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down"; #添加执行权限,否则mha无法启动
[root@mysql-db03 ~]# chmod +x /etc/mha/master_ip_failover

修改配置文件

#编辑配置文件
[root@mysql-db03 ~]# vim /etc/mha/app1.cnf #在[server default]标签下添加
[server default]
master_ip_failover_script=/usr/local/bin/master_ip_failover //添加使用MHA自带脚本

手动绑定VIP

#绑定vip
[root@mysql-db01 ~]# ifconfig eth0:0 10.0.0.55/24
[root@db01 bin]# ifconfig eth0:0 down //解绑vip #查看vip
[root@mysql-db01 ~]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 10.0.0.51/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.55/24 brd 10.0.0.255 scope global secondary eth0:0

  

测试ip漂移

#登录db02
[root@mysql-db02 ~]# mysql #查看slave信息
mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.51 //主库是51
Master_User: rep
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysql-db02-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes #停掉主库
[root@mysql-db01 ~]# systemctl stop mysqld //停掉主库Mysql测试 #在db03上查看从库slave信息
mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.52 //主库切换到52
Master_User: rep
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysql-db03-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes #在db01上查看vip信息
[root@mysql-db01 ~]# ip a |grep eth0 //vip没有了
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
inet 10.0.0.51/ brd 10.0.0.255 scope global eth0 #在db02上查看vip信息
[root@mysql-db02 ~]# ip a |grep eth0 //db02出现vip55
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
inet 10.0.0.52/ brd 10.0.0.255 scope global eth0
inet 10.0.0.55/ brd 10.0.0.255 scope global secondary eth0:

nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log >& &
//后台运行mha masterha_check_repl --conf=/etc/mha/app1.cnf //测试mha复制 [root@db03 mha]# masterha_check_status --conf=/etc/mha/app1.cnf //检测mha状态,db03查看主库是否切换52
app1 (pid:) is running(:PING_OK), master:10.0.0.52

mysql高可用架构 -> MHA配置VIP漂移-05的更多相关文章

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

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

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

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

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

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

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

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

  5. MySQL高可用之MHA配置

    本文简单介绍了MySQL的高可用实现方式之一的MHA MHA:Master High Availability,对主节点进行监控,可实现自动故障转移至其它从节点:通过提升某一从节点为新的主节点,基于主 ...

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

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

  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. kickstart无人值守安装之实践篇

    1.系统环境准备 涉及的服务有: DHCP服务 TFTP服务 PXE客户端 HTTP服务 [root@ks ~]# cat /etc/redhat-release CentOS release 6.9 ...

  2. Linux内核设计与实现第八周读书笔记

    第四章 进程调度 进程在操作系统看来是程序的运行态表现形式. 4.1多任务 多任务操作系统就是能同时并发地交互执行多个进程的操作系统. 多任务操作系统会使多个进程处于堵塞或者睡眠状态.这些任务尽管位于 ...

  3. 「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!(dij+bitset)

    从S出发跑dij,从T出发跑dij,顺便最短路计数. 令$F(x)$为$S$到$T$最短路经过$x$的方案数,显然这个是可以用$S$到$x$的方案数乘$T$到$x$的方案数来得到. 然后第一个条件就变 ...

  4. 【贪心】【CF1061B】 Views Matter

    Description 给定一个只有一行的,由 \(n\) 组小正方体组成的方块,每组是由 \(a_i\) 块小正方体竖直堆叠起来的,求最多能抽掉多少块使得它的左视图和俯视图不变.方块不会掉落 Inp ...

  5. [网络流]小M的作物

    小\(M\)的作物(最小割) 做的第一道网络流,因为一个智障错误调了好久嘤嘤嘤 题目描述 小\(M\)在\(MC\)里开辟了两块巨大的耕地\(A\)和\(B\)(你可以认为容量是无穷),现在,小\(P ...

  6. nodejs调用脚本(python/shell)和系统命令

    每种语言都有自己的优势,互相结合起来各取所长程序执行起来效率更高或者说哪种实现方式较简单就用哪个,nodejs是利用子进程来调用系统命令或者文件,文档见http://nodejs.org/api/ch ...

  7. QT 菜单资源设置

    版权声明 该文章原创于Qter开源社区(www.qter.org),作者yafeilinux,转载请注明出处!   导语        在前一篇中我们学习了使用资源文件为主窗口添加菜单图标.这次,我们 ...

  8. 抓包工具Charles

    Charles Charles可以在windows,linux,mac各种操作系统上安装使用,它是java编写一款非免费工具:而fiddler只能在windows系统上使用 Charles抓包前,要确 ...

  9. Windows 2012 R2 安装net4.6.1

    下载并安装Net4.6.1 根据提示下载如下,并安装 https://support.microsoft.com/zh-cn/help/2919355/windows-rt-8-1--windows- ...

  10. c# 的一些基本操作或属性

    http下载文件,不保存到服务器,直接使用浏览器下载 /// <summary> /// 根据url下载文件 /// </summary> /// <param name ...