/mariadb-galera-ansible

Ansible scripts to install and configure the Highly available MariaDB Galera cluster

Primary LanguageJinja

Deploy the Galera Cluster.

A Multi-Master Cluster of MariaDB based on synchronous replication.

Description

Galera Cluster is a synchronous multi-master replication plug-in for InnoDB. It is very different from the regular MySQL Replication, and addresses a number of issues including write conflicts when writing on multiple masters, replication lag and slaves being out of sync with the master. Users do not have to know which server they can write to (the master) and which servers they can read from (the slaves).

Getting Started

ansible-playbook -i inventories/galera/test-db/hosts galera.yml -e 'first_time=true'

Variables

Variable Default Description
ip - private IP of the VM
dns_domain - specify the hostname of the node VM
mariadb_version - specify the version of MariaDB to be installed.
galera_cluster_name 10.5 specify wsrep_cluster_name.
first_time false is the custom environment variable defined to determine if its first run to setup the cluster.
mysql_root_password - specify mariadb root password.
innodb_buffer_pool_size 512M set innodb_buffer_pool_size for MariaDB.
mariadb_repo_url default_link It is repository_url, a URL to the directory where the repodata directory of a MariaDB repository is located.

Tested Versions

Troubleshooting

Recover a MariaDB Galera Cluster Node due to Database Corruption

  • First make sure other nodes are running well and follow these instructions.
  • Navigate to mysql folder using cd /var/lib/mysql/
  • Create a new directory using mkdir /fioldername
  • Copy the whole folder mysql using rsync -avz . /foldername/
  • Remove all the files in mysql folder using rm -rf *
  • Again copy the mysql DB from backup folder to mysql folder using cp -rpf /foldername/mysql .
  • Add innodb_force_recovery=1 in /etc/my.cnf.d/server.cnf file
  • Add TimeoutSec variable in /etc/systemd/system/mysql.service file
  • The above TimeoutSec variable value should be mentioned in secs TimeoutSec=900
  • Now start the service systemctl start mariadb
  • You can check the status of cluster using systemctl status mariadb
  • Once the cluster is up just comment innodb_force_recovery=1 in server.cnf file
  • Then again restart the cluster using systemctl restart mariadb