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.ymlperforms Linux initialization by default, including dependency installation, SELinux changes, stoppingfirewalld, and managedsysctlupdates. 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
bin/dbbotctl support packages --stack mysql --version 8.4.9 --os <OS> --full
If the server is connected to the Internet and automatic downloading is enabled, manual uploading is not required.
In offline environments, use the command above to query the package name and download URL for your operating system, then upload the primary package to
mysql_ansible/downloads. Replace<OS>with your OS type, such asCentOS7,RHEL9, orAlmaLinux9.If you store the offline package in a custom directory, also update
mysql_packages_dirinplaybooks/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: truein the snippet above. The default isfalse, so the playbook will fail inpre_tasksotherwise. - The experimental environment can be temporarily set to
true, and the production environment should be changed to your own password. - MySQL
9.7.xusesglibc2.28packages and is not supported on the CentOS/RHEL 7 family; use MySQL8.4.xon 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
| Item | Details |
|---|---|
| Prerequisites | dbbotctl 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 variables | master_ip, slave_ips, mysql_version, and mysql_port; if you keep the public defaults, explicitly set fcs_allow_dbbot_default_passwd: true |
| Next step | If 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, likeunsafe_uninstall.yml, reads the current effective values fromplaybooks/common_config.ymlandadvanced_config.yml.- If you later change
mysql_versionormysql_portto point at another instance, switch them back before uninstalling the original instance, or pass-e mysql_version=5.7.44 -e mysql_port=3307explicitly. unsafe_uninstall.ymlremoves the instance data, log, and runtime directories, but keeps the software base directory, Linux user, and instancemy.cnfso 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 RECAPshowsfailed. - To temporarily skip automatic validation, pass
-e fcs_run_post_deploy_checks=falseexplicitly. - 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"