MySQL Primary-Replica Deployment Quick Start

Example: MySQL 8.4.9, one primary and two replicas. MySQL 8.4.x works on the CentOS/RHEL 7 family; MySQL 9.7.x requires an operating system that supports glibc2.28.

Use a fresh environment whenever possible.

master_slave.yml performs Linux initialization by default, including dependency installation, SELinux changes, stopping firewalld, and managed sysctl updates. Avoid using an existing business host for the first validation run.

1. Prepare dbbot and Ansible

dbbot_version="$(basename "$(curl -fsSLI -o /dev/null -w '%{url_effective}' https://github.com/fanderchan/dbbot/releases/latest)")"
curl -fL -O "https://github.com/fanderchan/dbbot/releases/download/${dbbot_version}/dbbot-${dbbot_version}.tar.gz"
tar -zxvf "dbbot-${dbbot_version}.tar.gz" -C /usr/local/

/usr/local/dbbot/bin/dbbotctl env setup
source ~/.bashrc
ansible --version

2. Prepare MySQL installation package (optional)

cd /usr/local/dbbot/mysql_ansible/downloads
mysql_version="8.4.9"
curl -fL -O "https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${mysql_version}-linux-glibc2.17-x86_64-minimal.tar.xz"

If the server is connected to the Internet and automatic downloading is enabled, manual uploading is not required.

If you store the offline package in a custom directory, also update mysql_packages_dir in playbooks/common_config.yml.

3. Configure host and parameters

inventory/hosts.ini

[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>'"

The IPs above use RFC 5737 documentation ranges and are examples only. Replace them with your actual host addresses.

playbooks/common_config.yml

mysql_version: "8.4.9"
mysql_port: 3306
fcs_allow_dbbot_default_passwd: true

Description:

  • dbbot’s public default passwords follow Dbbot_<user>@8888 / Dbbot_<linux_user>@9999.
  • If you still use the public default passwords, keep fcs_allow_dbbot_default_passwd: true in the snippet above. The default is false, so the playbook will fail in pre_tasks otherwise.
  • The experimental environment can be temporarily set to true, and the production environment should be changed to your own password.
  • MySQL 9.7.x uses glibc2.28 packages and is not supported on the CentOS/RHEL 7 family; use MySQL 8.4.x on those systems.

playbooks/vars/var_master_slave.yml

master_ip: 192.0.2.131
slave_ips:
  - 192.0.2.132
  - 192.0.2.133
sub_nets: 192.0.2.%

3.1 Dependency chain

ItemDetails
Prerequisitesdbbotctl env setup is complete, [dbbot_mysql] is ready in inventory/hosts.ini, and the MySQL package is either uploaded or allowed to auto-download
Required variablesmaster_ip, slave_ips, mysql_version, and mysql_port; if you keep the public defaults, explicitly set fcs_allow_dbbot_default_passwd: true
Next stepIf you need monitoring, continue with node_exporter_install.yml and mysqld_exporter_install.yml, then register node_exporter and mysqld_exporter with dbbotctl exporter register

4. Pre-execution check

cd /usr/local/dbbot/mysql_ansible/playbooks
ansible dbbot_mysql -m ping

5. Execute deployment

cd /usr/local/dbbot/mysql_ansible/playbooks
ansible-playbook master_slave.yml

During execution, enter confirm as prompted to continue.

For non-interactive execution in scripts or CI, append -e dbbot_confirmation_input=confirm explicitly. Writing confirm to stdin alone does not replace this variable.

In scripts, CI jobs, or SSH one-liners, also prefer the explicit portable Ansible path:

python3 /usr/local/dbbot/portable-ansible/ansible-playbook master_slave.yml -e dbbot_confirmation_input=confirm

Note:

  • master_slave.yml, like unsafe_uninstall.yml, reads the current effective values from playbooks/common_config.yml and advanced_config.yml.
  • If you later change mysql_port to point at another instance, switch it back before uninstalling the original instance, or pass -e mysql_port=<target_port> explicitly.
  • unsafe_uninstall.yml removes the instance data, log, and runtime directories, but keeps the software base directory, Linux user, and instance my.cnf so the removed instance configuration remains auditable.

6. Deployment completion validation

master_slave.yml runs post-deploy acceptance checks automatically in post_tasks by default. These checks cover the MySQL service, listening port, SQL login, primary binlog status, replica threads, replication source address, and replication lag.

  • If post-deploy validation fails, the playbook fails and PLAY RECAP shows failed.
  • To temporarily skip automatic validation, pass -e fcs_run_post_deploy_checks=false explicitly.
  • The command below is only for manual follow-up diagnostics, not the primary acceptance step:
mysql -uadmin -h127.0.0.1 -P3306 -pDbbot_admin@8888 -e "select @@version"