docker-swarm部署mysql主从集群的 Compose 模板
时间: 2023-12-04 16:20:24 浏览: 253
可以直接回答,我这里有一个示例的 Compose 模板,可以参考:
version: '3.7'
services:
master:
image: mysql:5.7
command: mysqld --server-id=1 --log-bin=/var/log/mysql/mysql-bin.log --binlog-do-db=mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root123
volumes:
- mysql-data:/var/lib/mysql
deploy:
replicas: 1
placement:
constraints: [node.role == manager]
slave:
image: mysql:5.7
command: mysqld --server-id=2 --log-bin=/var/log/mysql/mysql-bin.log --binlog-do-db=mysql --relay-log=/var/log/mysql/mysql-relay-bin.log --relay-log-info-file=/var/log/mysql/relay-log.info --log-slave-updates
restart: always
environment:
MYSQL_ROOT_PASSWORD: root123
MYSQL_MASTER_HOST: master
MYSQL_MASTER_PORT: '3306'
MYSQL_MASTER_USER: root
MYSQL_MASTER_PASSWORD: root123
volumes:
- mysql-data:/var/lib/mysql
deploy:
replicas: 2
placement:
constraints: [node.role != manager]
volumes:
mysql-data:
阅读全文