masterha_master_switch
Manual Failover
$ masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=host1
$ masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=host1 --new_master_host=host5
Non-Interactive Failover
$ masterha_master_switch --master_state=dead --conf=/etc/conf/masterha/app1.cnf --dead_master_host=host1 --new_master_host=host2 --interactive=0
Scheduled(Online) Master Switch
$ masterha_master_switch --master_state=alive --conf=/etc/app1.cnf --new_master_host=host2
Monitoring_Multpile
# masterha_manager --conf=/etc/conf/masterha/app1.cnf
# masterha_manager --conf=/etc/conf/masterha/app2.cnf
masterha_manager
# masterha_manager --conf=/etc/conf/masterha/app1.cnf
Runnning_Background
manager_host$ nohup masterha_manager --conf=/etc/app1.cnf < /dev/null > /var/log/masterha/app1/app1.log 2>&1 &
Running MHA Manager from daemontools
1 - Install daemontools
manager_host# yum -y install daemontools
2 - Create run file under /service/masterha_(app_name)/run_
manager_host# mkdir /service/masterha_app1
manager_host# cat /service/masterha_app1/run
#!/bin/sh
exec masterha_manager --conf=/etc/app1.cnf --wait_on_monitor_error=60 --wait_on_failover_error=60 >> /var/log/masterha/app1/app1.log 2>&1
manager_host# chmod 755 /service/masterha_app1/run
##########################################################################################
# stopping monitoring
manager_host# svc -d /service/masterha_app1
# starting monitoring
manager_host# svc -u /service/masterha_app1
masterha_conf_host
# masterha_conf_host --command=add --conf=/etc/conf/masterha/app1.cnf --hostname=db101
# masterha_conf_host --command=add --conf=/etc/conf/masterha/app1.cnf --hostname=db101 --block=server100 --params="no_master=1;ignore_fail=1"
The following lines will be added to the conf file.
# masterha_conf_host --command=delete --conf=/etc/conf/masterha/app1.cnf --block=server100
masterha_check_status
$ masterha_check_status --conf=/path/to/app1.cnf
$ echo $?
masterha_check_repl
manager_host$ masterha_check_repl --conf=/etc/app1.cnf
masterha_stop
manager_host$ masterha_stop --conf=/etc/app1.cnf
masterha_ssh_check
# masterha_check_ssh --conf=/etc/app1.cnf
purge_relay_logs
[app@slave_host1]$ cat /etc/cron.d/purge_relay_logs
# purge relay logs at 5am
0 5 * * * app /usr/bin/purge_relay_logs --user=root --password=PASSWORD --disable_relay_log_purge >> /var/log/masterha/purge_relay_logs.log 2>&1
secondary_check_script
secondary_check_script = masterha_secondary_check -s remote_host1 -s remote_host2
master_ip_failover_script
master_ip_failover_script= /usr/local/sample/bin/master_ip_failover
shutdown_script
shutdown_script= /usr/local/sample/bin/power_manager
Parameters
https://github.com/yoshinorim/mha4mysql-manager/wiki/Parameters#master_ip_failover_script.md
Writing an application configuration file
manager_host$ cat /etc/app1.cnf
[server default]
# mysql user and password
user=root
password=mysqlpass
# working directory on the manager
manager_workdir=/var/log/masterha/app1
# manager log file
manager_log=/var/log/masterha/app1/app1.log
# working directory on MySQL servers
remote_workdir=/var/log/masterha/app1
[server1]
hostname=host1
[server2]
hostname=host2
[server3]
hostname=host3
Writing a global configuration file
[server default]
user=root
password=rootpass
ssh_user=root
master_binlog_dir= /var/lib/mysql
remote_workdir=/data/log/masterha
secondary_check_script= masterha_secondary_check -s remote_host1 -s remote_host2
ping_interval=3
master_ip_failover_script=/script/masterha/master_ip_failover
shutdown_script= /script/masterha/power_manager
report_script= /script/masterha/send_master_failover_mail
app1:
manager_host$ cat /etc/app1.cnf
[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/app1.log
[server1]
hostname=host1
candidate_master=1
[server2]
hostname=host2
candidate_master=1
[server3]
hostname=host3
[server4]
hostname=host4
no_master=1
app2:
manager_host$ cat /etc/app2.cnf
[server default]
manager_workdir=/var/log/masterha/app2
manager_log=/var/log/masterha/app2/app2.log
[server1]
hostname=host11
candidate_master=1
[server2]
hostname=host12
candidate_master=1
[server3]
hostname=host13
[server4]
hostname=host14
no_master=1
Binlog server
manager_host$ cat /etc/app1.cnf
[server default]
# mysql user and password
user=root
password=mysqlpass
# working directory on the manager
manager_workdir=/var/log/masterha/app1
# manager log file
manager_log=/var/log/masterha/app1/app1.log
# working directory on MySQL servers
remote_workdir=/var/log/masterha/app1
[server1]
hostname=host1
[server2]
hostname=host2
[server3]
hostname=host3
[binlog1]
hostname=binlog_host1
[binlog2]
hostname=binlog_host2