Puppet Class: galera

Defined in:
modules/galera/manifests/init.pp

Overview

Set up a galera node with mariadb.

$cluster_nodes: list of fqdns of each node in this cluster

$server_id: unique integer identifier of this node

For initial setup, start with mariadb disabled everywhere. Then on one node run

galera_new_cluster

Then start mariadb on each node one at a time, checking status with

mysql -u root -p -e "show status like 'wsrep_cluster_size'"

After that, change puppet config to enable on all nodes.

Parameters:

  • cluster_nodes (Array[Stdlib::Fqdn])
  • server_id (Integer)
  • enabled (Boolean)
  • port (Stdlib::Port) (defaults to: 3306)
  • socket (Stdlib::Unixpath) (defaults to: '/var/run/mysqld/mysqld.sock')
  • basedir (Stdlib::Unixpath) (defaults to: '/usr')
  • datadir (Stdlib::Unixpath) (defaults to: '/var/lib/mysql')
  • tmpdir (Stdlib::Unixpath) (defaults to: '/tmp')


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'modules/galera/manifests/init.pp', line 18

class galera(
    Array[Stdlib::Fqdn] $cluster_nodes,
    Integer             $server_id,
    Boolean             $enabled,
    Stdlib::Port        $port            = 3306,
    Stdlib::Unixpath    $socket          = '/var/run/mysqld/mysqld.sock',
    Stdlib::Unixpath    $basedir         = '/usr',
    Stdlib::Unixpath    $datadir         = '/var/lib/mysql',
    Stdlib::Unixpath    $tmpdir          = '/tmp',
    ) {

    # This will install the latest mariadb + required
    #  galera components.
    package { 'mariadb-server':
        ensure => 'present',
    }

    $service_ensure = $enabled ? {
        true => present,
        default => absent,
    }
    # Override the packaged service so we can increase TimeoutStartSec
    systemd::service { 'mariadb':
        ensure   => $service_ensure,
        content  => systemd_template('mariadb'),
        override => true,
        require  =>  [
            Package['mariadb-server'],
        ],
    }

    # The debian package installs this for backwards compatibility with sysV;
    #  it's confusing to have two different ways to start and stop the service
    #  so let's just remove it.
    file { '/etc/init.d/mysql':
        ensure  => absent,
    }

    $cluster_node_ips = $cluster_nodes.map |$host| { ipresolve($host, 4) }

    file { '/etc/mysql/mariadb.conf.d/50-server.cnf':
        owner   => 'root',
        group   => 'root',
        mode    => '0644',
        content => template('galera/server.cnf.erb'),
    }

    file { '/etc/mysql/mariadb.conf.d/50-mysql-clients.cnf':
        owner   => 'root',
        group   => 'root',
        mode    => '0644',
        content => template('galera/client.cnf.erb'),
    }

    file { '/etc/mysql/mariadb.conf.d/50-mysqldump.cnf':
        owner   => 'root',
        group   => 'root',
        mode    => '0644',
        content => template('galera/mysqldump.cnf.erb'),
    }
}