当前位置:网站首页>基于Docker构建MySQL主从复制数据库
基于Docker构建MySQL主从复制数据库
2022-08-09 19:27:00 【绝域时空】
0.前言
本次带来的是基于Docker-compose构建出MySQL单节点和主从复制的MySQL环境,本次使用的依旧是bitnami的第三方镜像资源。希望通过这个文章对于学习和使用Docker搭建MySQL的你提供帮助。
1.Docker构建单节点MySQL服务
1.1Docker-compose构建出MySQL节点服务
下面提供基于Docker-Compose 构建出单节点的MySQL服务的yml文件:
version: '2.1'
services:
mysql:
image: docker.io/bitnami/mysql:8.0
ports:
- '3306:3306'
volumes:
- 'mysql_data:/bitnami/mysql/data'
environment:
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
healthcheck:
test: ['CMD', '/opt/bitnami/scripts/mysql/healthcheck.sh']
interval: 15s
timeout: 5s
retries: 6
volumes:
mysql_data:
driver: local
1.2 配置信息
- MYSQL_ROOT_USER:数据库管理员用户。缺省值为 。root
- MYSQL_ROOT_PASSWORD:数据库管理员用户密码。无默认值。
2.Docker-compose 构建MySQL主从复制集群
2.1 Docker-compose构建
下面是Docker-Compose构建MySQL主从复制集群的yml配置文件
version: '2.1'
services:
mysql-master:
image: docker.io/bitnami/mysql:8.0
ports:
- '3306'
volumes:
- 'mysql_master_data:/bitnami/mysql/data'
environment:
- MYSQL_REPLICATION_MODE=master
- MYSQL_REPLICATION_USER=repl_user
- MYSQL_USER=my_user
- MYSQL_DATABASE=my_database
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
- MYSQL_ROOT_PASSWORD=my_root_password
healthcheck:
test: ['CMD', '/opt/bitnami/scripts/mysql/healthcheck.sh']
interval: 15s
timeout: 5s
retries: 6
mysql-slave:
image: docker.io/bitnami/mysql:8.0
ports:
- '3306'
depends_on:
- mysql-master
environment:
- MYSQL_REPLICATION_MODE=slave
- MYSQL_REPLICATION_USER=repl_user
- MYSQL_USER=my_user
- MYSQL_DATABASE=my_database
- MYSQL_MASTER_HOST=mysql-master
- MYSQL_MASTER_PORT_NUMBER=3306
- MYSQL_MASTER_ROOT_PASSWORD=my_root_password
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
healthcheck:
test: ['CMD', '/opt/bitnami/scripts/mysql/healthcheck.sh']
interval: 15s
timeout: 5s
retries: 6
volumes:
mysql_master_data:
driver: local
2.2 配置信息
下面是基于Docker-Compose构建MySQL主从复制的一些环境变量的配置信息:
- MYSQL_REPLICATION_MODE:复制模式。可能的值 /。无默认值。masterslave
- MYSQL_REPLICATION_USER:首次运行时在主服务器上创建的复制用户。无默认值。
- MYSQL_REPLICATION_PASSWORD:复制用户密码。无默认值。
- MYSQL_MASTER_HOST:复制主站(从属参数)的主机名/IP。无默认值。
- MYSQL_MASTER_PORT_NUMBER:复制主服务器的服务器端口(从属参数)。缺省值为 。3306
- MYSQL_MASTER_ROOT_USER:复制主服务器上有权访问 (从属参数) 的用户。默认值为MYSQL_DATABASE=root
- MYSQL_MASTER_ROOT_PASSWORD:复制主服务器上有权访问(从属参数)的用户的密码。无默认值。
边栏推荐
猜你喜欢

小满nestjs(第五章 nestjs cli)

DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰二氧化硅颗粒用

3D感知(二):单目3D物体检测

How are data integration APIs key to enterprise digital transformation?

Visual studio 2022 debugging skills introduction

Prometheus Operator 自定义监控添加redis explorer

Win11搜索不到文件的解决方法

字节二面问的MySQL,差点没答好

Access control knowledge

CMake installation upgrade higher version
随机推荐
Redis 大的情况下,key 要如何处理?
WPF中加载并使用图像资源
leetcode二叉搜索树与双向链表
Byte side: Can TCP and UDP use the same port?
UE4_定序器控制蓝图对象
阿里二面:没有 accept,能建立 TCP 连接吗?
laravel报错:TokenMismatchException in VerifyCsrfToken.php line 68:
Week 8 Deep learning for object detection
C语言之实现倒置字符串的两种方法
小满nestjs(第三章 前置知识装饰器)
基于模糊PID控制器的水温控制系统仿真
What are the benefits of enterprise data integration?How do different industries solve the problem of data access?
Simulation of Water Temperature Control System Based on Fuzzy PID Controller
Next second data: the transformation of the modern data stack brought about by the integration of lake and warehouse has begun
Characteristics and Development Prospects of Korea's Cyber Security System
Ali Ermi: Without accept, can a TCP connection be established?
韩国网络安全体系特征与发展前景
OpenSSL SSL_read: Connection was reset, errno 10054
大健康产业商业供应链管理系统数字化提升产业链运作效率推动供应链标准化建设
痛击面试官 CURD系统也能做出技术含量