Skip to content

MariaDB Galera multi-master database cluster install script

Notifications You must be signed in to change notification settings

valecloud/MariaDB-Galera-cluster

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 

Repository files navigation

MariaDB-Galera-cluster

MariaDB Galera multi-master database cluster install script

Install

#init the swarm:
root@node1:/# docker swarm init

#generate manager token and copy the token to the node2 and node3
root@node1:/# docker swarm join-token manager
To add a manager to this swarm, run the following command:
   docker swarm join --token SWMTKN-1-0fo48mwadacjoz01iqnqnv9qiqkjh9ipzhct6ip2f63pagrk5o-36ybigvk9mkfoag1ph266o4x4 192.168.0.1:2377

#Join the node2 and node3 to the swarm
root@node1:/# docker swarm join --token SWMTKN-1-0fo48mwadacjoz01iqnqnv9qiqkjh9ipzhct6ip2f63pagrk5o-36ybigvk9mkfoag1ph266o4x4 192.168.0.1:2377

root@node2:/# docker swarm join --token SWMTKN-1-0fo48mwadacjoz01iqnqnv9qiqkjh9ipzhct6ip2f63pagrk5o-36ybigvk9mkfoag1ph266o4x4 192.168.0.1:2377

#check the results:
root@node1:/# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
egl8tjxb8kcwlppolmnu43tj8 *   node1               Ready               Active              Reachable           19.03.8
gkyht0zioff010q3n7v5wpmke     node2               Ready               Active              Reachable           19.03.8
j56c5kig56714zbbbk0rbc7aj     node3               Ready               Active              Leader              19.03.8


curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
  • Clone the reposity to each node.
#create a new folder
mkdir /cluster && cd /cluster
#download the reposity
curl -L "https://raw.githubusercontent.com/simonyipeter/MariaDB-Galera-cluster/master/wsrep_service.sh" -o wsrep_service.sh && chmod +x wsrep_service.sh

Configuration

  • Edit the wsrep_service.sh file with your best text editor:
mcedit wsrep_service.sh
  • Modify the GALERA_DATA_ROOT_FOLDER variable, the cluster will store database files here. GALERA_DB will be the first database in the cluster and the password and the root password will be stored in the GALERA_PWD variable.

  • Start the first container on any node, it will initial the cluster. the container name will mariadb-galera-0 Each container will use this ports: 3306/tcp 4444/tcp and 4567-4568/tcp, so before start container, stop the mysql server on the host or modify the port number in the wsrep_service.sh Example: -p 3306:3306 -> -p 3307:3306

root@node1:/cluster# ./wsrep_service.sh bootstrap
  • On the next node clone the reposity and join to the cluster, mariadb-galera-2 will be the container name which joint to the mariadb-galera-0
root@node2:/cluster# ./wsrep_service.sh start 2 0
# and the next node join to mariadb-galera-2
root@node3:/cluster# ./wsrep_service.sh start 3 2
  • Check the cluster state on any node:
root@node2:/cluster# ./wsrep_service.sh status
+---------------------------+----------------+
| VARIABLE_NAME             | VARIABLE_VALUE |
+---------------------------+----------------+
| WSREP_CLUSTER_SIZE        | 3              |
| WSREP_CLUSTER_STATUS      | Primary        |
| WSREP_EVS_DELAYED         |                |
| WSREP_LOCAL_STATE_COMMENT | Synced         |
| WSREP_READY               | ON             |
+---------------------------+----------------+

  • Let's destroy and the first container on node1 and create a new one:
root@node1:/cluster# ./wsrep_service.sh stop
root@node1:/cluster# ./wsrep_service.sh start 1 2
#After a few seconds, check again the status:
root@node1:/cluster# ./wsrep_service.sh status

Backup

Easy to create backup from all databases:

root@node1:/cluster# ./wsrep_service.sh backup

The backup files will be located in the db_bkp folder

About

MariaDB Galera multi-master database cluster install script

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%