文档章节

MHA之masterha_master_switch

xxj123gogo
 xxj123gogo
发布于 2017/05/25 16:01
字数 1447
阅读 98
收藏 1
mha

如下是 MHA 的 masterha_master_switch 功能的 官方介绍,大体翻译下,需要时候可以查阅。

masterha_master_switch

masterha_master_switch可以用来做master failover 也可以用来做在线的主库切换。

Manual Failover

有时候需要做手动failover, 可以用如下命令:

$ masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=host1 

可用的参数如下:

  • --master_state=dead

    强制参数. 可选有: "dead" or "alive". 如果设置为 alive,将执行 在线切主操作。后面介绍。

  • --dead_master_host=(hostname)

    强制参数,--dead_master_ip 和 --dead_master_port 也可以指定。

  • --new_master_host=(hostname)

    可选参数。如果不指定,程序自动选举。

  • --interactive=(0|1)

    1为交互模式,默认;0为非交互。

  • --ssh_reachable=(0|1|2)

    Specifying whether the master is reachable via SSH or not. Set 0 if not reachable, set 1 if reachable, set 2 if unknown. Default is 2. If 2 is set, the command internally checks the master is reachable via SSH or not, and update the internal SSH status with 0 or 1. If the master is reachable via SSH, and if master_ip_failover_script or shutdown_script is set, the command passes "--command=stopssh". If not, masterha_master_switch passes "--command=stop". In addition, if the crashed master is reachable via SSH, the failover script tries to copy unsent binary logs from the crashed master.master是否通过SSH可达。0表示不可达;2表示未知,默认。

  • --skip_change_master

    By setting this argument on master failover, MHA exits after applying differential relay logs, and skipping CHANGE MASTER and START SLAVE. So slaves do not point to a new master. This may help if you want to manually double check whether slave recovery succeeded or not.当切换完毕,不执行CHANGE MASTER TO 操作,这在需要手动确认切换效果的时候可能用到。

  • --skip_disable_read_only

    By passing this parameter, MHA skips executing SET GLOBAL read_only=0 on the new master. This may be useful when you want to manually disable .跳过在新主上 SET GLOBAL read_only=0的操作。以便稍后手动操作。

  • --last_failover_minute=(minutes)

    Same as masterha_manager.

  • --ignore_last_failover

    Same as masterha_manager.

  • --wait_on_failover_error=(seconds)

    Same as masterha_manager.

    Note that this parameter applies to automated/non-interactive failover only, and this does not apply to interactive failover. That is, if --interactive=0 is not set, wait_on_failover_error is simply ignored and does not sleep on errors.

  • --remove_dead_master_conf

    Same as masterha_manager.

    masterha_master_switch runs interactive failover procedures by default. You need to type "yes" from keyboard as below.

    ... Starting master switch from host1(192.168.0.1:3306) to host2(192.168.0.2:3306)? (yes/NO): yes ...

    New master is determined by the same rule as automated failover, if --new_master_host is not set. When you run manual failover, you have an option to set new master explicitly. The below is an example.

    Starting master switch from host1(192.168.0.1:3306) to host2(192.168.0.2:3306)? (yes/NO): no Continue? (yes/NO): yes Enter new master host name: host5 Master switch to gd1305(10.17.1.238:3306). OK? (yes/NO): yes ...

    In this case, host5 will be new master, as long as binary logging is enabled and major version is not higher than other slaves. The below command has the same effect as the above.

    $ masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=host1 --new_master_host=host5
    
  • --wait_until_gtid_in_sync(0|1)

    This option is available since 0.56.

    When doing GTID based failover, MHA waits until slaves to catch up the new master's GTID if setting wait_until_gtid_in_sync=1. If setting 0, MHA doesn't wait slaves to catch up. Default is 1.   适用于GTID模式,设置为1表示MHA将等待所有slave追上新master的GTID,默认;0表示不等。

  • --skip_change_master

    This option is available since 0.56.

    If this option is set, MHA skips executing CHANGE MASTER.   MHA将跳过CHANGE MASTER操作。

  • --skip_disable_read_only

    This option is available since 0.56.

    If this option is set, MHA skips executing SET GLOBAL read_only=0 on the new master.

  • --ignore_binlog_server_error

    This option is available since 0.56.

    If this option is set, MHA ignores any error from binlog servers during failover.

 开始举例子

  •  确认老主已死,并明确指定新主

 masterha_master_switch --conf=/etc/app1.cnf --master_state=dead --dead_master_host=host1 --new_master_host=host2

  •   确认老主已死,系统系统自动选新主

  masterha_master_switch --conf=/etc/app1.cnf --master_state=dead --dead_master_host=host1

 

Scheduled(Online) Master Switch

有时候我们希望有计划的切主,甚至老主正在运行着。典型的情景就是更换硬件,升级服务器等这些需要停机的操作,这时候就可以在线切主。

如下:

$ masterha_master_switch --master_state=alive --conf=/etc/app1.cnf --new_master_host=host2

--master_state=alive must be set. Program flows for the scheduled master switch is slightly different from the master failover. For example, you do not need to power off the master server, but you need to make sure that write queries are not executed on the master. By settingmaster_ip_online_change_script, you can control how to disallow write traffics on the current master (i.e. dropping writable users, setting read_only=1, etc) before executing FLUSH TABLES WITH READ LOCK, and how to allow write traffics on the new master.  --master_state=alive必须要设置。

Online master switch starts only when all of the following conditions are met.

  • IO threads on all slaves are running
  • SQL threads on all slaves are running
  • Seconds_Behind_Master on all slaves are less or equal than --running_updates_limit seconds
  • On master, none of update queries take more than --running_updates_limit seconds in the show processlist output

The reasons of these restrictions are for safety reasons, and to switch to the new master as quickly as possible. masterha_master_switch takes below arguments when switching master online.

  • --new_master_host=(hostname)

    New master's hostname. 新主的hostname

  • --orig_master_is_new_slave

    After master switch completes, the previous master will run as a slave of the new master. By default, it's disabled (the previous master will not join new replication environments). If you use this option, you need to set repl_password parameter in the config file because current master does not know the replication password for the new master. 将老主切换成新主的slave节点。如果不指定这个参数,老主将不加入新的集群环境。

  • --running_updates_limit=(seconds)

    If the current master executes write queries that take more than this parameter, or any of the MySQL slaves behind master more than this parameter, master switch aborts. By default, it's 1 (1 second).当老主当前写操作执行超过N秒,或者任何一台slave的 slaves behind master 超过N秒,切换都将终止。

  • --remove_orig_master_conf

    When this option is set, if master switch succeeds correctly, MHA Manager automatically removes the section of the dead master from the configuration file. By default, the configuration file is not modified at all.

  • --skip_lock_all_tables

    When doing master switch, MHA runs FLUSH TABLES WITH READ LOCK on a orig master to make sure updates are really stopped. But FLUSH TABLES WITH READ LOCK is very expensive and if you can make sure that no updates are coming to the orig master (by killing all clients at master_ip_online_change_script etc), you may want to avoid to lock tables by using this argument,切换过程中,老主将被施加 FLUSH TABLES WITH READ LOCK ,这是个昂贵的操作,如果你可以确定没有写操作,可以指定这个参数。

又要举例子了

  • 将master从host1切换到host2,切换完成,将host1作为新环境的slave继续运行

masterha_master_switch --conf=/etc/app1.cnf --master_state=alive  --new_master_host=host2 --orig_master_is_new_slave --running_updates_limit=5

  • 将master从host1切换到host2,切换完成,host1不再参与新环境的复制

masterha_master_switch --conf=/etc/app1.cnf --master_state=alive  --new_master_host=host2  --running_updates_limit=5

© 著作权归作者所有

xxj123gogo
粉丝 0
博文 62
码字总数 83973
作品 0
其它
程序员
私信 提问
MySQL高可用架构之MHA

MHA简介: MHA是由日本人yoshinorim(原就职于DeNA现就职于FaceBook)开发的比较成熟的MySQL高可用方案。MHA能够在30秒内实现故障切换,并能在故障切换中,最大可能的保证数据一致性。 该软件...

LUksl
2017/11/23
0
0
mha的搭建步骤(一主一从架构)

mha的搭建步骤(一主一从架构) http://www.cnblogs.com/xiaoboluo768/p/5135584.html 环境: centos 6.8 x64 192.168.0.32 # master 192.168.0.33 #管理节点和从节点slave VIP:192.168.0.106......

lxm111111
2017/01/21
0
0
MHA Quick Start Guide

MHA QuickStart Guide, MySQL 6 Comments MHA (Master High Availability Manager and tools for MySQL) is one of the most important pieces of our managed services. When properly set ......

rootliu
07/02
15
0
MySQL高可用架构之MHA (未完,待续)

MySQL高可用架构之MHA 简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作...

jinyan2049
2015/03/18
0
0
【MySQL】【高可用】从masterha_master_switch工具简单分析MHA的切换逻辑

简介:masterhamasterswitch作为一个切换工具被集成在MHA程序包中, 安装:编译安装MHA manager后会在/usr/local/bin/中生成二进制可执行程序masterhamasterswitch。 使用: 本文转自 angry_...

科技小能手
2017/11/12
0
0

没有更多内容

加载失败,请刷新页面

加载更多

数据库表与表之间的一对一、一对多、多对多关系

表1 foreign key 表2 多对一:表 1 的多条记录对应表 2 的一条记录 利用foreign key的原理我们可以制作两张表的多对多,一对一关系 多对多: 表1的多条记录可以对应表2的一条记录 表2的多条记...

Garphy
36分钟前
6
0
MySQL 表崩溃修复

MySQL日志报错 2019-10-19 13:41:51 19916 [ERROR] /usr/local/mysql/bin/mysqld: Table './initread_hss/user_info' is marked as crashed and should be repaired2019-10-19 13:41:51 1......

雁南飞丶
45分钟前
5
0
Error和Exception

1.Error类和Exception类都是继承Throwable类 2.Error(错误)是系统中的错误,程序员是不能改变的和处理的,是在程序编译时出现的错误,只能通过修改程序才能修正。一般是指与虚拟机相关的问...

大瑞清_liurq
今天
4
0
8086汇编基础 start 程序入口标签的示例

    IDE : Masm for Windows 集成实验环境 2015     OS : Windows 10 x64 typesetting : Markdown    blog : my.oschina.net/zhichengjiu    gitee : gitee.com/zhichengjiu   ......

志成就
今天
4
0
uni app 零基础小白到项目实战2

<template> <scroll-view v-for="(card, index) in list" :key="index"> <view v-for =(item, itemIndex) in card"> {{item.value}}</view> </scroll-view></template> GraceUi va......

达达前端小酒馆
今天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部