下面来给各位同学介绍一个MHA实现mysql主从切换之主故障,手动指定Master到从节点,希望例子能帮助各位解决问题.
本文主要模拟实现主Master故障后,手动指定Master到从节点.
- #masterha_master_switch --master_state=dead --conf=/etc/masterha/app1.cnf --dead_master_host=10.1.1.231 --dead_master_ip=10.1.1.231 --dead_master_port=63306 --new_master_host=10.1.1.234 --new_master_ip=10.1.1.234 --new_master_port=63306
只显示如下日志,部分信息在附件,利用MHA实现mysql主从切换之主故障–手动指定Master到从节点的照片:
- ----- Failover Report -----
- app1: MySQL Master failover 10.1.1.231 to 10.1.1.234 succeeded
- Master 10.1.1.231 is down!
- Check MHA Manager logs at compute-0-52.local for details.
- Started manual(interactive) failover.
- The latest slave 10.1.1.234(10.1.1.234:63306) has all relay logs for recovery.
- Selected 10.1.1.234 as a new master.
- 10.1.1.234: OK: Applying all logs succeeded.
- Generating relay diff files from the latest slave succeeded.
- 10.1.1.234: Resetting slave info succeeded.
- --Vevb.com
- Master failover to 10.1.1.234(10.1.1.234:63306) completed successfully.
此时从库已经变成主库,到10.1.1.234上查看如下信息:
- mysql> show master status;
- +------------------------+----------+--------------+--------------------------------------+-------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
- +------------------------+----------+--------------+--------------------------------------+-------------------+
- | mysql-slave-bin.000011 | 120 | denovo_ng | mysql,denovo,test,information_schema | |
- +------------------------+----------+--------------+--------------------------------------+-------------------+
- 1 row in set (0.00 sec)
- mysql>
原主库恢复以后,添加它为Slave到Master/Slave集群里面,具体操作如下:
1、10.1.1.234(新主库)执行如下,可参考:
centos5.6下mysql5.6主从环境安装配置,http://www.diyoms.com/website/1318.html
grant replication slave on *.* to 'jpsync'@'10.1.1.231' identified by 'jppasswd';
flush privileges;
同时修改/etc/my.cnf添加如下:
skip_slave_start
注意:防止重启数据库,启动slave进程,导致数据不一致.
并删除master.info和relay-log.info.
2、10.1.1.231(新从库)上执行:
- change master to master_host='10.1.1.234',master_port=63306,master_user='jpsync',
- master_password='jppasswd', master_log_file='mysql-master-bin.000011',master_log_pos=120;
这个时候再执行show slave statusG;后出现如下结果说明主从复制已经恢复.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
新闻热点
疑难解答