通过MHA做Mysql主从切换

MHA常用命令

检查ssh

masterha_check_ssh --conf=/data/mha/testdb/conf/testdb.cnf

检查replfuzhi de qingk (还可以用作健康检查)

masterha_check_repl --conf=/data/mha/testdb/conf/testdb.cnf

检查主库位置

masterha_check_status --conf=/data/mha/testdb/conf/testdb.cnf

这一切正常的情况下,就可以做数据库切换

切换前

在线切换前,需要把event_scheduler关闭

在主库执行 set global event_scheduler=0;

切换

停止MHA监控

首先在mha节点上,找到对应数据库的监控

ps -ef | grep /data/mha/testdb/conf/testdb.cnf

kill 对应的监控进程。

执行切换

masterha_master_switch --master_state=alive --conf=/data/mha/testdb/conf/testdb.cnf new_master_host=192.168.0.1 --new_master_port=3306 --orig_master_is_new_slave

切换后

检查vip

切换后vip应该漂移到新的主库(原从库)

参数修改

主库

read_only=off

在命令行里,set global read_only=0

在my.cnf,修改read_only值为0

relay_log_purge=on

在命令行里,set global relay_log_purge=1

event_scheduler=on

在命令行里,set global event_scheduler=1

在my.cnf,修改event_scheduler值为1

从库

read_only=on

在命令行里,set global read_only=1

在my.cnf,修改read_only值为1

relay_log_purge=on

在命令行里,set global relay_log_purge=1

event_scheduler=off

在命令行里,set global event_scheduler=0

在my.cnf,修改event_scheduler值为0

 

 同步状态检查

在从库show slave status\G

检查

Slave_IO_Running:Yes

Slave_SQL_Running:Yes

Seconds_behind_Master: 0

则表示同步正常。

 

posted on 2020-03-22 17:27  jerry1111  阅读(423)  评论(0编辑  收藏  举报

导航