MySQL5.7.36之高可用架构部署-MHA-VIP漂移

1、创建文件 vi /usr/local/bin/master_vip_mysql_mha

复制代码
#!/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.31.220/24'; #同一段落IP,需要管理员那边申请
my $key = '1';
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip"; #如果你的网卡名称不是ens33,那就需要修改
my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down"; #如果你的网卡名称不是ens33,那就需要修改
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";
}

2、将master_vip_mysql_mha文件进行文本转化

复制代码
yum -y install dos2unix*
dos2unix /usr/local/bin/master_vip_mysql_mha

3、将master_vip_mysql_mha文件添加可执行文件

复制代码
chmod +x /usr/local/bin/master_vip_mysql_mha

4、在manager配置文件【server default】中添加master_ip_failover_script记录

复制代码
vi /etc/mha/app1.cnf
master_ip_failover_script=/usr/local/bin/master_vip_mysql_mha

5、在此时的主库上,手动生成第一个vip地址

复制代码
ifconfig ens33:1 192.168.31.220/24
如果指令错误请采用以下指令删除:ifconfig ens33:1 down 

6、重启mha

复制代码
masterha_stop --conf=/etc/mha/app1.cnf #停止
nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log 2>&1 & #启动
masterha_check_status --conf=/etc/mha/app1.cnf #查看MHA状态
相关推荐
聆风吟º1 天前
Oracle到KingbaseES数据库迁移:全流程实战指南与避坑总结
数据库·oracle·数据库迁移·kingbasees
哈__1 天前
Oracle至KingbaseES数据库迁移全攻略:痛点拆解、配置实操与问题排查
数据库·oracle
shandianchengzi1 天前
【记录】Tailscale|部署 Tailscale 到 linux 主机或 Docker 上
linux·运维·docker·tailscale
JZC_xiaozhong1 天前
电商ERP如何同步订单数据到MySQL?集成方案解析
数据库·mysql·数据分析·etl工程师·嵌入式实时数据库·电商erp集成·数据集成与应用集成
消失的旧时光-19431 天前
第四篇(实战): 订单表索引设计实战:从慢 SQL 到毫秒级
java·数据库·sql
知识分享小能手1 天前
Oracle 19c入门学习教程,从入门到精通, Oracle 表空间与数据文件管理详解(9)
数据库·学习·oracle
John Song1 天前
Linux机器怎么查看进程内存占用情况
linux·运维·chrome
zhengfei6111 天前
Chroma DB — 未经授权的信息披露
数据库
KaiwuDB1 天前
KaiwuDB 获评“2025 中国大数据产业年度国产化优秀代表厂商”
数据库
肉肉心很软1 天前
使用onlyoffice实现文件预览编辑 + Docker一键部署流程
运维·docker·容器