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.
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.
vi /etc/yum.repos.d/mariadb" you'll create a new Repo-Configfile. Here is the MariaDB 10.3 Repository-Config
# 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.
You have to install the following packets:
yum install MariaDB-server galera MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common
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.
[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.