MHA 在线切换过程(一)

2015-07-16 12:09:31 · 作者: · 浏览: 2

MySQL MHA 在线切换是MHA除了自动监控切换换提供的另外一种方式,多用于诸如硬件升级,MySQL数据库迁移等等。该方式提供快速切换和优雅的阻塞写入,无关关闭原有服务器,整个切换过程在0.5-2s 的时间左右,大大减少了停机时间。本文演示了MHA 在线切换并给出了在线切换的基本步骤。


1、MHA在线切换方式及要求
? ? $ masterha_master_switch --master_state=alive --conf=/etc/app1.cnf --new_master_host=host2
?
? ? a、SQL threads on all slaves are running
? ? b、Seconds_Behind_Master on all slaves are less or equal than --running_updates_limit seconds
? ? c、On master, none of update queries take more than --running_updates_limit seconds in the show processlist output
?


2、在线进行切换基本步骤
? ? a、检测MHA配置置及确认当前master
? ? b、决定新的master
? ? c、阻塞写入到当前master
? ? d、等待所有从服务器与现有master完成同步
? ? e、在新master授予写权限,以及并行切换从库
? ? f、重置原master为新master的slave


3、演示在线切换
###获取masterha_master_switch帮助
[root@vdbsrv4 ~]# masterha_master_switch --help
Usage:
? ? # For master failover


? ? masterha_master_switch --master_state=dead
? ? --global_conf=/etc/masterha_default.cnf
? ? --conf=/usr/local/masterha/conf/app1.cnf --dead_master_host=host1


? ? # For online master switch


? ? masterha_master_switch --master_state=alive
? ? --global_conf=/etc/masterha_default.cnf
? ? --conf=/usr/local/masterha/conf/app1.cnf


? ? See online reference
? ? (http://code.google.com/p/mysql-master-ha/wiki/masterha_master_switch)
? ? for details.


###校验当前是否启用masterha_manager
[root@vdbsrv4 ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
app1 is stopped(2:NOT_RUNNING).


###切换前
mysql> show slave hosts;
+-----------+---------+------+-----------+--------------------------------------+
| Server_id | Host? ? | Port | Master_id | Slave_UUID? ? ? ? ? ? ? ? ? ? ? ? ? |
+-----------+---------+------+-----------+--------------------------------------+
|? ? ? 1001 | vdbsrv2 | 3306 |? ? ? ? 1 | 75bef614-e342-11e4-921d-000c295fb2eb |
|? ? ? 1002 | vdbsrv3 | 3306 |? ? ? ? 1 | 091f79b8-e386-11e4-93d5-000c2943c830 |
+-----------+---------+------+-----------+--------------------------------------+


To:
vdbsrv3(192.168.1.8:3306) (new master)
?+--vdbsrv2(192.168.1.7:3306)
?+--vdbsrv1(192.168.1.6:3306)
Tue Apr 21 15:42:13 2015 - [info] Checking whether vdbsrv3(192.168.1.8:3306) is ok for the new master..
Tue Apr 21 15:42:13 2015 - [info]? ok.
Tue Apr 21 15:42:13 2015 - [info] vdbsrv1(192.168.1.6:3306): SHOW SLAVE STATUS returned empty result. To check replication filtering rules,
? temporarily executing CHANGE MASTER to a dummy host.
Tue Apr 21 15:42:13 2015 - [info] vdbsrv1(192.168.1.6:3306): Resetting slave pointing to the dummy host.
Tue Apr 21 15:42:13 2015 - [info] ** Phase 1: Configuration Check Phase completed.
Tue Apr 21 15:42:13 2015 - [info]
Tue Apr 21 15:42:13 2015 - [info] * Phase 2: Rejecting updates Phase..
Tue Apr 21 15:42:13 2015 - [info] ###建议部署master_ip_online_change_script 脚本,该脚本会自动阻塞以及kill原master session,置原master为只读
Tue Apr 21 15:42:13 2015 - [warning] master_ip_online_change_script is not defined. Skipping disabling writes on the current master.#此演示未指定
Tue Apr 21 15:42:13 2015 - [info] Locking all tables on the orig master to reject updates from everybody (including root):
Tue Apr 21 15:42:13 2015 - [info] Executing FLUSH TABLES WITH READ LOCK..
Tue Apr 21 15:42:13 2015 - [info]? ok.
Tue Apr 21 15:42:13 2015 - [info] Orig master binlog:pos is mysql-bin.000023:651371104.
Tue Apr 21 15:42:13 2015 - [info]? Waiting to execute all relay logs on vdbsrv3(192.168.1.8:3306)..
Tue Apr 21 15:42:13 2015 - [info]? master_pos_wait(mysql-bin.000023:651371104) completed on vdbsrv3