MariaDB clustering with galera

Some notes for myself written down publicly in the hopes that they might help some future person.

It is highly recommended to have the cluster on a vlan/vswitch!
Galera does not implement it’s own security for the cluster ports. See the vlan part at the bottom of this document if you do not have vlans setup yet.

In this example the following IPs are used:
Local machine: 192.168.100.1
Another cluster node: 192.168.100.2

Make sure mariadb is off before starting!

edit /etc/mysql/mariadb.conf.d/60-galera.cnf

[galera]
wsrep_on = ON
wsrep_provider = /usr/lib/galera/libgalera_smm.so
wsrep_cluster_address = "gcomm://192.168.100.1,192.168.100.2"
wsrep_provider_options="gmcast.listen_addr=tcp://192.168.100.1:4567;ist.recv_addr=192.168.100.1:4568"
binlog_format = row
wsrep_cluster_name="galeracluster"
default_storage_engine = InnoDB
wsrep_node_address = 192.168.100.1
innodb_autoinc_lock_mode = 2
wsrep_sst_receive_address=192.168.100.1:4444
bind-address = 192.168.100.1

If this is the first node in the cluster, or all nodes in the cluster are currently down, you have to run
galera_new_cluster to bootstrap the cluster again. Otherwise you can just start the mariadb service through systemd.

Now you’re good to go!
While everything should work now, if you want to read more about galera you can do so here.

Addendum: Vlans

You should keep the cluster on a vlan for security reasons. This can be done in netplan by editing /etc/netplan/(yourconfig).yaml and adding:

  vlans:
    enp0s31f6.4001:
      id: 4001
      link: enp0s31f6
      mtu: 1400
      addresses:
        - 192.168.100.1/24

Here enp0s31f6 is the interface name, 4001 is the vlan id, and 192.168.100.1 is the ip to assign to the local box.

Leave a Reply

Your email address will not be published. Required fields are marked *