MHA官方文档翻译(十)

2015-02-03 03:55:14 · 作者: · 浏览: 76
(OS存活但是mysqld服务终止),MHA manager传递如下参数

--command=stopssh --ssh_user=(ssh username so that you can connect to the master) --host=(master's hostname) --ip=(master's ip address) --port=(master's port number) --pid_file=(master's pid file)

If the master is not reachable via SSH, MHA Manager passes thefollowing arguments.

--command=stop --host=(master's hostname) --ip=(master's ip address)

该脚本以如下方式运行。如果--command=stopssh被通过,则该脚本会通过ssh在mysqld和mysqld_safe进程上执行kill -9操作。如果—pid_file同样被通过,该脚本就会尝试只杀死代理的进程,而不是所有的mysql进程,这在单个master上运行多实例时是非常有用的。如果成功地通过SSH停止了该服务,则脚本运行结果返回10,并且后续manager会通过SSH连接到master并保存必要的binlog。如果该脚本无法通过SSH连接到master或者—command命令通过的话,那么该脚本将会尝试关闭机器电源。关闭电源依赖于H/W。如果电源关闭成功,该脚本返回0,否则返回1。当MHA接到返回的0时即开始故障切换。如果返回的代码既不是0也不是10,MHA将会终止故障转移工作。缺省参数为空,所以默认情况下MHA不对其做任何事。

并且,MHA在开始监控之后就会调用该脚本,以下参数将会在这个时候被传递过去,你可以在这里检测脚本设置。是否控制电源很多程度上决定于H/W,所以非常简易在这里检测电源状态。如果你哪里配置错了,在启动监控的时候你需要特别小心。

--command=status --host=(master's hostname) --ip=(master's ip address)

report_script

当故障切换完成或返回错误的时候,你或许希望可以发送一个报告给你,report_script参数可适用于这种场合。MHA manager将会传递如下参数

--orig_master_host=(dead master's hostname) --new_master_host=(new master's hostname) --new_slave_hosts=(new slaves' hostnames, delimited by commas) --subject=(mail subject) --body=(body)

默认情况下该参数为空,即MHA不对其做任何事。在MHAmanager包的

Default parameter is empty, so MHA Manager does not invokeanything by default. /samples/scripts/send_report目录下有使用范例。

init_conf_load_script

这个脚本能被应用于你不想在配置文件中填写清楚的文本信息,比如密码和复制账户的密码。通过从这个脚本中返回name=value对,你可以重写这个全局配置文件。范例如下

  #!/usr/bin/perl
  
  print "password=$ROOT_PASS\n";
  print "repl_password=$REPL_PASS\n";

缺省参数为空,所以MHA不对其做任何事。

?

Command reference

这一部分不做翻译,通常情况下只需要运行范例的命令,参数的详细介绍请见官方文档。

?

masterha_manager: 开启MHA Manager

  # masterha_manager --conf=/etc/conf/masterha/app1.cnf

masterha_master_switch:切换master,分故障master切换和在线master切换两种

交互式故障master切换

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

指定新的master

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

非交互式

$ masterha_master_switch --master_state=dead --conf=/etc/conf/masterha/app1.cnf --dead_master_host=host1 --new_master_host=host2 --interactive=0

?

在线master切换

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

masterha_check_status:检查MHA运行状态

$ masterha_check_status --conf=/path/to/app1.cnf
  app1 (pid:8368) is running(0:PING_OK), master:host1
  $ echo $?
  0

Status Code(Exit code)

Status String

Description

0

PING_OK

Master is running and MHA Manager is monitoring. Master state is alive.

1

---

Unexpected error happened. For example, config file does not exist. If this error happens, check arguments are valid or not.

2

NOT_RUNNING

MHA Manager is not running. Master state is unknown.

3

PARTIALLY_RUNNING

MHA Manager main process is not running, but child processes are running. This should not happen and should be investigated. Master state is unknown.

10

INITIALIZING_MONITOR

MHA Manager is just after startup and initializing. Wait for a while and see how the status changes. Master state is unknown.

20

PING_FAILING

MHA Manager detects ping to master is failing. Master state is maybe down.

21

PING