This patch add support for Galera replication.
Features:
- It detects if Galera replication was enabled wsrep_on=ON
- By default it enables cluster auto bootstrap feature
- By default the first cluster node is used for cluster auto bootstrapping
based on the wsrep_cluster_address parameter or by setting the
`WSREP_CLUSTER_ADDRESS` environment variable
- cluster auto bootstrap feature can be disabled by setting the
`WSREP_SKIP_AUTO_BOOTSTRAP` environment variable
- use the `WSREP_AUTO_BOOTSTRAP_ADDRESS` environment variable to explicitly
choice other node for cluster bootstrapping
- cluster node hostnames or IP addresses must be valid to enable cluster
auto bootstrapping
How to use it.
1. Prepare MariaDB configuration file `galera.cnf`:
```plaintext
[galera]
wsrep_on = ON
wsrep_sst_method = mariabackup
wsrep_provider = /usr/lib/libgalera_smm.so
binlog_format = row
default_storage_engine = InnoDB
innodb_doublewrite = 1
innodb_autoinc_lock_mode = 2
```
2. Make it read-only:
```plaintext
chmod 444 galera.cnf
```
3. Prepare Docker Compose file `docker-compose.yml`:
```yaml
services:
node:
image: mariadb
restart: always
security_opt:
- label=disable
environment:
WSREP_CLUSTER_ADDRESS: "${WSREP_CLUSTER_ADDRESS:-}"
MARIADB_ROOT_PASSWORD: example
volumes:
- ./galera.cnf:/etc/mysql/conf.d/10-galera.cnf:ro
command:
- --wsrep-cluster-address=gcomm://db_node_1,db_node_2,db_node_3
deploy:
replicas: 3
```
4. Start Docker Compose:
```plaintext
docker-compose --project-name db up
```
To start N MariaDB instances using environment variable:
```plaintext
WSREP_CLUSTER_ADDRESS="gcomm://db_node_1,db_node_2,db_node_3,db_node_4,db_node_5"
docker-compose --project-name db up --scale node="$(echo "${WSREP_CLUSTER_ADDRESS}" | tr ',' ' ' | wc -w)"
```
To start N MariaDB instances using MariaDB configuration file:
```plaintext
docker-compose --project-name db up --scale node="$(grep -i wsrep_cluster_address <name>.cnf | tr -d ' ' | tr ',' ' ' | wc -w)"
```
Closes: MariaDB#28