This commit is contained in:
Benjamin Toby
2025-02-16 17:12:40 +01:00
parent e9761cc971
commit e95f4d1087
628 changed files with 3091 additions and 1073 deletions
+12
View File
@@ -0,0 +1,12 @@
FROM mariadb:11-jammy
RUN apt update
RUN apt install -y curl wget zip unzip xz-utils galera-4
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
COPY .bash_history /root/.bash_history
ENTRYPOINT ["entrypoint.sh"]
CMD [ "mariadbd" ]
@@ -0,0 +1,45 @@
name: galera
services:
mariadb-node1:
build:
context: .
dockerfile: Dockerfile
networks:
galera:
container_name: mariadb-node1
environment:
- MARIADB_ROOT_PASSWORD=password
volumes:
- ./conf.d/node1.cnf:/etc/mysql/conf.d/galera.cnf
- ./db:/var/lib/mysql
mariadb-node2:
build:
context: .
dockerfile: Dockerfile
container_name: mariadb-node2
networks:
galera:
environment:
- MARIADB_ROOT_PASSWORD=password
volumes:
- ./conf.d/node2.cnf:/etc/mysql/conf.d/galera.cnf
command: ["mariadbd"]
mariadb-node3:
build:
context: .
dockerfile: Dockerfile
container_name: mariadb-node3
networks:
galera:
environment:
- MARIADB_ROOT_PASSWORD=password
volumes:
- ./conf.d/node3.cnf:/etc/mysql/conf.d/galera.cnf
command: ["mariadbd"]
networks:
galera:
driver: bridge
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
# Path to the grastate.dat file
GRSTATE_FILE="/var/lib/mysql/grastate.dat"
# Check if the MARIADB_SLAVE environment variable is set
if [ ! -z "$MARIADB_SLAVE" ]; then
# If MARIADB_SLAVE is set, this node is a slave, so just run mariadbd (no --wsrep-new-cluster)
echo "MARIADB_SLAVE environment variable is set. Starting as a slave node."
exec mariadbd "$@"
else
# If grastate.dat exists, check if the cluster has already been bootstrapped
if [ -f "$GRSTATE_FILE" ]; then
# Read the value of safe_to_bootstrap from grastate.dat
SAFE_TO_BOOTSTRAP=$(grep -E "^safe_to_bootstrap" "$GRSTATE_FILE" | cut -d ':' -f 2 | tr -d ' ')
if [ "$SAFE_TO_BOOTSTRAP" == "1" ]; then
# Cluster is already bootstrapped, so start mariadbd without --wsrep-new-cluster
echo "Cluster is already bootstrapped. Starting mariadbd without --wsrep-new-cluster."
exec mariadbd "$@"
else
# Cluster is not bootstrapped, so run mariadbd with --wsrep-new-cluster
echo "Cluster is not bootstrapped. Bootstrapping the cluster."
exec mariadbd --wsrep-new-cluster "$@"
fi
else
# If grastate.dat doesn't exist, assume it's a new cluster and bootstrap it
echo "grastate.dat not found. Bootstrapping the cluster."
exec mariadbd --wsrep-new-cluster "$@"
fi
fi