Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to commonly used scripts in MHA

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

master_ip_failover

In common HA environments, it is often the case that a virtual IP is assigned to the master. If the master goes down,HA software acts like a Pacemaker to transfer the virtual IP to the standby master.

Another common approach is to create a global directory database containing all apps and writer/reader ip addresses. For example {app_master1,192.168.0.1},{app_master2,192.168.0.2}..., Instead of using virtual IP, in this case you need to update the directory database when the master goes down.

There are pros and cons to both methods. MHA does not enforce which one to use, but provides the master_ip_failover_script parameter to do so. In other words, you need to write a script to adjust the connection of the application service to the new master, and then define the master_ip_failover_script parameter. Here is an example:

master_ip_failover_script= /usr/local/sample/bin/master_ip_failover

You can find a simple script at (MHA Manager package)/samples/scripts/master_ip_failover. This script is included in the manager tarball and GitHUb branch.

The MHA manager calls master_ip_failover_script three times, the first time before starting master monitor (to check if the script is available), the second time before calling shutdown_script, and the third time after new master has applied all the difference logs. (You don't have to specify these parameters in the configuration file)

power_manager (prevent split brain)

You may need to force the master server to shut down to prevent it from serving again, which is important to avoid splitting the brain. Here is an example:

shutdown_script= /usr/local/sample/bin/power_manager

You can find a simple script at (MHA Manager package)/samples/scripts/power_manager. This script is included in the manager tarball and GitHUb branch.

Before calling the shutdown_script script,MHA manager internally tries to connect to mysql master via ssh. If ssh can connect (meaning OS is alive, but Mysqld is not running), MHA manager passes the following parameters:

--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 host's ssh fails to connect, MHA uses the following parameters:

--command=stop (this will turn off power via fence devices)

--host=(master's hostname)

--ip=(master's ip address)

The script's general function is as follows. If--command=stopssh is called, the script will kill all mysqld_safe services on the target server using killall-9. If--pid_file is set, the script attempts to kill the specified process. If the script is successful, the script exits back to state 10. If the exit state is 10, the MHA manager then connects to master via ssh to get the binary log it needs. If the script fails to connect to the server via ssh, it passes the--command=stop parameter, which attempts to power down the machine. Power down depends on H/W.HP(ILO),DELL(SOR). If power off succeeds, the script will return to state 0, otherwise it will return to state 1. When the return state is 0, the MHA manager starts failover. If the return state is not 0 or 10, the MHA manager will terminate unexpectedly. This parameter is empty by default, so MHA manager does not invoke any scripts.

In addition,MHA manager calls shutdown_script before starting monitoring. The following parameters are passed. The goal is to check whether scripts are available, and if errors are found, you can know ahead of time.

--command=status

--host=(master's hostname)

--ip=(master's ip address)

send_report

You want to send a report (e.g. email) when a failover occurs. Report_script does this. MHA manager passes the following parameters.

--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)

By default this parameter is empty, so MHA manager does not invoke any scripts.

You can find a simple script at (MHA Manager package)/samples/scripts/send_report. This script is included in the manager tarball and GitHUb branch.

master_ip_online_change

These are a few simple versions of the master_ip_failover_script parameter, but the master failover command does not call it. The master online change command calls it. (masterha_master_switch --master_state=alive), passing the following parameters:

Current master write freezing phase

--command=stop or stopssh

--orig_master_host=(current master's hostname)

--orig_master_ip=(current master's ip address)

--orig_master_port=(current master's port number)

--orig_master_user=(current master's user)

--orig_master_password=(current master's password)

--orig_master_ssh_user=(from 0.56, current master's ssh user)

--orig_master_is_new_slave=(from 0.56, notifying whether the orig master will be new slave or not)

New master granting write phase

--command=start

--orig_master_host=(orig master's hostname)

--orig_master_ip=(orig master's ip address)

--orig_master_port=(orig master's port number)

--new_master_host=(new master's hostname)

--new_master_ip=(new master's ip address)

--new_master_port(new master's port number)

--new_master_user=(new master's user)

--new_master_password=(new master's password)

--new_master_ssh_user=(from 0.56, new master's ssh user)

MHA executes FLUASH TABLES WITH READ LOCK after the current master write freezing phase, and you can perform operations like master_ip_failover_script during the new master granting write phase. For example, create a user with write permissions, execute SET GLOBAL read_only=0, update the directory database, etc. If your script exits with a status other than 1 or 10, MHA manager will terminate unexpectedly, stopping master switch.

This parameter defaults to null, so MHA manager does not make any calls.

You can find a simple script at (MHA Manager package)/samples/scripts/master_ip_online_change. This script is included in the manager tarball and GitHUb branch.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report