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.

Revisions

  1. jniltinho revised this gist Sep 5, 2025. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,15 @@


    apt update
    apt install -y curl
    curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup|bash -s -- --mariadb-server-version="mariadb-10.6"
    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/
  2. jniltinho revised this gist Sep 5, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@
    ## 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
  3. jniltinho revised this gist Sep 5, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,7 @@ 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
    @@ -71,6 +72,7 @@ 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
    @@ -95,6 +97,7 @@ 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
  4. jniltinho revised this gist Feb 3, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,10 @@ curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup|bash -s -- --mariad

    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):
  5. jniltinho revised this gist Feb 2, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    ## 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/

  6. jniltinho revised this gist Feb 2, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    ## 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/mariabackup-sst-method/
    ## https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/


  7. jniltinho revised this gist Feb 2, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ apt update
    apt install -y curl
    curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup|bash -s -- --mariadb-server-version="mariadb-10.6"

    apt install -y mariadb-server-10.6
    apt install -y mariadb-server-10.6 mariadb-backup

    mysql_secure_installation

  8. jniltinho created this gist Feb 2, 2025.
    113 changes: 113 additions & 0 deletions mariadb-galera-cluster.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,113 @@
    #!/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/


    apt update
    apt install -y curl
    curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup|bash -s -- --mariadb-server-version="mariadb-10.6"

    apt install -y mariadb-server-10.6

    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=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=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=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'"