Add Additional MariaDB Galera Hosts/Servers To Database Cluster
One of the great advantages of a MariaDB Galera cluster is the ability to scale up and down with ease. If you need to add further database capacity to your cluster you can provision additional MariaDB Galera servers/hosts within minutes. The more MariaDB Galera servers in your database cluster the better the redundancy. Similarly, if you find you have too many MariaDB Galera servers you can remove them from the cluster. So let’s look at adding an additional MariaDB Galera server/host to our existing MariaDB Galera database cluster.
Provision Server
We’re adding another Ubuntu 22 VPS server to our existing cluster that is servicing our High Availability email servers. In our article on How to install Postfixadmin in Ubuntu Postfix Servers, we configured our database servers in a MariaDB Galera database cluster. We have m1 and m2.relay.gb.net. We’ve provisioned another server called m3.relay.gb.net and now we will connect that to our MariaDB Galera database cluster.
Install MariaDB
As in the other articles. Install MariaDB and run the initial setup program. Specify the options below. It’s much faster to add additional MariaDB Galera hosts to an existing MariaDB Galera cluster.
apt install mariadb-server -y && mysql_secure_installation script
Switch to unix_socket authentication: N
Change the root password: N
Remove anonymous users: Y
Disallow root login remotely: N
Remove test database and access to it: Y
Reload privilege tables now: Y
Next, login to an existing Galera server in your cluster. Open up the Copy the /etc/mysql/mariadb.conf.d/60-galera.cnf file and specify the IP of the server you want to add to the cluster. Your specifying the new IP in the wsrep_cluster_address field.
## Cluster Name
wsrep_cluster_name = "Postfix HA Database Cluster"
## Cluster Node IPs
wsrep_cluster_address = gcomm://151.xx.124.8x,51.xx.170.26x,135.xxx.67.2x
Save the file. Next, Copy the /etc/mysql/mariadb.conf.d/60-galera.cnf file to your new Glaera host. Do not copy the file to any of the other existing hosts. Don’t forget to stop MariaDB on the new host.
systemctl stop mariadb
scp /etc/mysql/mariadb.conf.d/60-galera.cnf root@hostname.server.com:/etc/mysql/mariadb.conf.d/
Now in the new server open up the /etc/mysql/mariadb.conf.d/60-galera.cnf file and modify the server name at the bottom.
## Below settings to identify lines in logs
wsrep_node_name = M3
wsrep_node_address = "51.xx.170.26x"
Save and close the file. Ensure that the new server’s IP is listed in any additional MariaDB Glaera NVMe VPS servers in your cluster. Just add the IP to the /etc/mysql/mariadb.conf.d/60-galera.cnf file on existing hosts in the cluster.
Configure Firewall Rules
And finally, ensure the new server can communicate through the firewall on the existing Glaera hosts in the cluster. You also need to whitelist the existing servers in the new Glaera host.
# Replication Rules
ufw allow from 151.80.124.86 proto tcp to any port 3306
ufw allow from 151.80.124.86 proto tcp to any port 4444
ufw allow from 151.80.124.86 proto tcp to any port 4567
ufw allow from 151.80.124.86 proto tcp to any port 4568
You are now ready to start MariaDB on the new additional MariaDB Galera server. When you start MariaDB the additional server will contact the other servers listed in the 60-galera.cnf file and import the existing tables and databases. One by one on the existing hosts in the Galera cluster, restart MariaDB.
systemctl restart mariadb
Finally on the additional MariaDB Galera server now start MariaDB. You should now notice when checking the MariaDB Galera Cluster size that the additional MariaDB Galera host is in the cluster.
mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
You have now expanded your MariaDB Galera Replication Cluster with an additional host.