1. Add settings for Galera in a MariaDB configuration file:
- Edit the following file such as by using the nano editor: nano /etc/mysql/mariadb.conf.d/50-server.cnf
- Comment out (i.e. put a # before or delete) the following line: #bind-address = 127.0.0.1
- Add the following set of config that you modify to the IP addresses of your current and future containers – paste it somewhere suitable in the document (such as at the end or after another section finishes):
# MariaDB cluster information [galera] wsrep_on = ON wsrep_cluster_name = "MariaDB Galera Cluster" wsrep_provider = /usr/lib/galera/libgalera_smm.so wsrep_cluster_address = "gcomm://192.168.8.31,192.168.8.32,192.168.8.33" binlog_format = row default_storage_engine = InnoDB innodb_autoinc_lock_mode = 2 bind-address = 0.0.0.0 wsrep_node_address="192.168.8.31"
2. Clone the container to create two more
- Switch the container off by running the ‘shutdown now‘ command.
- In Proxmox WebGUI, right click on the container and select ‘clone’.
- Choose a fitting hostname for the cloned CT, such as ‘mariadb-node2’.
- Do the same for the third container and choose a hostname such as ‘mariadb-node3’.
- Before you switch them on, go to each of their Network tab settings and change their IPv4 to make sure they are not identical!
3. Initialize the Galera cluster + restart MariaDB
- After you have switched each of them on, go to their respective configuration file (see step 1 above) to make sure that that the ‘wsrep_node_address=’ parameter points to them rather than the first node.
- To make sure that one node can see each other, run a simple ping test, such as from node 1 to node 2: ping mariadb-node2 and from node1 to node3: ping mariadb-node3
- On node 1 (or actually any one of them), initialize the Galera cluster and then restart the MariaDB service.
galera_new_cluster systemctl restart mariadb
- In case you get errors when restarting the MariaDB service, make sure that the information in /etc/mysql/mariadb.conf.d/50-server.cnf is correct (that the default bind to 127.0.0.1 is commented out and that the information about each node is accurate, esp. the ‘wsrep_node_address=‘ parameter.
- Now you can restart the mariadb service on the two other nodes and you will have a basic cluster up and running!
4. Verify that the Galera cluster is operational
- On any of the nodes, log into the MySQL service, such as by running ‘mysql -u root -p‘ . Enter the root password for the MySQL service.
- Run the following SQL command:
show status like 'wsrep_%';
- Pay attention to the ‘wsrep_cluster_size‘ item – if all three nodes are up, the number should be 3.
5. Create a test DB and confirm it is replicated
- While still logged into the database service as root, run the following command:
create database testdb; show databases;
- Log into another MariaDB node and after logging into the SQL service (mysql -u root -p), run the show databases; command as well. Do you see the database called testdb there, too?