Skip to content

Instantly share code, notes, and snippets.

@potikanond
Created January 29, 2021 09:28
Show Gist options
  • Save potikanond/44cf1fb0720e81439f92a7a3e7fc3456 to your computer and use it in GitHub Desktop.
Save potikanond/44cf1fb0720e81439f92a7a3e7fc3456 to your computer and use it in GitHub Desktop.
docker-compose file for Mariadb Cluster deployment using Galera
version: '3.5'
services:
seed:
image: colinmollenhour/mariadb-galera-swarm:10.4.11-2020-01-06
environment:
- XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password
- MYSQL_USER=dpotikan
- MYSQL_PASSWORD_FILE=/run/secrets/mysql_password
- MYSQL_DATABASE=database
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password
- MYSQL_ROOT_HOST=%
- DEFAULT_TIME_ZONE=Asia/Bangkok
- TZ=Asia/Bangkok
- NODE_ADDRESS=^10.0.*.*
networks:
- dbnet
command: seed
volumes:
- mysql-data:/var/lib/mysql
secrets:
- xtrabackup_password
- mysql_password
- mysql_root_password
node:
image: colinmollenhour/mariadb-galera-swarm:10.4.11-2020-01-06
environment:
- XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password
- NODE_ADDRESS=^10.0.*.*
- HEALTHY_WHILE_BOOTING=1
- TZ=Asia/Bangkok
networks:
- dbnet
ports:
- 3306:3306
command: node tasks.seed,tasks.node
volumes:
- mysql-data:/var/lib/mysql
deploy:
replicas: 0
secrets:
- xtrabackup_password
volumes:
mysql-data:
name: '{{.Service.Name}}-{{.Task.Slot}}-data'
driver: local
networks:
dbnet:
driver: overlay
secrets:
xtrabackup_password:
external: true
mysql_password:
external: true
mysql_root_password:
external: true
@dpotikan
Copy link

dpotikan commented Jun 1, 2021

Start MariaDB Cluster node

docker service create --name maria-cluster --network maria-net --replicas=1 --mount type=bind,source=/dir/on/host,destination=/var/lib/mysql --env DB_SERVICE_NAME=maria-cluster --env MYSQL_ROOT_PASSWORD=my_password --env DEFAULT_TIME_ZONE=Asia/Bangkok --env TZ=Asia/Bangkok toughiq/mariadb-cluster

Scale up the number of cluster node to 3

# docker service scale maria-cluster=3

Run Maxscale as MariaDB load-balancer

# docker service create --name maria-lb --network maria-net --env DB_SERVICE_NAME=maria-cluster --env ENABLE_ROOT_USER=1 --env DEFAULT_TIME_ZONE=Asia/Bangkok --env TZ=Asia/Bangkok --publish 3306:3306 toughiq/maxscale

Check MariaDB Cluster & Maxscale status

# docker exec -it maxscale.<SLOT>.<ID> maxadmin -pmariadb list servers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment