Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Last active September 5, 2025 04:50
Show Gist options
  • Select an option

  • Save jniltinho/b41927078b91773fabc22216d34f7040 to your computer and use it in GitHub Desktop.

Select an option

Save jniltinho/b41927078b91773fabc22216d34f7040 to your computer and use it in GitHub Desktop.
Install MariaDB Galera Cluster
#!/bin/bash
## https://www.howtoforge.com/how-to-setup-mariadb-galera-cluster-on-ubuntu-20-04/
## https://www.linkedin.com/pulse/setting-up-mariadb-galera-multi-node-cluster-ubuntu-2204-sahu-azrjc
## https://computingforgeeks.com/how-to-setup-mariadb-galera-cluster-on-ubuntu-with-haproxy/
## https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/
## https://mariadb.com/kb/en/mariabackup-sst-method/
## https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/
## https://mariadb.org/download/?t=repo-config&d=22.04+%22jammy%22&v=10.6&r_m=rackspace
apt update
apt install apt-transport-https curl
curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
cat <<EOF > /etc/apt/sources.list.d/mariadb.list
# MariaDB 10.6 repository list
deb [signed-by=/etc/apt/keyrings/mariadb-keyring.pgp] https://mirror.rackspace.com/mariadb/repo/10.6/ubuntu $(lsb_release -cs) main
EOF
apt update
apt install -y mariadb-server-10.6 mariadb-backup
ln -s /etc/apparmor.d/usr.sbin.mariadbd /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/usr.sbin.mariadbd
aa-status
mysql_secure_installation
# Enter current password for root (enter for none):
# Switch to unix_socket authentication [Y/n] n
# Change the root password? [Y/n] Y
# New password:
# Re-enter new password:
# Remove anonymous users? [Y/n] Y
# Disallow root login remotely? [Y/n] Y
# Remove test database and access to it? [Y/n] Y
# Reload privilege tables now? [Y/n] Y
## On the first node, create a galera.cnf file using the following command:
cat <<EOF > /etc/mysql/conf.d/galera.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://node1-ip-address,node2-ip-address,node3-ip-address"
# Galera Synchronization Configuration
#wsrep_sst_method=mariabackup
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="node1-ip-address"
wsrep_node_name="node1"
EOF
## On the second node, create a galera.cnf file using the following command:
cat <<EOF > /etc/mysql/conf.d/galera.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://node1-ip-address,node2-ip-address,node3-ip-address"
# Galera Synchronization Configuration
#wsrep_sst_method=mariabackup
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="node2-ip-address"
wsrep_node_name="node2"
EOF
## On the third node, create a galera.cnf file using the following command:
cat <<EOF > /etc/mysql/conf.d/galera.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://node1-ip-address,node2-ip-address,node3-ip-address"
# Galera Synchronization Configuration
#wsrep_sst_method=mariabackup
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="node3-ip-address"
wsrep_node_name="node3"
EOF
## You will need to stop the MariaDB service on all nodes. You can run the following command to stop the MariaDB service:
systemctl stop mariadb
# On the first node, initialize the MariaDB Galera cluster with the following command:
galera_new_cluster
mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
## On the second node, start the MariaDB service with the following command:
systemctl start mariadb
mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
## On the third node, start the MariaDB service with the following command:
systemctl start mariadb
mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment