{"id":7859,"date":"2023-07-04T04:23:40","date_gmt":"2023-07-04T04:23:40","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=7859"},"modified":"2023-07-04T04:23:41","modified_gmt":"2023-07-04T04:23:41","slug":"mariadb-galera-cluster-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/mariadb-galera-cluster-on-centos-7\/","title":{"rendered":"How to Configure MariaDB Galera Cluster on CentOS 7?"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 2,157<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p>A multi-master cluster for MariaDB, Galera uses synchronous replication to replicate data. Using Galera, each node in the cluster may be a master and write to any other node simultaneously. Galera\u2019s active design lacks failover, enhances load balancing, and fault tolerance.<\/p>\n\n\n\n<p>This tutorial will examine how to set up a Galera cluster with three nodes running CentOS 7 and MariaDB. To provide complete redundancy, at least three nodes are required. If two nodes were utilized to construct a Galera cluster, and one node went down ungracefully, the other node would fail to function.<\/p>\n\n\n\n<p><strong>We have Two Nodes (server) :<\/strong><\/p>\n\n\n\n<p>192.168.1.11<\/p>\n\n\n\n<p>192.168.1.12<\/p>\n\n\n\n<p><strong>Step 1:<\/strong><\/p>\n\n\n\n<p>On both servers, need to configure the MariaDB server.<\/p>\n\n\n\n<p>First, we will add Mariadb Respository to each node and create a repo file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim \/etc\/yum.repos.d\/MariaDB10.1.repo\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"566\" height=\"52\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img1.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7862\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img1.jpg 566w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img1-300x28.jpg 300w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/figure>\n\n\n\n<p>Add the following repository information to each nodes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># MariaDB 10.1 CentOS repository\n\n# https:\/\/downloads.mariadb.org\/mariadb\/repositories\/\n\n[mariadb] name = MariaDB\n\nbaseurl = https:\/\/yum.mariadb.org\/10.1\/centos7-amd64 gpgkey=https:\/\/yum.mariadb.org\/RPM-GPG-KEY-MariaDB gpgcheck=1<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"629\" height=\"165\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img2.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7863\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img2.jpg 629w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img2-300x79.jpg 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/figure>\n\n\n\n<p>Now install the MariaDB package on all Nodes using the below command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum install MariaDB-server MariaDB-client MariaDB-common -y<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"926\" height=\"177\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img3.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7864\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img3.jpg 926w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img3-300x57.jpg 300w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img3-768x147.jpg 768w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">Restart the mariadb on each node by using the command:\n\nsystemctl restart mariadb<\/pre>\n\n\n\n<p><strong>Step 2:<\/strong><\/p>\n\n\n\n<p>After packages are installed, we are going to secure MariaDB using the following command on each node. Do not Forget to allow remote login:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql_secure_installation<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"711\" height=\"39\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img4.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7865\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img4.jpg 711w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img4-300x16.jpg 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"572\" height=\"586\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img5.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7866\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img5.jpg 572w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img5-293x300.jpg 293w\" sizes=\"(max-width: 572px) 100vw, 572px\" \/><\/figure>\n\n\n\n<p>Galera can use Rsync to perform the replication between cluster nodes. So we need to install both Rsync using the below command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum install rsync -y<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Database has been configured. Now, let\u2019s move forward to Configure MariaDB<\/strong> <strong>Galera Cluster<\/strong><\/h2>\n\n\n\n<p><strong>Step&nbsp;<\/strong><strong>3<\/strong><strong>:<\/strong><\/p>\n\n\n\n<p>Galera Master Node Configuration:<\/p>\n\n\n\n<p>Lets configure one node ( 192.168.1.11 ) with Galera before joining additional nodes. We need to add the following configuration to MariaDB configuration file in \/etc\/my.cnf.d\/server.cnf under [galera] section:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 wsrep_on=ON\n\nwsrep_provider=\/usr\/lib64\/galera\/libgalera_smm.so wsrep_cluster_address=\"gcomm:\/\/192.168.1.11,192.168.1.12\"\n\n# Galera Cluster Configuration wsrep_cluster_name=\"galeracluster1\"\n\n# Galera Synchronization Configuration wsrep_sst_method=rsync\n\n# Galera Node Configuration wsrep_node_address=\"192.168.1.11\" wsrep_node_name=\"galera1\"<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"454\" height=\"395\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img6.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7867\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img6.jpg 454w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img6-300x261.jpg 300w\" sizes=\"(max-width: 454px) 100vw, 454px\" \/><\/figure>\n\n\n\n<p>The same content needs to be copied to another node (192.168.1.12) to be joined to the cluster except the node_address and node_name<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 wsrep_on=ON\n\nwsrep_provider=\/usr\/lib64\/galera\/libgalera_smm.so wsrep_cluster_address=\"gcomm:\/\/192.168.1.11,192.168.1.12\"\n\n# Galera Cluster Configuration wsrep_cluster_name=\"galeracluster1\"\n\n# Galera Synchronization Configuration wsrep_sst_method=rsync<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"632\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img7-1024x632.png\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7868\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img7-1024x632.png 1024w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img7-300x185.png 300w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img7-768x474.png 768w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img7.png 1420w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We need to add a log location for MariaDB. Add the following log location under the [mysqld] section on each node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">log_error=\/var\/log\/mariadb.log<\/pre>\n\n\n\n<p>Since the log file does not exist, we will create it as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">touch \/var\/log\/mariadb.log <\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">chown mysql: mysql \/var\/log\/mariadb.log<\/pre>\n\n\n\n<p><strong>Step&nbsp;<\/strong><strong>4<\/strong><strong>:<\/strong><\/p>\n\n\n\n<p>Create Galera Cluster on the first node.<\/p>\n\n\n\n<p>We are now ready to create the cluster on 192.168.1.11. Keep in mind that do not run the cluster creation command on more than one node.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">galera_new_cluster<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"431\" height=\"25\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img8.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7869\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img8.jpg 431w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img8-300x17.jpg 300w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img8-417x25.jpg 417w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/figure>\n\n\n\n<p>Verify the MariaDB running with right port 3306 and cluster with 4567 using this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">netstat -tulnp<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"898\" height=\"160\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img9.jpg\" alt=\"How to Configure MariaDB Galera Cluster on CentOS 7?\" class=\"wp-image-7870\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img9.jpg 898w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img9-300x53.jpg 300w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img9-768x137.jpg 768w\" sizes=\"(max-width: 898px) 100vw, 898px\" \/><\/figure>\n\n\n\n<p>after that, restart the MariaDB on the first node (192.168.1.11)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart mariadb <\/pre>\n\n\n\n<p><strong>Step&nbsp;<\/strong><strong>5<\/strong><strong>:<\/strong><\/p>\n\n\n\n<p>Verify the Galera Master Node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -u root -p <\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">SHOW STATUS LIKE 'wsrep_cluster_size';<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"326\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img10.jpg\" alt=\"\" class=\"wp-image-7871\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img10.jpg 732w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img10-300x134.jpg 300w\" sizes=\"(max-width: 732px) 100vw, 732px\" \/><\/figure>\n\n\n\n<p>As we can see from the cluster size, there is only one member node in the cluster which is the primary master node we just configured<\/p>\n\n\n\n<p><strong>Step&nbsp;<\/strong><strong>6<\/strong><strong>:<\/strong><\/p>\n\n\n\n<p>Add additional nodes to Galera Cluster<\/p>\n\n\n\n<p>Follow this Step to add the content of [galera] section on second node (192.168.1.12). Only change the value for node address and node name respectively:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wsrep_node_address=\"192.168.1.12\" wsrep_node_name=\"galera2\"<\/pre>\n\n\n\n<p>The wsrep_node_address is the IP address of the node being configured, and the wsrep_node_name is the name of that node. After adding each servers configuration file, we can start or restart MariaDB.<\/p>\n\n\n\n<p><strong>Step 7:<\/strong><\/p>\n\n\n\n<p>Run the following command on the second node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">galera_new_cluster<\/pre>\n\n\n\n<p>After this, you can restart the MariaDB service on nodes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart mariadb<\/pre>\n\n\n\n<p>To check the total Custer Size, you can use the below command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SHOW STATUS LIKE 'wsrep_cluster_size';<\/pre>\n\n\n\n<p>We have configured two nodes as a Cluster.<\/p>\n\n\n\n<p><strong>Step 8:<\/strong><\/p>\n\n\n\n<p>Testing replication on Galera Cluster<\/p>\n\n\n\n<p>We can test the replication between cluster nodes are functioning as expected by creating a test database on one node and viewing the database list on another node. The test database should be on all the nodes if replication is working properly. We are going to create a test database named \u2018galera_db_test\u2019 on node 1. create database galera_db_test;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"484\" height=\"98\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img12.jpg\" alt=\"\" class=\"wp-image-7872\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img12.jpg 484w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img12-300x61.jpg 300w\" sizes=\"(max-width: 484px) 100vw, 484px\" \/><\/figure>\n\n\n\n<p>Database has been created. Now you can verify on all nodes that replication is working by using this command in MySQL:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">show databases;<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"406\" height=\"281\" src=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img13.jpg\" alt=\"\" class=\"wp-image-7873\" srcset=\"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img13.jpg 406w, https:\/\/www.infinitivehost.com\/knowledge-base\/wp-content\/uploads\/2023\/07\/galera-img13-300x208.jpg 300w\" sizes=\"(max-width: 406px) 100vw, 406px\" \/><\/figure>\n\n\n\n<p>Galera cluster has been configured.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2,157 Views A multi-master cluster for MariaDB, Galera uses synchronous replication to replicate data. Using Galera, each node in the cluster may be a master and write to any other node simultaneously. Galera\u2019s active design lacks failover, enhances load balancing, and fault tolerance. This tutorial will examine how to set up a Galera cluster with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[52,54,49,50,53,51,56],"tags":[],"class_list":["post-7859","post","type-post","status-publish","format-standard","hentry","category-dedicated-server","category-email","category-reseller-hosting","category-shared-hosting","category-streaming-server","category-vps","category-windows"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/7859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=7859"}],"version-history":[{"count":4,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/7859\/revisions"}],"predecessor-version":[{"id":7875,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/7859\/revisions\/7875"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=7859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=7859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=7859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}