Ansible role for installing Mysql 5.7 master-slave with gtid and automatic failover
This Ansible role should
- add Oracle repo into servers
- protect hosts with UWF firewall
- install Mysql 5.7 packages
- configure mysql master-slave replication (replica seed is possible)
- install Haproxy as mysql frontend
- install Orchestrator for automatic failover and simply mysql replication management
Note: resolving hostnames important for orchestrator - add mysqldump into root cron on all mysql servers that will take full backup from mysql slave daily
Tested with ubuntu 16.04, debian 8 and ansible 2.3 (and vagrant 1.9)
Important
For avoiding split brains I recommend minimum setup of master + 2 slaves
But this role would work even with master + 1 slave, master initially marked as backup in haproxy exactly for this type of setup
Another Important
By default all servers contain read-only=1 in my.cnf, master would be changed in runtime after setup.
So you'll get read only master after any restart except orchestrator auto failover
Minimum variables that you should know and set:
mysql.yml
- name: Mysql Setup
hosts: mysql
become: true
vars:
replication_user:
name: replicator
host: '%'
password: '_strong_password_'
root_user:
name: root
host: '%'
password: '_strong_password_'
***
- name: Orchestrator Setup
hosts: orchestrator
become: true
vars:
mysql_root_user:
name: root
password: '_strong_password_'
group_vars/all.yml
mysql_port: 3306
frontend_mysql_master_port: 3310
frontend_mysql_slave_port: 3311
How to test:
- start vagrant vms
vagrant up
- run ansible playbook
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --ask-pass -i hosts mysql.yml