文件目录结构
关于每个配置项及docker-compose的安装,大家可以自己查
mysql配置文件
master --- my.cnf
[mysqld]
server_id = 1
gtid-mode = ON
enforce-gtid-consistency = 1
binlog-ignore-db = mysql
log-bin = mysql-bin
binlog_cache_size = 1M
binlog_format = mixed
expire_logs_days = 7
slave_skip_errors = 1062
log_slave_updates = ON
slave1 --- my.cnf
[mysqld]
server_id = 2
gtid-mode = ON
enforce-gtid-consistency = 1
binlog-ignore-db = mysql
log-bin = mysql-slave1-bin
binlog_cache_size = 1M
binlog_format = mixed
expire_logs_days = 7
slave_skip_errors = 1062
relay_log = mysql-relay-bin
log_slave_updates = ON
read_only = 1
slave1 --- my.cnf
[mysqld]
server_id = 3
gtid-mode = ON
enforce-gtid-consistency = 1
binlog-ignore-db = mysql
log-bin = mysql-slave1-bin
binlog_cache_size = 1M
binlog_format = mixed
expire_logs_days = 7
slave_skip_errors = 1062
relay_log = mysql-relay-bin
log_slave_updates = ON
read_only = 1
redis配置文件
master --- redis.conf
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
docker
Dockerfile
Dockerfiles --- Dockerfile-Spring-boot
FROM openjdk:8
WORKDIR /app
COPY ./jars/fmovies-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
docker-compose.yaml
docker-compose.yaml
version: '3'
networks:
miouo-fmovies-network:
driver: bridge
services:
springboot-app:
networks:
- miouo-fmovies-network
build:
context: .
dockerfile: ./Dockerfiles/Dockerfile-Spring-Boot
image: miouo-fmovies:0.0.1
container_name: miouo-fmovies-0.0.1
ports:
- "8080:8080"
depends_on:
- mysql-master
- mysql-slave-1
- mysql-slave-2
- redis-master-1
mysql-master:
container_name: miouo-mysql5.7-master
hostname: mysql-master
image: "mysql:5.7"
ports:
- "33070:3306"
networks:
- miouo-fmovies-network
volumes:
- ./db/mysql/master/etc:/etc/mysql
- ./db/mysql/master/var/lib:/var/lib/mysql
- ./db/mysql/master/my.cnf:/etc/my.cnf
- ./db/mysql/master/init_db:/docker-entrypoint-initdb.d/
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: fmovies
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
mysql-slave-1:
container_name: miouo-mysql5.7-slave-1
hostname: mysql-slave-1
image: "mysql:5.7"
ports:
- "33071:3306"
networks:
- miouo-fmovies-network
volumes:
- ./db/mysql/slave1/etc:/etc/mysql
- ./db/mysql/slave1/var/lib:/var/lib/mysql
- ./db/mysql/slave1/my.cnf:/etc/my.cnf
- ./db/mysql/slave1/init_db:/docker-entrypoint-initdb.d/
environment:
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123456
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
mysql-slave-2:
container_name: miouo-mysql5.7-slave-2
hostname: mysql-slave-2
image: "mysql:5.7"
ports:
- "33072:3306"
networks:
- miouo-fmovies-network
volumes:
- ./db/mysql/slave2/etc:/etc/mysql
- ./db/mysql/slave2/var/lib:/var/lib/mysql
- ./db/mysql/slave2/my.cnf:/etc/my.cnf
- ./db/mysql/slave2/init_db:/docker-entrypoint-initdb.d/
environment:
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123456
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
redis-master-1:
image: redis:7.2.4
container_name: miouo-redis7.2.4-master-1
restart: always
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
ports:
- 6379:6379
volumes:
- ./db/redis/master/data:/data
- ./db/redis/master/redis.conf:/usr/local/etc/redis/redis.conf
networks:
- miouo-fmovies-network
编排
命令行
docker-compose up -d