当前位置:网站首页>基于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:复制主服务器上有权访问(从属参数)的用户的密码。无默认值。
边栏推荐
- SqlServer 2016 安装相关问题
- [Graphic and textual] How to reinstall Win7 system
- Oracle 字段自增
- Acrel5000web能耗系统在某学院的应用-Susie 周
- What are the benefits of enterprise data integration?How do different industries solve the problem of data access?
- Cholesterol-PEG-Thiol, CLS-PEG-SH, Cholesterol-PEG-Sulfhydryl for improved solubility
- 2.3 监督学习-2
- Ali Ermi: Without accept, can a TCP connection be established?
- 【二叉树】树的子结构
- 【Jmeter】分布式搭建
猜你喜欢

鲜花线上销售管理系统的设计与实现

Prometheus Operator 自定义监控添加redis explorer

What are the benefits of enterprise data integration?How do different industries solve the problem of data access?

不经意传输协议OT

使用Mock技术模拟数据

leetcode二叉搜索树与双向链表

Beat the interviewer, the CURD system can also make technical content

Ali Ermi: Without accept, can a TCP connection be established?

DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified silica particles

【kali-密码攻击】(5.1.1)密码在线破解:Hydra(图形界面)
随机推荐
Win11找不到Internet Explore怎么办
source install/setup.bash时出现错误
An overall security understanding and method of cyberspace based on connection and security entropy
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰二氧化硅颗粒用
日期及时间处理包 Carbon 在 Laravel 中的简单使用[通俗易懂]
Definition and Basic Operations of Linear Tables
buuctf(探险2)
安科瑞支持以太网通讯、profibus通讯嵌入式电能表APM指导性技术要求-Susie 周
加工制造业智慧采购系统解决方案:助力企业实现全流程采购一体化协同
安装多版本php(php5.6,php7.2)
MySQL笔记-06 基础SQL操作
laravel 时区问题timezone
Characteristics and Development Prospects of Korea's Cyber Security System
prometheus学习3Grafana部署及基本使用
解决执行Command报错executable file not found in $PATH
2.2 监督学习-1
Ankerui supports Ethernet communication, profibus communication embedded energy meter APM guiding technical requirements-Susie Week
leetcode二叉搜索树与双向链表
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶可减少肽的免疫原性
看完这波 Android 面试题;助你斩获心中 offer