Table of Contents
Introduction
MariaDB Galera Cluster is a robust solution that combines the power of MariaDB, an open-source relational database management system, with Galera Cluster, a synchronous multi-master replication plugin.
MariaDB, a popular MySQL fork, offers a feature-enhanced and community-driven alternative to MySQL.
Galera Cluster, on the other hand, is a sophisticated replication technology that operates in a synchronous manner. It allows multiple database nodes to work together as a cluster, ensuring that all nodes have an identical copy of the database.
Use Cases : MariaDB Galera Cluster
E-commerce platforms
Ensuring uninterrupted availability and consistent data across multiple locations.
Financial systems
Maintaining data integrity and eliminating single points of failure.
Mission-critical applications
Providing fault tolerance and high performance for critical business operations.
Key Features and Benefits: MariaDB Galera Cluster
High Availability
With MariaDB Galera Cluster, your database remains highly available even in the event of node failures. If one node becomes unreachable, the cluster automatically promotes another node as the new primary, ensuring continuous operation and minimal downtime.
Data Consistency
Galera Cluster’s synchronous replication ensures that data consistency is maintained across all nodes in real time. Each transaction is applied uniformly to every node, preventing any data discrepancies or conflicts.
Scalability and Load Balancing
By distributing the workload across multiple nodes, MariaDB Galera Cluster allows you to scale your database system horizontally. As your application grows, you can add additional nodes to handle increased traffic, providing enhanced performance and improved response times. Load balancing is inherent to the cluster setup, enabling efficient resource utilization.
Automatic Data Distribution
When you write data to the cluster, it is automatically synchronized across all nodes. This means that read queries can be executed on any node, promoting load balancing and reducing the load on individual nodes.
How to set up a MariaDB Galera Cluster using Docker
you can follow these steps
Install Docker
If you haven’t already, install Docker on your system. Refer to
- How to install Docker on Ubuntu
- Install docker and learn containers on Centos
- Install Docker on Vagrant
Create a Docker network
Open a terminal and create a Docker network that will be used by the Galera cluster nodes:
Create Galera Cluster Containers
Create multiple Docker containers, each representing a node in the Galera cluster.
You can use the official MariaDB Galera Cluster Docker image or a custom image. For example, creating three nodes:
# docker run -d --name=node1 --network=galera_network -e MYSQL_ROOT_PASSWORD=my-secret-pw -e GALERA_CLUSTER=galera_cluster -e GALERA_NODE_NAME=node1 -e GALERA_NODE_ADDRESS=node1 mariadb:10.6 --wsrep-new-cluster
# docker run -d --name=node2 --network=galera_network -e MYSQL_ROOT_PASSWORD=my-secret-pw -e GALERA_CLUSTER=galera_cluster -e GALERA_NODE_NAME=node2 -e GALERA_NODE_ADDRESS=node2 mariadb:10.6
# docker run -d --name=node3 --network=galera_network -e MYSQL_ROOT_PASSWORD=my-secret-pw -e GALERA_CLUSTER=galera_cluster -e GALERA_NODE_NAME=node3 -e GALERA_NODE_ADDRESS=node3 mariadb:10.6
In the above commands, adjust the image version, container names, network, and other environment variables according to your requirements.
Verify Cluster Status
Check the cluster status by executing the following command in any of the cluster nodes:
docker exec -it node1 mysql -uroot -pmy-secret-pw -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
This command should display the number of nodes in the cluster
Conclusion
You now have a MariaDB Galera Cluster set up using Docker. You can connect to any of the nodes using the appropriate connection details (e.g., hostname, port, username, password) and start using the cluster.
I hope will this your helpful. Thank you for reading the DevopsRoles page!
I run the 3 above docker commands to create the nodes. However, when I run the 4th docker commands, the output is 0. Even when I change the node name from node1 to node2 to node3, it still returns 0
Hi Jacky,
It seems like you are facing an issue with the cluster size returning 0 even after running the Docker commands. Here are a few troubleshooting steps you can follow:
Correct Container Connection: Ensure that you are connecting to the correct container. Instead of using node1, try using node2 or node3 to see if you get a different result.
docker exec -it node2 mysql -uroot -pmy-secret-pw -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
Wait for Full Cluster Formation: When setting up a cluster, it takes some time for nodes to join and form a complete cluster. Make sure you have waited long enough (e.g., 1-2 minutes) before rechecking.
Check Logs: Check the logs of each container for any error messages. Use the following command to check the logs of node1:
docker logs node1
Replace node1 with the names of other nodes to check their logs.
Verify Cluster Configuration: Ensure that all nodes are using the same network (galera_network) and that environment variables like GALERA_CLUSTER, GALERA_NODE_NAME, and GALERA_NODE_ADDRESS are set correctly.
If the issue persists after checking these points, please provide more information about any specific errors you encounter so that we can offer more detailed assistance.
Good luck!
Made everyting like in your tutorial but having the same issue like previous commentor can you pls reach out to tell what can be wrong.
Hello,
I have create 3 nodes
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7b5cf1085237 mariadb “docker-entrypoint.s…” 3 minutes ago Up 3 minutes 3306/tcp node3
7b73ce28092d mariadb “docker-entrypoint.s…” 5 minutes ago Up 5 minutes 3306/tcp node2
7738e86d6bfd mariadb “docker-entrypoint.s…” 7 minutes ago Up 7 minutes 3306/tcp node1
and i have always this error :
docker exec -it node1 mysql -uroot -pmy-secret-pw -e “SHOW STATUS LIKE ‘wsrep_cluster_size'”
OCI runtime exec failed: exec failed: unable to start container process: exec: “mysql”: executable file not found in $PATH: unknown
BR Denis
Hello Denis,
The error you are encountering (executable file not found in $PATH) usually occurs because the mysql client is not installed inside the container or the container does not include it by default.
Here are some steps to troubleshoot and resolve the issue:
Check if the MySQL client is available in your MariaDB image: Some MariaDB Docker images may not include the mysql client. You can verify this by accessing the container shell and checking:
Then, try running:
If the command is not recognized, it confirms the mysql client is missing.
Install the MySQL client inside the container: If the mysql client is missing, you can install it. Here’s how:
(The above command assumes the container uses Alpine Linux. If it uses a different base OS, use the appropriate package manager, such as apt for Debian-based images or yum for CentOS.)
Re-run your command: After ensuring the mysql client is installed, try running your original command again:
Verify the MariaDB version: If you are using a custom MariaDB Docker image, ensure it is compatible with the Galera Cluster setup. Some images may require additional configuration.
Let me know if the issue persists, and I’ll be happy to assist further.
Best regards,
HuuPV