MHA日常笔记
1、启动mha:
[root@pxc2 ~]# masterha_manager --conf=/opt/mha/conf/mha.cnf
Mon Jun 29 00:29:03 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Jun 29 00:29:03 2020 - [info] Reading application default configuration from /opt/mha/conf/mha.cnf..
Mon Jun 29 00:29:03 2020 - [info] Reading server configuration from /opt/mha/conf/mha.cnf..
2、查看ssh登陆是否成功:
[root@pxc2 ~]# masterha_check_ssh --conf=/opt/mha/conf/mha.cnf
Mon Jun 29 00:33:47 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Jun 29 00:33:47 2020 - [info] Reading application default configuration from /opt/mha/conf/mha.cnf..
Mon Jun 29 00:33:47 2020 - [info] Reading server configuration from /opt/mha/conf/mha.cnf..
Mon Jun 29 00:33:47 2020 - [info] Starting SSH connection tests..
Mon Jun 29 00:33:48 2020 - [debug]
Mon Jun 29 00:33:47 2020 - [debug] Connecting via SSH from root@pxc1(192.168.56.121:22) to root@pxc2(192.168.56.130:22)..
Mon Jun 29 00:33:48 2020 - [debug] ok.
Mon Jun 29 00:33:48 2020 - [debug] Connecting via SSH from root@pxc1(192.168.56.121:22) to root@pxc3(192.168.56.122:22)..
Mon Jun 29 00:33:48 2020 - [debug] ok.
Mon Jun 29 00:33:48 2020 - [debug]
Mon Jun 29 00:33:48 2020 - [debug] Connecting via SSH from root@pxc2(192.168.56.130:22) to root@pxc1(192.168.56.121:22)..
Mon Jun 29 00:33:48 2020 - [debug] ok.
Mon Jun 29 00:33:48 2020 - [debug] Connecting via SSH from root@pxc2(192.168.56.130:22) to root@pxc3(192.168.56.122:22)..
Mon Jun 29 00:33:48 2020 - [debug] ok.
Mon Jun 29 00:33:49 2020 - [debug]
Mon Jun 29 00:33:48 2020 - [debug] Connecting via SSH from root@pxc3(192.168.56.122:22) to root@pxc1(192.168.56.121:22)..
Mon Jun 29 00:33:49 2020 - [debug] ok.
Mon Jun 29 00:33:49 2020 - [debug] Connecting via SSH from root@pxc3(192.168.56.122:22) to root@pxc2(192.168.56.130:22)..
Mon Jun 29 00:33:49 2020 - [debug] ok.
Mon Jun 29 00:33:49 2020 - [info] All SSH connection tests passed successfully.
3、查看复制是否建立好:
[root@pxc2 ~]# masterha_check_repl --conf=/opt/mha/conf/mha.cnf
Mon Jun 29 00:35:30 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Jun 29 00:35:30 2020 - [info] Reading application default configuration from /opt/mha/conf/mha.cnf..
Mon Jun 29 00:35:30 2020 - [info] Reading server configuration from /opt/mha/conf/mha.cnf..
Mon Jun 29 00:35:30 2020 - [info] MHA::MasterMonitor version 0.56.
Mon Jun 29 00:35:31 2020 - [info] GTID failover mode = 1
Mon Jun 29 00:35:31 2020 - [info] Dead Servers:
Mon Jun 29 00:35:31 2020 - [info] Alive Servers:
Mon Jun 29 00:35:31 2020 - [info] pxc1(192.168.56.121:13306)
Mon Jun 29 00:35:31 2020 - [info] pxc2(192.168.56.130:13306)
Mon Jun 29 00:35:31 2020 - [info] pxc3(192.168.56.122:13306)
Mon Jun 29 00:35:31 2020 - [info] Alive Slaves:
Mon Jun 29 00:35:31 2020 - [info] pxc1(192.168.56.121:13306) Version=5.7.22-log (oldest major version between slaves) log-bin:enabled
Mon Jun 29 00:35:31 2020 - [info] GTID ON
Mon Jun 29 00:35:31 2020 - [info] Replicating from 192.168.56.130(192.168.56.130:13306)
Mon Jun 29 00:35:31 2020 - [info] pxc3(192.168.56.122:13306) Version=5.7.25-log (oldest major version between slaves) log-bin:enabled
Mon Jun 29 00:35:31 2020 - [info] GTID ON
Mon Jun 29 00:35:31 2020 - [info] Replicating from 192.168.56.130(192.168.56.130:13306)
Mon Jun 29 00:35:31 2020 - [info] Current Alive Master: pxc2(192.168.56.130:13306)
Mon Jun 29 00:35:31 2020 - [info] Checking slave configurations..
Mon Jun 29 00:35:31 2020 - [info] read_only=1 is not set on slave pxc1(192.168.56.121:13306).
Mon Jun 29 00:35:31 2020 - [info] Checking replication filtering settings..
Mon Jun 29 00:35:31 2020 - [info] binlog_do_db= , binlog_ignore_db=
Mon Jun 29 00:35:31 2020 - [info] Replication filtering check ok.
Mon Jun 29 00:35:31 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Jun 29 00:35:31 2020 - [info] Checking SSH publickey authentication settings on the current master..
Mon Jun 29 00:35:31 2020 - [info] HealthCheck: SSH to pxc2 is reachable.
Mon Jun 29 00:35:31 2020 - [info]
pxc2(192.168.56.130:13306) (current master)
+--pxc1(192.168.56.121:13306)
+--pxc3(192.168.56.122:13306)
Mon Jun 29 00:35:31 2020 - [info] Checking replication health on pxc1..
Mon Jun 29 00:35:31 2020 - [info] ok.
Mon Jun 29 00:35:31 2020 - [info] Checking replication health on pxc3..
Mon Jun 29 00:35:31 2020 - [info] ok.
Mon Jun 29 00:35:31 2020 - [info] Checking master_ip_failover_script status:
Mon Jun 29 00:35:31 2020 - [info] /root/master_ip_failover --command=status --ssh_user=root --orig_master_host=pxc2 --orig_master_ip=192.168.56.130 --orig_master_port=13306
IN SCRIPT TEST====/sbin/ifconfig eth0:0 down==/sbin/ifconfig eth0:0 192.168.56.100/24===
Checking the Status of the script.. OK
Mon Jun 29 00:35:31 2020 - [info] OK.
Mon Jun 29 00:35:31 2020 - [warning] shutdown_script is not defined.
Mon Jun 29 00:35:31 2020 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
4、查看mha状态:
[root@pxc2 ~]# masterha_check_status --conf=/opt/mha/conf/mha.cnf
mha (pid:7129) is running(0:PING_OK), master:pxc2
5、停止mha:
[root@pxc2 ~]# masterha_stop --conf=/opt/mha/conf/mha.cnf
Stopped mha successfully.
[root@pxc2 ~]# masterha_check_status --conf=/opt/mha/conf/mha.cnf
mha is stopped(2:NOT_RUNNING).
6、手动在线切换方法:
1)关闭MHA监控
masterha_stop --conf=/opt/mha/conf/mha.cnf
2)switch
masterha_master_switch --conf=/opt/mha/conf/mha.cnf --master_state=alive --new_master_host=pxc3 --new_master_port=13306 --orig_master_is_new_slave --running_updates_limit=10000
--orig_master_is_new_slave切换时加上此参数是将原master变为slave节点,如果不加此参数,原来的master将不启动。
--running_updates_limit=10000 切换时候选master如果有延迟的话,mha切换不能成功,加上此参数表示延迟在此时间范围内都可切换(单位为s),但是切换的时间长短是由recover时relay日志的大小决定。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端