{"id":7055,"date":"2023-10-23T21:39:52","date_gmt":"2023-10-23T21:39:52","guid":{"rendered":"https:\/\/www.webhi.com\/how-to\/?p=7055"},"modified":"2023-10-23T21:39:54","modified_gmt":"2023-10-23T21:39:54","slug":"setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel","status":"publish","type":"post","link":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/","title":{"rendered":"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en.jpg\" alt=\"install and configure a Two Node Galera Cluster for MySQL\" class=\"wp-image-7071\" srcset=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en.jpg 1200w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en-300x169.jpg 300w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en-1024x576.jpg 1024w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en-768x432.jpg 768w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en-150x84.jpg 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction\">Introduction<\/h2>\n\n\n\n<p><strong>Galera Cluster<\/strong> enables building a high availability <strong>MySQL \/ MariaDB<\/strong> database cluster without compromising data consistency. By replicating data across nodes in real-time, Galera provides continuous uptime even when individual nodes fail.<\/p>\n\n\n\n<p>In this comprehensive tutorial, we will walk through the steps to configure a two node Galera cluster on Ubuntu\/Debian and CentOS\/RHEL Linux.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h3>\n\n\n\n<p>Before we begin, ensure you have:<\/p>\n\n\n\n<ul>\n<li>2 servers or VMs with Ubuntu 18.04+\/Debian 9+ or CentOS 7+\/RHEL 7+ installed.<\/li>\n\n\n\n<li>At least 2GB RAM and 2 vCPU cores on each node.<\/li>\n\n\n\n<li>Root access to servers via SSH.<\/li>\n\n\n\n<li>MySQL server already installed on both nodes. Version 5.7+ recommended.<\/li>\n\n\n\n<li>Basic firewall rules configured to allow traffic on ports 3306, 4567, 4568 and 4444.<\/li>\n<\/ul>\n\n\n\n<p>We will be executing most commands as the root user or with sudo privileges.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-galera-and-related-packages\">Installing Galera and Related Packages<\/h2>\n\n\n\n<p>We begin by installing the Galera Cluster software and other utilities needed for proper functioning of the cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"on-ubuntudebian\">On Ubuntu\/Debian<\/h3>\n\n\n\n<p>Update apt repository indexes and install the required packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ apt update\n$ apt install galera-4 mariadb-server socat python3-mysql.connector<\/code><\/pre>\n\n\n\n<p>This installs:<\/p>\n\n\n\n<ul>\n<li>galera-4 &#8211; Galera Cluster frameworks<\/li>\n\n\n\n<li>mariadb-server &#8211; For MySQL database server<\/li>\n\n\n\n<li>socat &#8211; For testing &amp; monitoring clusters<\/li>\n\n\n\n<li>python3-mysql.connector &#8211; For MySQL connections from Python<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"on-centosrhel\">On CentOS\/RHEL<\/h3>\n\n\n\n<p>Enable EPEL repos which provide the Galera packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ yum install epel-release<\/code><\/pre>\n\n\n\n<p>Now install Galera and dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ yum install galera mariadb-server rsync socat mysql-connector-python<\/code><\/pre>\n\n\n\n<p>This installs:<\/p>\n\n\n\n<ul>\n<li>galera &#8211; Galera Cluster<\/li>\n\n\n\n<li>mariadb-server &#8211; MySQL server<\/li>\n\n\n\n<li>rsync &#8211; For SST snapshot transfers<\/li>\n\n\n\n<li>socat &#8211; Monitoring utility<\/li>\n\n\n\n<li>mysql-connector-python &#8211; Python MySQL connector<\/li>\n<\/ul>\n\n\n\n<p>Galera Cluster is now ready to be configured on both nodes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"configuring-mysql-for-galera\">Configuring MySQL for Galera<\/h2>\n\n\n\n<p>For MySQL to use Galera, we need to configure some options in&nbsp;<code>my.cnf<\/code>.<\/p>\n\n\n\n<p>Open the config file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ nano \/etc\/my.cnf<\/code><\/pre>\n\n\n\n<p>Add the following under&nbsp;<code>[mysqld]<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">binlog_format=ROW\ndefault-storage-engine=innodb\ninnodb_autoinc_lock_mode=2\nbind-address=0.0.0.0\n\n# Galera settings\nwsrep_provider=\/usr\/lib64\/galera-4\/libgalera_smm.so\nwsrep_cluster_name='my_galera_cluster'\nwsrep_cluster_address=\"gcomm:\/\/node1,node2\"\n\n# This Only on Node 1\nwsrep_node_address='192.168.1.101'\nwsrep_node_name='node1'\n\n# This Only on Node 2\nwsrep_node_address='192.168.1.102'\nwsrep_node_name='node2'\n\nwsrep_sst_method=rsync<\/code><\/pre>\n\n\n\n<p>The&nbsp;<code>wsrep_cluster_address<\/code>&nbsp;contains a list of cluster node IPs.<\/p>\n\n\n\n<p><code>wsrep_node_address<\/code>&nbsp;and&nbsp;<code>wsrep_node_name<\/code>&nbsp;must be unique on every server.<\/p>\n\n\n\n<p>Save and close the file after making changes.<\/p>\n\n\n\n<p>Do this on both servers, replacing the IPs and names as per your servers.<\/p>\n\n\n\n<p>This configures MySQL to use the Galera plugin for replication.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"starting-the-galera-cluster\">Starting the Galera Cluster<\/h2>\n\n\n\n<p>With configuration in place, we are ready to bootstrap the cluster.<\/p>\n\n\n\n<p>Start MySQL only on the first node (node1):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ systemctl start mysql\n<em># or <\/em>\n$ systemctl start mariadb<\/code><\/pre>\n\n\n\n<p>This will initialize the Galera cluster.<\/p>\n\n\n\n<p>Check MySQL status and wsrep variables:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ mysql -u root -e \"SHOW STATUS LIKE '%wsrep%';\"<\/code><\/pre>\n\n\n\n<p>Example output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">+------------------------------+-------------------------------------------------+\n| Variable_name                | Value                                           |\n+------------------------------+-------------------------------------------------+\n| wsrep_local_state_uuid       | af2a75b4-9e1c-11ed-9838-be4b133a6b15            |\n| wsrep_protocol_version       | 7                                               |   \n| wsrep_last_committed         | 0                                               |\n| wsrep_replicated             | 0                                               |\n| wsrep_replicated_bytes       | 0                                               |\n| wsrep_repl_keys              | 0                                               |\n| wsrep_repl_keys_bytes        | 0                                               |\n| wsrep_repl_data_bytes        | 0                                               |\n| wsrep_repl_other_bytes       | 0                                               |\n| wsrep_received               | 1                                               |\n| wsrep_received_bytes         | 119                                             | \n| wsrep_local_commits          | 0                                               |  \n| wsrep_local_cert_failures    | 0                                               |\n| wsrep_local_replays          | 0                                               |\n| wsrep_local_send_queue       | 0                                               |\n| wsrep_local_send_queue_avg   | 0.000000                                        |        \n| wsrep_local_recv_queue       | 0                                               |\n| wsrep_local_recv_queue_avg   | 0.000000                                        |  \n| wsrep_local_cached_downto    | 18446744073709551615                            |\n| wsrep_flow_control_paused_ns | 0                                               |\n| wsrep_flow_control_sent      | 0                                               |\n| wsrep_flow_control_recv      | 0                                               |\n+------------------------------+-------------------------------------------------+ <\/code><\/pre>\n\n\n\n<p>This confirms Galera is operational. Note the local cluster size is 1 right now.<\/p>\n\n\n\n<p>Now start MySQL on the second node to join it to the cluster:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ systemctl start mysql\n<em># or<\/em>\n$ systemctl start mariadb<\/code><\/pre>\n\n\n\n<p>Verify it joined successfully:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ mysql -u root -e \"SHOW STATUS LIKE '%wsrep%';\"<\/code><\/pre>\n\n\n\n<p>We should now see the cluster size as 2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">| wsrep_cluster_size |2|<\/code><\/pre>\n\n\n\n<p>Additionally, run&nbsp;<code>mysql -e \"SHOW STATUS LIKE '%wsrep%';\"<\/code>&nbsp;on node1 again and the status variables should sync up between both nodes.<\/p>\n\n\n\n<p>Our two node Galera cluster is ready!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"testing-cluster-operation\">Testing Cluster Operation<\/h2>\n\n\n\n<p>Let&#8217;s test replication between the two nodes works as expected.<\/p>\n\n\n\n<p>On node1, create a test database and insert some data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt; CREATE DATABASE cluster_test;\nmysql&gt; USE cluster_test;\nmysql&gt; CREATE TABLE test (id INT, message VARCHAR(20));\nmysql&gt; INSERT INTO test VALUES (1, 'Hello Galera');\nmysql&gt; SELECT * FROM test;\n+------+----------------+ \n| id   | message        |\n+------+----------------+\n|    1 | Hello Galera   |\n+------+----------------+ <\/code><\/pre>\n\n\n\n<p>Now check the same table contents from node2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt; USE cluster_test; \nmysql&gt; SELECT * FROM test;\n+------+----------------+\n| id   | message        |\n+------+----------------+\n|    1 | Hello Galera   |\n+------+----------------+<\/code><\/pre>\n\n\n\n<p>The row replicated from node1 to node2 as expected.<\/p>\n\n\n\n<p>Let&#8217;s also test shutdown recovery. Stop MySQL on node1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ systemctl stop mysql\n<em># or<\/em>\n$ systemctl stop mariadb  <\/code><\/pre>\n\n\n\n<p>On node2, connect to MySQL and verify queries still work:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt; USE cluster_test;\nmysql&gt; SELECT * FROM test;\n+------+----------------+ \n| id   | message        |\n+------+----------------+\n|    1 | Hello Galera   |\n+------+----------------+<\/code><\/pre>\n\n\n\n<p>Node2 remains operational despite node1 shutdown since all data is replicated.<\/p>\n\n\n\n<p>Bring node1 back up:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ systemctl start mysql\n<em># or <\/em>\n$ systemctl start mariadb<\/code><\/pre>\n\n\n\n<p>It will sync again with node2 automatically. Run&nbsp;<code>SHOW STATUS LIKE '%wsrep%';<\/code>&nbsp;on both nodes to confirm values match.<\/p>\n\n\n\n<p>This demonstrates the high availability provided by Galera!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cluster-monitoring--management\">Cluster Monitoring &amp; Management<\/h2>\n\n\n\n<p>Now that we have a working Galera cluster, let&#8217;s look at some tips for monitoring and managing it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-cluster-status\">Checking Cluster Status<\/h3>\n\n\n\n<p>Use the&nbsp;<code>garbd<\/code>&nbsp;daemon to check high level cluster stats:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ garbd -a gcomm:\/\/192.168.1.101,192.168.1.102 -g my_galera_cluster\nGalera cluster Node 1\/2 info:\n  evs::protover =&gt; 7\n  evs::uuid     =&gt; af2a75b4-9e1c-11ed-9838-be4b133a6b15\n  evs::status   =&gt; Primary\n  evs::state    =&gt; Synced\nGalera cluster Node 2\/2 info: \n  evs::protover =&gt; 7 \n  evs::uuid     =&gt; af2a75b4-9e1c-11ed-9838-be4b133a6b15\n  evs::status   =&gt; Primary\n  evs::state    =&gt; Synced<\/code><\/pre>\n\n\n\n<p>This shows both nodes are in Synced state and part of the same cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"monitoring-node-status\">Monitoring Node Status<\/h3>\n\n\n\n<p>Use&nbsp;<code>mysqladmin<\/code>&nbsp;to check Galera variables on each node:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ mysqladmin -uroot -p -h192.168.1.101 variables | grep wsrep\n\n| wsrep_cluster_conf_id | 25 |\n| wsrep_cluster_size | 2 |\n| wsrep_cluster_state_uuid | af2a75b4-9e1c-11ed-9838-be4b133a6b15 |\n| wsrep_cluster_status | Primary |\n\n$ mysqladmin -uroot -p -h192.168.1.102 variables | grep wsrep \n\n| wsrep_cluster_conf_id | 25 |\n| wsrep_cluster_size | 2 |\n| wsrep_cluster_state_uuid | af2a75b4-9e1c-11ed-9838-be4b133a6b15 | \n| wsrep_cluster_status | Primary | <\/code><\/pre>\n\n\n\n<p>Values like cluster size, UUID, status should match on all nodes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-sst-transfer-status\">Checking SST Transfer Status<\/h3>\n\n\n\n<p>When a new node joins, State Snapshot Transfer (SST) is used to sync data to it.<\/p>\n\n\n\n<p>Monitor SST progress with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ mysql -e \"SHOW STATUS LIKE 'wsrep_local_state_uuid'\"\n+----------------------------------+--------------------------------------+\n| Variable_name                    | Value                                |  \n+----------------------------------+--------------------------------------+\n| wsrep_local_state_uuid           | af2a75b4-9e1c-11ed-9838-be4b133a6b15 |\n+----------------------------------+--------------------------------------+\n\n$ mysql -e \"SHOW STATUS LIKE 'wsrep_local_state_comment'\"\n+-----------------------------------+---------+ \n| Variable_name                     | Value   |\n+-----------------------------------+---------+\n| wsrep_local_state_comment         | Synced  |\n+-----------------------------------+---------+<\/code><\/pre>\n\n\n\n<p>While SST is in progress,&nbsp;<code>wsrep_local_state_comment<\/code>&nbsp;will show the sync percentage.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-recovery-status\">Checking Recovery Status<\/h3>\n\n\n\n<p>When a node rejoins after disconnect, status can be checked with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt;SHOW STATUS WHERE `variable_name` LIKE'wsrep_%';<\/code><\/pre>\n\n\n\n<p>Look for&nbsp;<code>wsrep_local_state_comment<\/code>&nbsp;like&nbsp;<code>Recovering<\/code>&nbsp;or&nbsp;<code>Donor\/Desynced<\/code>&nbsp;during recovery.<\/p>\n\n\n\n<p>This way various stages of cluster syncs and recovery can be tracked.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"monitoring-cluster-size\">Monitoring Cluster Size<\/h3>\n\n\n\n<p>To check the number of nodes in the cluster:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt; SHOW STATUS LIKE 'wsrep_cluster_size'; \n+--------------------+-------+\n| Variable_name      | Value |\n+--------------------+-------+\n| wsrep_cluster_size | 2     |\n+--------------------+-------+<\/code><\/pre>\n\n\n\n<p>Matching the expected number of nodes.<\/p>\n\n\n\n<p>We can also use the&nbsp;<code>clustercheck<\/code>&nbsp;script to monitor cluster size:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ clustercheck\nCluster is CORRECT (2 nodes)\n$ <\/code><\/pre>\n\n\n\n<p>This will warn if nodes are missing or extra.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-node-consistency\">Checking Node Consistency<\/h3>\n\n\n\n<p>The cluster status should be verified to ensure all nodes contain the same data.<\/p>\n\n\n\n<p>Comparing&nbsp;<code>wsrep_local_state_uuid<\/code>&nbsp;variable between nodes indicates consistency:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ mysql -e \"SHOW STATUS LIKE 'wsrep_local_state_uuid'\\G\" -h192.168.1.101\n   *************************** 1. row ***************************\n   Variable_name: wsrep_local_state_uuid\n        Value: af2a75b4-9e1c-11ed-9838-be4b133a6b15\n\n$ mysql -e \"SHOW STATUS LIKE 'wsrep_local_state_uuid'\\G\" -h192.168.1.102   \n   *************************** 1. row ***************************\n   Variable_name: wsrep_local_state_uuid\n        Value: af2a75b4-9e1c-11ed-9838-be4b133a6b15<\/code><\/pre>\n\n\n\n<p>If the UUID matches on nodes, data is consistent.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-connection-status\">Checking Connection Status<\/h3>\n\n\n\n<p>Use&nbsp;<code>socat<\/code>&nbsp;to check TCP connection status between nodes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ socat - TCP:192.168.1.101:4567\n&gt; \n$ socat - TCP:192.168.1.102:4567\n&gt;<\/code><\/pre>\n\n\n\n<p>This confirms TCP port 4567 is open between nodes for Galera Cluster replication traffic.<\/p>\n\n\n\n<p>We can also use MySQL to check connection status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt; SHOW STATUS WHERE `variable_name` LIKE '%connection%';\n+-----------------------------+-------+\n| Variable_name               | Value |  \n+-----------------------------+-------+\n| Slave_connections           | 0     |\n| Max_used_connections        | 2     |\n| Aborted_connects            | 0     |\n| Max_used_connections        | 2     |\n+-----------------------------+-------+<\/code><\/pre>\n\n\n\n<p>Monitor open connection count to detect issues.<\/p>\n\n\n\n<p>This provides insight into overall cluster health and connectivity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tracking-node-history\">Tracking Node History<\/h3>\n\n\n\n<p>The node history can be useful when troubleshooting or analyzing events:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt; SHOW STATUS LIKE 'wsrep_local_state_uuid%';\n+--------------------------------+--------------------------------------+\n| Variable_name                  | Value                                |\n+--------------------------------+--------------------------------------+  \n| wsrep_local_state_uuid         | af2a75b4-9e1c-11ed-9838-be4b133a6b15 |\n| wsrep_local_state_uuid_history | af2a75b4-9e1c-11ed-9838-be4b133a6b15 |\n+--------------------------------+--------------------------------------+<\/code><\/pre>\n\n\n\n<p>Any past cluster UUIDs will be appended to&nbsp;<code>wsrep_local_state_uuid_history<\/code>&nbsp;on events like recoveries.<\/p>\n\n\n\n<p>Similarly, the number of cluster membership changes is tracked by:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">mysql&gt; SHOW STATUS LIKE 'wsrep_cluster_size_change%';\n+-------------------------------+-------+\n| Variable_name                 | Value |  \n+-------------------------------+-------+\n| wsrep_cluster_size_changes    | 1     |\n| wsrep_cluster_size_change_history | 1 |\n+-------------------------------+-------+<\/code><\/pre>\n\n\n\n<p>This provides insight into cluster activity over time.<\/p>\n\n\n\n<p>Using these status variables and commands, the Galera cluster can be monitored for proper operation. Issues like node disconnects, replication lag, or consistency loss can be rapidly detected and debugged as well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"configuring-galera-arbitrator-optional\">Configuring Galera Arbitrator (optional)<\/h2>\n\n\n\n<p>For a two node cluster, we should setup a Galera Arbitrator to avoid split brain scenarios. The arbitrator is a lightweight process that provides a quorum for the cluster to determine which node should continue operating in case of network splits.<\/p>\n\n\n\n<p>On a third server, install just the&nbsp;<code>galera-4<\/code>&nbsp;or&nbsp;<code>galera<\/code>&nbsp;package.<\/p>\n\n\n\n<p>Modify&nbsp;<code>\/etc\/my.cnf<\/code>&nbsp;with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">[mysqld]\nwsrep_provider=\/usr\/lib64\/galera-4\/libgalera_smm.so\n\n[galera]\nwsrep_cluster_address=\"gcomm:\/\/192.168.1.101,192.168.1.102\" \nwsrep_cluster_name='my_galera_cluster'<\/code><\/pre>\n\n\n\n<p>Start the arbitrator:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ galera_arbitrator<\/code><\/pre>\n\n\n\n<p>Check logs at&nbsp;<code>\/var\/log\/mysql\/galera.log<\/code>&nbsp;to ensure it connected to the cluster successfully.<\/p>\n\n\n\n<p>The arbitrator will now participate in quorum calculations and provide automatic failover in split brain scenarios. This prevents data loss in the event of network partitions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>In this detailed guide, we covered the steps to install, configure and monitor a two node Galera cluster on Ubuntu\/Debian and CentOS\/RHEL distributions step-by-step with practical examples.<\/p>\n\n\n\n<p>Key takeaways include:<\/p>\n\n\n\n<ul>\n<li>Galera enables building multi-master MySQL clusters for high availability.<\/li>\n\n\n\n<li>Real-time row based replication provides consistency.<\/li>\n\n\n\n<li>Nodes can be dynamically added and removed.<\/li>\n\n\n\n<li>Automatic node joining, state transfers and quorum handling.<\/li>\n\n\n\n<li>Monitoring key status variables like wsrep metrics.<\/li>\n\n\n\n<li>Galera arbitrator prevents split brain scenarios.<\/li>\n<\/ul>\n\n\n\n<p>A two node Galera cluster serves well for reducing downtime and providing redundancy for many applications. Additional nodes can be introduced seamlessly later if needed.<\/p>\n\n\n\n<p>Using this tutorial as a guide, you can now deploy highly available MySQL clusters with Galera on Ubuntu\/Debian and CentOS\/RHEL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Galera Cluster enables building a high availability MySQL \/ MariaDB database cluster without compromising data consistency. By replicating data across nodes in real-time, Galera provides continuous uptime even when individual nodes fail. In this comprehensive tutorial, we will walk through the steps to configure a two node Galera cluster on Ubuntu\/Debian and CentOS\/RHEL Linux. ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[57,69],"tags":[],"yoast_head":"\n<title>Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL - WebHi Tutorials &amp; Documentations<\/title>\n<meta name=\"description\" content=\"Step-by-step guide to install, configure and monitor a highly available Galera cluster for MySQL \/ MariaDB on Ubuntu\/Debian and CentOS\/RHEL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL - WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"og:description\" content=\"Step-by-step guide to install, configure and monitor a highly available Galera cluster for MySQL \/ MariaDB on Ubuntu\/Debian and CentOS\/RHEL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webhi.technology\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-23T21:39:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-23T21:39:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en.jpg\" \/>\n<meta name=\"author\" content=\"webhi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:site\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webhi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\"},\"author\":{\"name\":\"webhi\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\"},\"headline\":\"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL\",\"datePublished\":\"2023-10-23T21:39:52+00:00\",\"dateModified\":\"2023-10-23T21:39:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\"},\"wordCount\":1103,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"articleSection\":[\"Databases\",\"Linux system administration\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\",\"name\":\"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL - WebHi Tutorials &amp; Documentations\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\"},\"datePublished\":\"2023-10-23T21:39:52+00:00\",\"dateModified\":\"2023-10-23T21:39:54+00:00\",\"description\":\"Step-by-step guide to install, configure and monitor a highly available Galera cluster for MySQL \/ MariaDB on Ubuntu\/Debian and CentOS\/RHEL.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webhi.com\/how-to\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"name\":\"WebHi Tutorials &amp; Documentations\",\"description\":\"System administration and knowledge base\",\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\",\"name\":\"WebHi Technology\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"width\":288,\"height\":95,\"caption\":\"WebHi Technology\"},\"image\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webhi.technology\",\"https:\/\/twitter.com\/WebHiTechnology\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\",\"name\":\"webhi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1782424353\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1782424353\",\"caption\":\"webhi\"},\"sameAs\":[\"https:\/\/www.webhi.com\/how-to\"],\"url\":\"https:\/\/www.webhi.com\/how-to\/author\/webhi\/\"}]}<\/script>\n","yoast_head_json":{"title":"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL - WebHi Tutorials &amp; Documentations","description":"Step-by-step guide to install, configure and monitor a highly available Galera cluster for MySQL \/ MariaDB on Ubuntu\/Debian and CentOS\/RHEL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/","og_locale":"en_US","og_type":"article","og_title":"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL - WebHi Tutorials &amp; Documentations","og_description":"Step-by-step guide to install, configure and monitor a highly available Galera cluster for MySQL \/ MariaDB on Ubuntu\/Debian and CentOS\/RHEL.","og_url":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/","og_site_name":"WebHi Tutorials &amp; Documentations","article_publisher":"https:\/\/www.facebook.com\/webhi.technology","article_published_time":"2023-10-23T21:39:52+00:00","article_modified_time":"2023-10-23T21:39:54+00:00","og_image":[{"url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/10\/galera_cluster_en.jpg"}],"author":"webhi","twitter_card":"summary_large_image","twitter_creator":"@WebHiTechnology","twitter_site":"@WebHiTechnology","twitter_misc":{"Written by":"webhi","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#article","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/"},"author":{"name":"webhi","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54"},"headline":"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL","datePublished":"2023-10-23T21:39:52+00:00","dateModified":"2023-10-23T21:39:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/"},"wordCount":1103,"commentCount":0,"publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"articleSection":["Databases","Linux system administration"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/","url":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/","name":"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL - WebHi Tutorials &amp; Documentations","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/#website"},"datePublished":"2023-10-23T21:39:52+00:00","dateModified":"2023-10-23T21:39:54+00:00","description":"Step-by-step guide to install, configure and monitor a highly available Galera cluster for MySQL \/ MariaDB on Ubuntu\/Debian and CentOS\/RHEL.","breadcrumb":{"@id":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhi.com\/how-to\/setup-config-galera-cluster-for-mysql-mariadb-ubuntu-debian-centos-rhel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhi.com\/how-to\/"},{"@type":"ListItem","position":2,"name":"Setup Galera Cluster for MySQL\/MariaDB on Ubuntu\/Debian and CentOS\/RHEL"}]},{"@type":"WebSite","@id":"https:\/\/www.webhi.com\/how-to\/#website","url":"https:\/\/www.webhi.com\/how-to\/","name":"WebHi Tutorials &amp; Documentations","description":"System administration and knowledge base","publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webhi.com\/how-to\/#organization","name":"WebHi Technology","url":"https:\/\/www.webhi.com\/how-to\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/","url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","contentUrl":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","width":288,"height":95,"caption":"WebHi Technology"},"image":{"@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webhi.technology","https:\/\/twitter.com\/WebHiTechnology"]},{"@type":"Person","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54","name":"webhi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/","url":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1782424353","contentUrl":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1782424353","caption":"webhi"},"sameAs":["https:\/\/www.webhi.com\/how-to"],"url":"https:\/\/www.webhi.com\/how-to\/author\/webhi\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/7055"}],"collection":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/comments?post=7055"}],"version-history":[{"count":8,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/7055\/revisions"}],"predecessor-version":[{"id":7083,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/7055\/revisions\/7083"}],"wp:attachment":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/media?parent=7055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/categories?post=7055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/tags?post=7055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}