MySQL Primary-Replica Deployment Quick Start
Example: MySQL 8.4.8, one primary and two replicas.
1. Prepare dbbot and Ansible
dbbot_version="$(basename "$(curl -fsSLI -o /dev/null -w '%{url_effective}' https://github.com/fanderchan/dbbot/releases/latest)")"
wget "https://github.com/fanderchan/dbbot/releases/download/${dbbot_version}/dbbot-${dbbot_version}.tar.gz"
tar -zxvf "dbbot-${dbbot_version}.tar.gz" -C /usr/local/
cd /usr/local/dbbot/portable-ansible-v0.5.0-py3
sh setup_portable_ansible.sh
source ~/.bashrc
ansible --version
2. Prepare MySQL installation package (optional)
cd /usr/local/dbbot/mysql_ansible/downloads
mysql_version="8.4.8"
wget "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_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.8"
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.
playbooks/vars/var_master_slave.yml:
master_ip: 192.0.2.131
slave_ips:
- 192.0.2.132
- 192.0.2.133
sub_nets: 1%
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.
6. Deployment completion validation
- Check
PLAY RECAPfor nofailed/unreachable. - Perform a version check on the target machine:
mysql -uadmin -h127.0.0.1 -P3306 -pDbbot_admin@8888 -e "select @@version"