Creating a HA MySQL Cluster with MariaDB Galera - blake-anderson/SEC-440 GitHub Wiki
This will be an installation guide for Ubuntu
Configure static IP's for all nodes in the cluster, set host name and then perform an apt update
Installing MariaDB
apt install mariadb-server
nano /etc/mysql/conf.d/galera.cnf (You will be creating this file, it does not already exist!)
See the configuration in this Github repository. https://github.com/blake-anderson/SEC-440/blob/master/galera.cnf%20-%20Week%203
IMPORTANT NOTE ON CONFIG FILE
On the master node, you must leave the wsrep_cluster_address=gcomm:// line EMPTY (Paste exactly as is here)
Configure it normally on the rest of the boxes, with all three IP's (include that machine's IP, too)
If you fail to do this, the master node will not be able to start MySQL, and MariaDB will fail to launch!
Modifying MariaDB
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Check the bind-addressline, and make sure it is
bind-address = 0.0.0.0
If it is set to localhost, or 127.0.0.0, change it to 0.0.0.0, so MySQL will listen on all interfaces instead of locally only.
Initialize the cluster
Now, on the master node (the machine you left the config line empty on) run the command
galera_new_cluster
This will initialize the cluster, and running the command cat /var/lib/mysql/grastate.dat should show a unique UUID. It should not be 0's. If it is, restart Mariadb, then run the new_cluster command again.
NOTE- In the output of that cat, you should not see safe_to_bootstrap: 0. If this is the case, it is probably breaking the cluster init. Change the line in that file from safe_to_bootstrap: 0 to safe_to_bootstrap: 1
On the other two machines, turn on Mariadb (or restart if it's already running)
systemctl restart mariadb
Now, when you run the command
echo "SHOW STATUS LIKE 'wsrep_cluster_size';" | mysql
The output should print wsrep_cluster_size 3, meaning all three nodes are syncing and connected to the cluster!
Configuring Keepalived for true HA
Like the HAProxy instances, these nodes must be anchored to a single IP that can be given to WordPress.
Install keepalived
apt get install keepalived
This also runs off of a very specific config file, much like HAProxy
nano /etc/keepalived/keepalived.conf
The config file is in the code repository in this github page. Copy / paste it with the correct IP’s https://github.com/blake-anderson/SEC-440/blob/master/keepalived.config%20-%20Week%202
Note on the configuration- The only line that needs to be changed is the priority line, which MUST have different values for each node (Higher = Master).
systemctl restart keepalived
To figure out master status,
systemctl status keepalived will list out the most recent events.
Keep note of the Virtual IP, this will need to be supplied to wordpress (or whatever webapp) later.