477 views
asked in MariaDB by
Configure MariaDB Galera Cluster in ubuntu 24.04 LTS

1 Answer

answered by

inchirags@gmail.com   MariaDB DBA Tutorial         https://www.chirags.in

*****************************************************************************************

* Configure MariaDB Galera Cluster in ubuntu 24.04 LTS *

*****************************************************************************************

YouTube Video

Here's a step-by-step guide to configure a MariaDB Galera Cluster on Ubuntu 24.04 LTS:

Server Details:

+---------+-------------------+
| Server  |   Server IP       |
+---------+-------------------+
| Server1 | 192.168.224.129   |
| Server2 | 192.168.224.130   |
| Server3 | 192.168.224.131   |
+---------+-------------------+

Step 1: Firewall Configuration

sudo ufw status
sudo ufw allow ssh
sudo ufw allow 3306/tcp
sudo ufw allow 4567/tcp
sudo ufw allow 4568/tcp
sudo ufw allow 4444/tcp
sudo ufw enable

Step 2: Update and Install Required Packages

Run these commands on all cluster nodes:

sudo apt update
sudo apt upgrade -y

sudo apt install mariadb-server mariadb-client rsync -y

sudo systemctl start mariadb
sudo systemctl enable mariadb

sudo systemctl status mariadb

Step 3: Configure MariaDB on All Nodes

Edit the MariaDB configuration file:

#Primary Node

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add or update the following configuration under [mysqld]:

Add # before 

# bind-address=127.0.0.1

# add to last line

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.224.129,192.168.224.130,192.168.224.131"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# any cluster name
wsrep_cluster_name="MariaDB_Cluster"
# own IP address
wsrep_node_address="192.168.224.129"

#Secondary Node1

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add or update the following configuration under [mysqld]:

Add # before 

# bind-address=127.0.0.1

# add to the end

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# specify all nodes in cluster
wsrep_cluster_address="gcomm://192.168.224.129,192.168.224.130,192.168.224.131"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# any cluster name
wsrep_cluster_name="MariaDB_Cluster"
# specify this host's IP address
wsrep_node_address="192.168.224.130"

#Secondary Node2

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add or update the following configuration under [mysqld]:

Add # before 

# bind-address=127.0.0.1

# add to the end

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# specify all nodes in cluster
wsrep_cluster_address="gcomm://192.168.224.129,192.168.224.130,192.168.224.131"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# any cluster name
wsrep_cluster_name="MariaDB_Cluster"
# specify this host's IP address
wsrep_node_address="192.168.224.131"

Save and exit the all the files.

Step 4: Start the Cluster

On the first node only:

#in Node 1 (Primary Node)

sudo systemctl stop mariadb
sudo galera_new_cluster
sudo systemctl start mariadb

#On the other nodes:

sudo systemctl stop mariadb
sudo systemctl start mariadb

Verify cluster status:

MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_local_state_comment';
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_status';

-- wsrep_cluster_size should match the number of nodes.

-- wsrep_cluster_status should be Primary.

-- wsrep_local_state_comment should show Synced.

Step 5: Create a Test Database

On any node:

Run the following SQL commands:

-- Create a Test Database

CREATE DATABASE galera_test;

-- Use the Test Database

USE galera_test;

-- Create a Test Table

CREATE TABLE test_table (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Insert Sample Data

INSERT INTO test_table (name) VALUES ('Node1 Test'), ('Node2 Test'), ('Node3 Test');

Step 6: Verify Data on All Nodes

On Node1:

Connect directly to Node1:

mysql -u root -p

Check the data:

MariaDB [(none)]> USE galera_test;
MariaDB [galera_test]> SELECT * FROM test_table;

Output:

+----+------------+---------------------+
| id | name       | created_at          |
+----+------------+---------------------+
|  1 | Node1 Test | 2025-01-01 15:59:58 |
|  4 | Node2 Test | 2025-01-01 15:59:58 |
|  7 | Node3 Test | 2025-01-01 15:59:58 |
+----+------------+---------------------+
3 rows in set (0.001 sec)

On Node2 and Node3:

Repeat the same steps on each node (192.168.224.130, 192.168.224.131).

Check if the database replicates on other nodes.

Your MariaDB Galera Cluster is now successfully set up on Ubuntu 24.04 LTS! Let me know if you encounter any issues.

For any doubts and query, please write on YouTube video comments section.

Note : Flow the Process shown in video.

Please, Subscribe and like for more videos:

https://www.youtube.com/@chiragstutorial

Don't forget to, Follow, Like,  Share &, Comment

Thanks & Regards,

Chitt Ranjan Mahto "Chirag"

_________________________________________________________________________________________

Note: All scripts used in this demo will be available in our website.

Link will be available in description.

Most popular tags

laravel postgresql laravel-10 replication ha postgresql mongodb laravel-11 mongodb database mongodb tutorial ubuntu 24.04 lts streaming-replication mysql database laravel postgresql backup laravel login register logout database mysql php laravel 11 - login with otp valid for 10 minutes. user and admin registration user and admin login multiauth technlogy asp.net asp.net c# mysql master slave replication centos linux laravel sql server schedule backup autobackup postgresql django python haproxy load balancer install self sign ssl laravel 11 gaurds zabbix 7 how to install graylog on ubuntu 24.04 lts | step-by-step asp.net core mvc .net mvc network upload c# ssl integration sql server on ubuntu 22.04 lts mssql server ms sql server sql server user access in postgres mysql password change cent os linux configure replica laravel 11 socialite login with google account google login kubernetes (k8s) install nginx load balancer install install and configure .net 8.0 in ubuntu 24.04 lts php in iis php with iis php tutorial chirags php tutorials chirags php tutorial chirags tutorial laravel 11 guards mongodb sharding metabase business analytics metabase postgresql 16 to postgresql 17 postgresql migration letsencrypt mongodb crud rocky linux laravel custom captcha laravel 11 captcha laravel captcha mongo dll php.ini debian 12 nginx apache nextcloud gitea in ubuntu git gitea npm error node js mysql ndb cluster mysql cluster ssl oracle login register logout in python debian windows shell batch file bat file time stamp date time shopping cart in laravel centos rhel swap memeory rhel 5.5
...