下面來給各位同學(xué)介紹一個(gè)MHA實(shí)現(xiàn)mysql主從切換之主故障,手動(dòng)指定Master到從節(jié)點(diǎn),希望例子能幫助各位解決問題.
本文主要模擬實(shí)現(xiàn)主Master故障后,手動(dòng)指定Master到從節(jié)點(diǎn).
- #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實(shí)現(xiàn)mysql主從切換之主故障–手動(dòng)指定Master到從節(jié)點(diǎn)的照片:
- ----- 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.
此時(shí)從庫已經(jīng)變成主庫,到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>
原主庫恢復(fù)以后,添加它為Slave到Master/Slave集群里面,具體操作如下:
1、10.1.1.234(新主庫)執(zhí)行如下,可參考:
centos5.6下mysql5.6主從環(huán)境安裝配置,http://www.diyoms.com/website/1318.html
grant replication slave on *.* to 'jpsync'@'10.1.1.231' identified by 'jppasswd';
flush privileges;
同時(shí)修改/etc/my.cnf添加如下:
skip_slave_start
注意:防止重啟數(shù)據(jù)庫,啟動(dòng)slave進(jìn)程,導(dǎo)致數(shù)據(jù)不一致.
并刪除master.info和relay-log.info.
2、10.1.1.231(新從庫)上執(zhí)行:
- 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;
這個(gè)時(shí)候再執(zhí)行show slave statusG;后出現(xiàn)如下結(jié)果說明主從復(fù)制已經(jīng)恢復(fù).
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
新聞熱點(diǎn)
疑難解答
圖片精選