您好,欢迎访问一九零五行业门户网

MHA 在线切换过程

mysql mha 在线切换是mha除了自动监控切换换提供的另外一种方式,多用于诸如硬件升级,mysql数据库迁移等等。该方式提供快速切换
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
    ()
    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 |
+-----------+---------+------+-----------+--------------------------------------+
###实施在线切换
[root@vdbsrv4 ~]# masterha_master_switch --conf=/etc/masterha/app1.cnf --master_state=alive --new_master_host=vdbsrv3 \
> --orig_master_is_new_slave --running_updates_limit=10000 --interactive=0
tue apr 21 15:42:13 2015 - [info] mha::masterrotate version 0.56.
tue apr 21 15:42:13 2015 - [info] starting online master switch..
tue apr 21 15:42:13 2015 - [info]
tue apr 21 15:42:13 2015 - [info] * phase 1: configuration check phase..
tue apr 21 15:42:13 2015 - [info]
tue apr 21 15:42:13 2015 - [warning] global configuration file /etc/masterha_default.cnf not found. skipping.
tue apr 21 15:42:13 2015 - [info] reading application default configuration from /etc/masterha/app1.cnf..
tue apr 21 15:42:13 2015 - [info] reading server configuration from /etc/masterha/app1.cnf..
tue apr 21 15:42:13 2015 - [info] gtid failover mode = 0
tue apr 21 15:42:13 2015 - [info] current alive master: vdbsrv1(192.168.1.6:3306)
tue apr 21 15:42:13 2015 - [info] alive slaves:
tue apr 21 15:42:13 2015 - [info]  vdbsrv2(192.168.1.7:3306)  version=5.6.22-log (oldest major version between slaves) log-bin:enabled
tue apr 21 15:42:13 2015 - [info]    replicating from 192.168.1.6(192.168.1.6:3306)
tue apr 21 15:42:13 2015 - [info]  vdbsrv3(192.168.1.8:3306)  version=5.6.22-log (oldest major version between slaves) log-bin:enabled
tue apr 21 15:42:13 2015 - [info]    replicating from 192.168.1.6(192.168.1.6:3306)
tue apr 21 15:42:13 2015 - [info] executing flush no_write_to_binlog tables. this may take long time..
tue apr 21 15:42:13 2015 - [info]  ok.
tue apr 21 15:42:13 2015 - [info] checking mha is not monitoring or doing failover..
tue apr 21 15:42:13 2015 - [info] checking replication health on vdbsrv2..  ###author : leshami
tue apr 21 15:42:13 2015 - [info]  ok.                                                            ###blog    :
tue apr 21 15:42:13 2015 - [info] checking replication health on vdbsrv3..
tue apr 21 15:42:13 2015 - [info]  ok.
tue apr 21 15:42:13 2015 - [info] vdbsrv3 can be new master.
tue apr 21 15:42:13 2015 - [info]
from:
vdbsrv1(192.168.1.6:3306) (current master)
 +--vdbsrv2(192.168.1.7:3306)
 +--vdbsrv3(192.168.1.8:3306)
其它类似信息

推荐信息