Configure MariaDB Galera Cluster in ubuntu 24.04 LTS

Configure MariaDB Galera Cluster in ubuntu 24.04 LTS

[email protected] ? 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.

要查看或添加评论,请登录

Chitt Ranjan Mahto的更多文章

社区洞察

其他会员也浏览了