MySQL MHA 故障转移-VIP

MHA故障转移-VIP

#手工在主库添加VIP
ifconfig ens33:1 192.168.80.200/24

配置VIP脚本

vim /usr/local/bin/master_ip_failoverchmod +x /usr/local/bin/#!/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.80.200/24';                                                          #指定vip的地址,自己指定
my $brdc = '192.168.80.255';                                                            #指定vip的广播地址
my $ifdev = 'ens33';                                                                            #指定vip绑定的网卡
my $key = '1';                                                                                          #指定vip绑定的虚拟网卡序列号
my $ssh_start_vip = "/sbin/ifconfig $ifdev:$key $vip";          #代表此变量值为ifconfig ens33:1 192.168.80.200
my $ssh_stop_vip = "/sbin/ifconfig $ifdev:$key down";           #代表此变量值为ifconfig ens33:1 192.168.80.200 down
my $exit_code = 0;                                                                                      #指定退出状态码为0
#my $ssh_start_vip = "/usr/sbin/ip addr add $vip/24 brd $brdc dev $ifdev label $ifdev:$key;/usr/sbin/arping -q -A -c 1 -I $ifdev $vip;iptables -F;";
#my $ssh_stop_vip = "/usr/sbin/ip addr del $vip/24 dev $ifdev label $ifdev:$key";
##################################################################################
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 \"`;
}
## 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";
}

修改manager配置文件

[server default]
manager_log=/data/mha/mysql3306/manager.log
manager_workdir=/data/mha/mysql3306/manager
master_binlog_dir=/data/mha/mysql3306/
user=mha
password=mha
ping_interval=2
repl_password=123456
repl_user=repl
ssh_user=root
master_ip_failover_script=/usr/local/bin/master_ip_failover[server1]
hostname=192.168.80.22
port=3306[server2]
hostname=192.168.80.11
candidate_master=1
port=3306[server3]
hostname=192.168.80.33
port=3306

重启MHA

sh start_mha.shmasterha_check_status --conf=/data/mha/mha_3306.cnf

灾备演练

#kill 主节点mysql进程[root@master ~]# ps -ef|grep mysql
root      52566   1775  0 03:37 pts/0    00:00:00 /bin/sh ./mysqld_safe --defaults-file=/data/mysql3306/etc/my.cnf --user=mysql
mysql     52900  52566  0 03:37 pts/0    00:00:05 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql3306/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql3306/log/mysql.err --pid-file=/data/mysql3306/data/mysql.pid --socket=/data/mysql3306/tmp/mysql.sock --port=3306
root      61368   1775  0 04:03 pts/0    00:00:00 grep --color=auto mysql
[root@master ~]# kill -9 52566 52900

查看MHA 日志

Checking the Status of the script.. OK
Mon Jun 23 04:13:47 2025 - [info]  OK.
Mon Jun 23 04:13:47 2025 - [warning] shutdown_script is not defined.
Mon Jun 23 04:13:47 2025 - [info] Set master ping interval 2 seconds.
Mon Jun 23 04:13:47 2025 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check ma                              ster reachability from two or more routes.
Mon Jun 23 04:13:47 2025 - [info] Starting ping health check on 192.168.80.11(192.168.80.11:3306)..
Mon Jun 23 04:13:47 2025 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
Mon Jun 23 04:14:35 2025 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
Mon Jun 23 04:14:35 2025 - [info] Executing SSH check script: exit 0
Mon Jun 23 04:14:35 2025 - [info] HealthCheck: SSH to 192.168.80.11 is reachable.
Mon Jun 23 04:14:37 2025 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.80.11' (11                              1))
Mon Jun 23 04:14:37 2025 - [warning] Connection failed 2 time(s)..
Mon Jun 23 04:14:39 2025 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.80.11' (11                              1))
Mon Jun 23 04:14:39 2025 - [warning] Connection failed 3 time(s)..
Mon Jun 23 04:14:41 2025 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.80.11' (11                              1))
Mon Jun 23 04:14:41 2025 - [warning] Connection failed 4 time(s)..
Mon Jun 23 04:14:41 2025 - [warning] Master is not reachable from health checker!
Mon Jun 23 04:14:41 2025 - [warning] Master 192.168.80.11(192.168.80.11:3306) is not reachable!
Mon Jun 23 04:14:41 2025 - [warning] SSH is reachable.
Mon Jun 23 04:14:41 2025 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cn                              f and /data/mha/mha_3306.cnf again, and trying to connect to all servers to check server status..
Mon Jun 23 04:14:41 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Jun 23 04:14:41 2025 - [info] Reading application default configuration from /data/mha/mha_3306.cnf..
Mon Jun 23 04:14:41 2025 - [info] Reading server configuration from /data/mha/mha_3306.cnf..
[root@mha mysql3306]# tail -f manager.log
Check MHA Manager logs at mha:/data/mha/mysql3306/manager.log for details.Started automated(non-interactive) failover.
Invalidated master IP address on 192.168.80.11(192.168.80.11:3306)
Selected 192.168.80.22(192.168.80.22:3306) as a new master.
192.168.80.22(192.168.80.22:3306): OK: Applying all logs succeeded.
192.168.80.22(192.168.80.22:3306): OK: Activated master IP address.
192.168.80.33(192.168.80.33:3306): OK: Slave started, replicating from 192.168.80.22(192.168.80.22:3306)
192.168.80.22(192.168.80.22:3306): Resetting slave info succeeded.
Master failover to 192.168.80.22(192.168.80.22:3306) completed successfully.

master 已经切到slave1,并且vip 跳到了salve1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/pingmian/86306.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/86306.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Elasticsearch索引字段的类型

在 Elasticsearch 中,索引字段的类型(即 Mapping 中的字段类型)对搜索和存储性能影响很大。下面是各种常用数据类型的用途及推荐使用场景总结: 1. keyword 类型(精确匹配) 适合数据: 不需要分词…

kubernetes证书续签-使用kubeadm更新证书(下)

#作者:任少近 文章目录 查看kubelet证书查看kubelet当前所使用的证书 更换 node上的kubelet证书生成node1所需要的kubelet.conf文件生成node2所需要的kubelet.conf文件查看csr 更新 ~/.kube/config 文件重启相关组件 查看kubelet证书 以上少了kubelet的证书&#…

AI智能体长期记忆系统架构设计:从认知模型到生产实践

1 长期记忆:AI智能体的认知基石 1.1 人类记忆与AI记忆的类比 #mermaid-svg-VIPKAFe7VgN4UHFA {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-VIPKAFe7VgN4UHFA .error-icon{fill:#552222;}#mermaid-svg-VIPKAFe7V…

快速上手:利用音频大模型与Java提取视频文案

文章目录 1、前言2、需求说明2.1 需求说明2.2 数据准备 3、功能实现3.1 使用视频理解大模型能力3.1.1 三方平台视频在线链接解析3.1.2 三方平台视频内网链接解析3.1.3 三方平台视频转存本地服务 3.2 使用音频识别大模型能力3.2.1 三方平台视频在线链接解析3.2.2 三方平台视频详…

LLM复杂记忆存储-多会话隔离案例实战

导读:在多用户并发的对话系统中,会话隔离问题往往成为开发者面临的技术难题。当数千个用户同时与AI助手交互时,如何确保每个用户的对话历史完全独立,避免数据混淆和隐私泄露? 本文深入剖析了基于RunnableWithMessageHi…

【PX4-AutoPilot教程-TIPS】PX4系统命令行控制台ConsolesShells常用命令(持续更新)

PX4系统命令行控制台 Consoles & Shells 常用命令 查看每个应用程序的堆栈使用情况获取所有可用命令和APP的列表应用程序启动、停止和状态查询查看本地文件系统查看剩余的可用RAM查看工作队列中正在运行的内容以及运行速率查看特定的uORB话题调试uORB话题进行模式切换和故障…

国内优秀wordpress主题推荐

在国内,WordPress 主题市场虽然不如国外那样庞大,但依然有许多优秀且适合中国用户需求的主题。以下是一些经过评估和推荐的国内优秀WordPress主题,涵盖不同类型的网站需求,如博客、企业官网、资源站、社区论坛等。 WP汉主题 WP汉…

第 6 章:进阶话题

第 6 章:进阶话题 过拟合vs欠拟合:模型复杂度和泛化能力的关系 在前面的章节中,我们已经学习了神经网络的基础知识、常见架构和基本训练流程。然而,在实际的深度学习项目中,仅仅掌握这些基础知识是不够的。我们还需要…

4.2_1朴素模式匹配算法

知识总览: 什么是字符串的模式匹配: 主串:想从该串获取结果的串 模式串:想搜索的内容,不一定在主串中能搜到,子串一定能在主串中搜到 字符串模式匹配:在主串找模式串并返回找到的第一个模式串…

华为云Flexus+DeepSeek征文|华为云ModelArts搭建Dify-LLM应用开发平台(AI智能选股大模型)

前言 在当今数字化时代,人工智能(AI)技术在金融领域的应用愈发广泛,其中 AI 智能选股大模型备受关注。为了构建高效且精准的 AI 智能选股大模型,选择合适的开发平台和工具至关重要。华为云 ModelArts 作为一款面向 AI …

C4.5算法深度解析:决策树进化的里程碑

C4.5是机器学习史上最经典的算法之一,由ID3之父Ross Quinlan在1993年提出。作为ID3的革命性升级,它不仅解决了前代的核心缺陷,更开创了连续特征处理和剪枝技术的先河,成为现代决策树的奠基之作。 本文由「大千AI助手」原创发布&am…

leetcode 65

#include <string> #include <vector> #include <unordered_map> using namespace std;class Solution { public:bool isNumber(string s) {// 定义状态转移表vector<unordered_map<char, int>> states {{{ , 0}, {s, 1}, {d, 2}, {., 4}}, // …

微服务(nacos+myibatis)中如何在一个模块调用多数据库源的一种方案

#nacos配置默认数据库 spring.datasource.typecom.alibaba.druid.pool.DruidDataSource spring.datasource.driverNamecom.mysql.jdbc.Driver #默认数据库名 master spring.datasource.dynamic.primarymaster spring.datasource.dynamic.strictfalse spring.datasource.d…

高标准通信国际接轨,Ethercat与PROFINET网关实现全自动化生产线

在呼和浩特&#xff0c;集成商以其先进的食品饮料行业解决方案&#xff0c;为乳制品行业打造了一个智能化工厂的典范。这个工厂的核心是PROFINET全集成自动化&#xff08;TIA&#xff09;&#xff0c;它通过SIMATIC S7-1200 PLC和ethercat系统&#xff0c;构建了一个强大的PROF…

Netty 引用计数抽象类 AbstractReferenceCountedByteBuf 详解

核心类图 ----------------------------- ---------------------------------- | ReferenceCountUpdater | | AbstractReferenceCountedByteBuf | | <T extends ReferenceCounted>| | (extends AbstractByteBuf) | ----------…

用Python做一个手机镜头

文章目录 设置光学参数添加光学器件 设置光学参数 官方文档&#xff1a;设计手机镜头 rayoptics中提供了OpticalModel类&#xff0c;可用于创建光学模型对象。OpticalModel类中的【optical_spec】成员&#xff0c;是一个OpticalSpecs对象&#xff0c;可用于指定光圈、视野、光…

16.1 Python应用容器化终极指南:Dockerfile多阶段构建与安全优化实战

Python应用容器化终极指南:Dockerfile多阶段构建与安全优化实战 #mermaid-svg-6Yor3ONhmPaQAcY6 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-6Yor3ONhmPaQAcY6 .error-icon{fill:#552222;}#mermaid-svg-6Yor3ON…

基于SpringBoot + Vue打造的画师约稿平台实现

概述 基于SpringBoot Vue打造的画师约稿平台&#xff0c;该平台设计精美、功能完善&#xff0c;无论是想要搭建类似平台的开发者&#xff0c;还是对画师约稿系统感兴趣的人士&#xff0c;都能从中获取有价值的信息。 主要内容 ​​用户端功能​​&#xff1a; 如图所示&…

杰理-耳机-可视化sdk-最大音量提示音-7016G

杰理-耳机-可视化sdk-最大音量提示音 1.音量最大的时候发出消息 2.通过 MSG_FROM_AUDIO 进行发送 3.创建地方接收&#xff0c;并且播放提示音 学习q群:187115320

抖音图文带货权限怎么开通

在这个数字化营销蓬勃发展的时代&#xff0c;抖音作为一个流量巨大的平台&#xff0c;为广大创作者和商家提供了丰富的变现途径。其中&#xff0c;图文带货权限就是一个有效的拓宽变现能力的一个渠道。 那么&#xff0c;如何才能开通抖音的图文带货功能呢&#xff1f; 开通抖…