Update async replication example

This commit is contained in:
Anel Husakovic 2023-11-27 13:20:15 +01:00 committed by Daniel Black
parent 54a8a7fb16
commit 0186989bcc
2 changed files with 55 additions and 23 deletions

6
examples/.env Normal file
View File

@ -0,0 +1,6 @@
MARIADB_ROOT_PASSWORD=secret
MARIADB_REPLICATION_USER=repl
MARIADB_REPLICATION_PASSWORD=replicationpass
PRIMARY_name='mariadb-primary'
REPLICATION_name_1='mariadb-replica-1'
REPLICATION_name_2='mariadb-replica-2'

View File

@ -1,29 +1,22 @@
version: "3" version: "3"
services: x-common-variables: &common-variables
master: MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
image: mariadb:latest MARIADB_REPLICATION_USER: ${MARIADB_REPLICATION_USER}
command: --log-bin --log-basename=mariadb MARIADB_REPLICATION_PASSWORD: ${MARIADB_REPLICATION_PASSWORD}
environment:
- MARIADB_ROOT_PASSWORD=password x-common-attributes: &common-attributes
- MARIADB_USER=testuser env_file:
- MARIADB_PASSWORD=password - .env
- MARIADB_DATABASE=testdb image: mariadb:lts
- MARIADB_REPLICATION_USER=repl environment: *common-variables
- MARIADB_REPLICATION_PASSWORD=replicationpass
healthcheck: healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
interval: 10s interval: 10s
timeout: 5s timeout: 5s
retries: 3 retries: 3
replica:
image: mariadb:latest x-common-replication: &common-replication
command: --server-id=2 --log-basename=mariadb
environment:
- MARIADB_ROOT_PASSWORD=password
- MARIADB_MASTER_HOST=master
- MARIADB_REPLICATION_USER=repl
- MARIADB_REPLICATION_PASSWORD=replicationpass
- MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR
healthcheck: healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--replication_io", "--replication_sql", "--replication_seconds_behind_master=1", "--replication"] test: ["CMD", "healthcheck.sh", "--connect", "--replication_io", "--replication_sql", "--replication_seconds_behind_master=1", "--replication"]
interval: 10s interval: 10s
@ -32,3 +25,36 @@ services:
depends_on: depends_on:
master: master:
condition: service_healthy condition: service_healthy
services:
master:
<<: *common-attributes
container_name: ${PRIMARY_name}
command: --log-bin --log-basename=mariadb
environment:
- MARIADB_USER=testuser
- MARIADB_PASSWORD=password
- MARIADB_DATABASE=testdb
replica1:
<<:
- *common-attributes
- *common-replication
container_name: ${REPLICATION_name_1}
command: --server-id=2 --log-basename=mariadb
environment:
- MARIADB_MASTER_HOST=${PRIMARY_name}
- MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR
replica2:
<<:
- *common-attributes
- *common-replication
container_name: ${REPLICATION_name_2}
command: --server-id=3 --log-basename=mariadb
environment:
- MARIADB_MASTER_HOST=${PRIMARY_name}
- MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR
networks:
backend: