MySQL MHA Deployment Guide
This article explains the supported boundaries and basic usage of mha.yml.
1. Support boundaries
- Currently maintained only for
CentOS 7 / Red Hat 7 - Target architecture: one master, multiple replicas + MHA Manager
- Applicable version: MySQL
5.7
mha.yml belongs to the traditional high availability solution. For new clusters, it is recommended to use MGR or InnoDB Cluster.
192.168.161.* is the default dbbot three-node regression subnet, not a legacy MHA-specific environment. To validate mha.yml, prepare a separate CentOS 7 or Red Hat 7 environment and use MySQL 5.7.
2. inventory and roles
mha.yml still uses the [dbbot_mysql] host group, and the actual roles are distinguished by variables:
[dbbot_mysql]
192.0.2.131 ansible_user=root ansible_ssh_pass="'<your_password>'"
192.0.2.132 ansible_user=root ansible_ssh_pass="'<your_password>'"
192.0.2.133 ansible_user=root ansible_ssh_pass="'<your_password>'"
3. Key variables
Edit mysql_ansible/playbooks/common_config.yml:
mysql_version: "5.7.44"
mysql_port: 3306
fcs_allow_dbbot_default_passwd: true
Description:
mha.ymlsupports only MySQL5.7; do not keep the default MySQL9.7.xconfiguration.fcs_allow_dbbot_default_passwd: trueis suitable only for temporary lab environments. If you keep dbbot’s public default passwords, this switch must be enabled explicitly; production environments should use custom passwords and keep this switchfalse.
Edit mysql_ansible/playbooks/vars/var_mha.yml:
master_ip: 192.0.2.131
slave_ips:
- 192.0.2.132
- 192.0.2.133
manager_ip: 192.0.2.133
vip: 192.0.2.130
vip_netmask: "32"
net_work_interface: ens33
mha_secondary_check_script: ""
Description:
manager_ipcannot be the same asmaster_ipmanager_ipshould be placed on the replica nodevip,vip_netmask,net_work_interfaceneed to be consistent with the actual network environmentens33is only an example interface name. Before running a VIP-related playbook, confirm the real interface withip route get <gateway>orip -o -4 addr show. CentOS 7 KVM test environments may also useeth0.mha_secondary_check_scriptis empty by default, which keeps the classic MHA default behavior. For production, configure a topology-specific multi-path check command to reduce false positives from a single manager path.
4. Execution entry
cd /usr/local/dbbot/mysql_ansible/playbooks
ansible-playbook mha.yml
During execution, enter confirm as prompted.
For non-interactive execution, append the confirmation variable explicitly:
python3 /usr/local/dbbot/portable-ansible/ansible-playbook mha.yml -e dbbot_confirmation_input=confirm
If you also override boolean variables on the command line, use JSON extra-vars so key=true is not parsed as a string:
python3 /usr/local/dbbot/portable-ansible/ansible-playbook mha.yml \
-e dbbot_confirmation_input=confirm \
-e '{"fcs_allow_dbbot_default_passwd": true}'
5. Uninstall
mha_unsafe_uninstall.yml stops the classic MHA manager, removes the configured VIP and MHA runtime files, and then removes the MySQL instance data, log, and runtime directories for the current mysql_port:
cd /usr/local/dbbot/mysql_ansible/playbooks
ansible-playbook mha_unsafe_uninstall.yml
During execution, enter confirm as prompted. For non-interactive execution, append -e dbbot_confirmation_input=confirm.
By default, the playbook does not remove the MHA RPM packages. If you need to remove mha4mysql-manager and mha4mysql-node, append -e '{"mha_uninstall_remove_packages": true}'.
6. Things to note
- The current
mha.ymldocument only coversCentOS 7andRed Hat 7prerequisites. - Three-node regression environments that do not meet the
CentOS 7/Red Hat 7and MySQL5.7requirements are expected to be blocked by themha.ymlpreflight checks. - If you use it on other distributions, you need to verify Perl dependencies and MHA RPM compatibility yourself first.
secondary_check_scriptis not configured by default. Production environments should add MHA secondary checks based on their network topology.- If you need to rerun after a failure, it is recommended to confirm the MHA Manager configuration, VIP status, and MySQL instance status before deciding whether to clean up the residual files.