萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> MHA實現mysql主從切換之主故障

MHA實現mysql主從切換之主故障

下面來給各位同學介紹一個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.

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

 

copyright © 萬盛學電腦網 all rights reserved