Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Added setup for mariadb with replication
Browse files Browse the repository at this point in the history
  • Loading branch information
vardan10 committed Nov 17, 2023
1 parent d29569d commit ec328be
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docker/mariaDB/mysql-healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

mysql -h"$HOSTNAME" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" --silent -e"use $MYSQL_DATABASE"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

# Unique identifying number of the server.
server_id = 1
server-id = 1

# Set binary log file base name.
log_bin=mysql-bin.log
Expand Down
22 changes: 22 additions & 0 deletions docker/mariaDB/read/conf/mysql.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[mysqld]

# Default authentication plugin
default-authentication-plugin=caching_sha2_password

# Default character charset
character-set-server=utf8mb4

# Default collation server
collation-server=utf8mb4_unicode_ci

# Max connections
max_connections=500

# Unique identifying number of the server.
server-id = 2

# Set binary log file base name. This should be identical to the binary log file base name in source.
log_bin=mysql-bin.log

# Set the relay log file base name used by replica. This is needed to avoid error incase hostname is changed in future.
relay_log=mysql-relay-bin.log
21 changes: 21 additions & 0 deletions jenkins/mariadb-with-replication/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONY: clean up down
all: up

compose := docker-compose -f docker-compose.yml

up:
$(compose) up --detach

down:
$(compose) down --volumes --remove-orphans

logs:
$(compose) logs

clean: down

cli-primary:
$(compose) exec mysql-primary mysql -u root -ppassword lisk

cli-replica:
$(compose) exec mysql-read-replica mysql -u root -ppassword lisk
64 changes: 64 additions & 0 deletions jenkins/mariadb-with-replication/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: '3.3'
services:
mysql-primary:
image: mariadb:10.7
container_name: mysql-primary
command: mysqld
volumes:
- ../../docker/mariadb/primary/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- mysql-primary-data:/var/lib/mysql
- ../../docker/mariadb/primary/init:/docker-entrypoint-initdb.d
restart: always
networks:
- services_network
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=lisk
- MYSQL_PASSWORD=password
ports:
- '127.0.0.1:3306:3306'
healthcheck:
test: ['CMD', 'mysqladmin', 'ping', '-hlocalhost', '-ppassword']

mysql-read-replica:
image: mariadb:10.7
depends_on:
mysql-primary:
condition: service_healthy
command: mysqld
volumes:
- ../../docker/mariadb/read/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- ../../docker/mariadb/read/init:/docker-entrypoint-initdb.d
restart: always
expose:
- '3306'
networks:
- services_network
deploy:
mode: replicated
replicas: 1
endpoint_mode: vip
environment:
- MYSQL_ROOT_PASSWORD=password
healthcheck:
test: ['CMD', 'mysqladmin', 'ping', '-hlocalhost', '-ppassword']

mysql-read-replica-haproxy:
image: nginx:latest
depends_on:
mysql-read-replica:
condition: service_healthy
volumes:
- ../../docker/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- '127.0.0.1:3307:3307'
networks:
- services_network
healthcheck:
test: ['CMD', 'service', 'nginx', 'status']

networks:
services_network:

volumes:
mysql-primary-data:
3 changes: 3 additions & 0 deletions jenkins/mariadb-with-replication/mysql-healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

mysql -h"$HOSTNAME" -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" --silent -e"use $MARIADB_DATABASE"
2 changes: 1 addition & 1 deletion jenkins/mariadb/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
image: mariadb:10.7
command: mysqld --max_connections=500
volumes:
- ../../docker/mysql/standalone/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- ../../docker/mariadb/primary/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- db-data:/var/lib/mysql
- ./mysql-healthcheck.sh:/healthcheck.sh
restart: always
Expand Down
4 changes: 2 additions & 2 deletions jenkins/mysql-with-replication/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: mysql:8
container_name: mysql-primary
platform: linux/amd64
command: mysqld --max_connections=500
command: mysqld
volumes:
- ../../docker/mysql/primary/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- mysql-primary-data:/var/lib/mysql
Expand All @@ -27,7 +27,7 @@ services:
mysql-primary:
condition: service_healthy
platform: linux/amd64
command: mysqld --max_connections=500
command: mysqld
volumes:
- ../../docker/mysql/read/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- ../../docker/mysql/read/init:/docker-entrypoint-initdb.d
Expand Down
2 changes: 1 addition & 1 deletion jenkins/mysql/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
platform: linux/amd64
command: mysqld --max_connections=500
volumes:
- ../../docker/mysql/standalone/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- ../../docker/mysql/primary/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
- db-data:/var/lib/mysql
- ./mysql-healthcheck.sh:/healthcheck.sh
restart: always
Expand Down

0 comments on commit ec328be

Please sign in to comment.