Home HOWTO - setup mariadb cluster
Post
Cancel

HOWTO - setup mariadb cluster

I just did it, you did it also once and you will do it in the future or if you are on this page because you want to do it right know, its a honor for me to help you with. Setup a mariadb (galera) cluster is very easily.

Requirements

First of all, you should install the MariaDB repository. You’ll find the right repo for you linux-distro on the webpage of MariaDB. Cause I like to use a rhel-based linux, I’ll use a CentOS in this tutorial. So if you use CentOS as well, you can use the following repo-code-snippet. With “vi /etc/yum.repos.d/mariadb” you’ll create a new Repo-Configfile. Here is the MariaDB 10.3 Repository-Config

1
2
3
4
5
6
7
# MariaDB 10.3 CentOS repository list - created 2019-05-30 18:12 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

After that, you can install the packets.

Install pakets

You have to install the following packets:

1
yum install MariaDB-server galera MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common

Configuration

To use a cluster, you need at least two nodes, but I think you already installed two Server for this cluster ;) . Before configuring the two nodes, we stop the daemons with “systemctl stop mariadb”. Oh yes, we also can activate the daemon for starting with the OS after rebooting the system :) with “systemctl enable mariadb”. Now we can configure the node with the following snippets in this configfile “/etc/my.cnf.d/server.cnf”. You have to set at least the following parameters.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[mysqld]
datadir=/srv/database/
#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_name="db-cluster-01"
wsrep_cluster_address="gcomm://IP-NODE-01,IP-NODE-02"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
innodb_flush_log_at_trx_commit=0
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="IP-NODE-01"
wsrep_node_name="NODE-NAME"
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

With this configuration the cluster is ready to use. Of course, you have to use this configuration on both nodes.

Initialize the Cluster

First of all, we have to initialize the cluster for the first use. To do that, we have to use mysqld --wsrep-new-cluster or. galera_new_cluster. This will setup the cluster. Please do not use this, to start the cluster or a node. You can start the second node with systemctl start mariadb.

Restarting the Cluster

If you have to restart a clusternode, it is important to do that separatly. If you don’t do that, you can lose some data or risk an inkonsistent db. If both nodes are “dying” at the same time, you have to start the cluster with galera_recovery. In some cases the restart will fail, then you have to analyze which node is the primary node. You can determine this with the file grastate.dat in the mysql-dir. The node with the higher seqno in the grastate.dat ist the node you should start first. If the vale is -1, you have to start both server with wsrep_recover. MariaDB will now recover the seqno and you should be able to determine which server you should start first.

Documentation for MultipathD

The multipathd supports the devicemapper with the configuration of the harddrives which are mounted with more than one path.

Important Files

The configuration file for the multipathd is the following: - /etc/multipath.conf This file holds the configuratipn… – Blacklisting – Exceptions – Assignment – and so on… This files would be generated by the multipathd:

  • /etc/multipath/bindings

    Controls the assignment

  • /etc/multipath/wwids

    Includes the wwids

Tools

The tool to build and change the configurationsfiles is mpathconf. With it you can modify the /etc/multipath.conf. You also could modify the /etc/multipath.conf manually. Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
defaults {
         udev_dir               /dev
         no_path_retry          1
         polling_interval       10
         path_checker           tur
         path_grouping_policy   group_by_prio
         user_friendly_names    yes
         selector               "round-robin 0"
         max_fds                "4128"
}
blacklist {
        devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
        devnode "^hd[a-z]"
        devnode "^dcssblk[0-9]*"
        wwid "*"
}
blacklist_exceptions {
        wwid "3600d0230000000000e13955cc3757802"
        wwid "3600d0230000000000e13955cc3757801"
        wwid "3600d0230000000000e13955cc3757800"
        wwid "3600d0230000000000e13955cc3757803"
        wwid "3600d0230000000000e13955cc3757804"
}
multipaths {
        multipath {
                uid 54321
                gid 0
                wwid "3600d0230000000000e13955cc3757800"
                mode 0660
                alias AliasA
        }
        multipath {
                uid 54321
                gid 0
                wwid "3600d0230000000000e13955cc3757801"
                mode 0660
                alias AliasB
        }
        multipath {
                uid 54321
                gid 0
                wwid "3600d0230000000000e13955cc3757802"
                mode 0660
                alias AliasC
        }
        multipath {
                uid 54321
                gid 0
                wwid "3600d0230000000000e13955cc3757803"
                mode 0660
                alias AliasD
        }
        multipath {
                uid 54321
                gid 0
                wwid "3600d0230000000000e13955cc3757804"
                mode 0660
                alias AliasE
        }
}

I think this file is selfexplained :)

Determine WWIDs

To get the WWIDs you can use the command scsi_id -g -u /dev/sdb. You will get the WWID for the device sdb. With this little for-loop for device in /dev/sd*; do echo "Device: ${device} $(scsi_id -g -u ${device})"; done you will get all WWIDs for the devices. The output should look like that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
> Device: /dev/sdb 3600d0230000000000e13955cc3757800
> Device: /dev/sdc 3600d0230000000000e13955cc3757801
> Device: /dev/sdd 3600d0230000000000e13955cc3757802
> Device: /dev/sde 3600d0230000000000e13955cc3757803
> Device: /dev/sdf 3600d0230000000000e13955cc3757804
> Device: /dev/sdg 3600d0230000000000e13955cc3757800
> Device: /dev/sdh 3600d0230000000000e13955cc3757801
> Device: /dev/sdi 3600d0230000000000e13955cc3757802
> Device: /dev/sdj 3600d0230000000000e13955cc3757803
> Device: /dev/sdk 3600d0230000000000e13955cc3757804
> Device: /dev/sdl 3600d0230000000000e13955cc3757800
> Device: /dev/sdm 3600d0230000000000e13955cc3757801
> Device: /dev/sdn 3600d0230000000000e13955cc3757802
> Device: /dev/sdo 3600d0230000000000e13955cc3757803
> Device: /dev/sdp 3600d0230000000000e13955cc3757804
> Device: /dev/sdq 3600d0230000000000e13955cc3757800
> Device: /dev/sdr 3600d0230000000000e13955cc3757801
> Device: /dev/sds 3600d0230000000000e13955cc3757802
> Device: /dev/sdt 3600d0230000000000e13955cc3757803
> Device: /dev/sdu 3600d0230000000000e13955cc3757804

You have to put this WWIDs into the multipath.conf. You also can use other criterias to set the exceptions, the vendor for example.

Autoconfig with multipathd

When everything in the configurationsfile is done correctly , the multipathd needs to be restartet service multipathd restart and the devicemapper should do his magic. You should check if the multipathd is in the autostart. chkconfig multipathd --list when not chkconfig multipathd on.

This post is licensed under CC BY 4.0 by the author.

iperf – a great bandwidth measure tool

SSH / Clientconfig – Unknown wrongfully