【docker】使用Docker快速体验MySQL半同步复制机制
2020-07-02 本文已影响0人
miniy_7
- 准备工作 docker 拉取安装 docker 镜像
- 配置外部conf 文件
- 编辑主库配置
# 编辑
vi docker/mysql/master/conf/my.cnf
#内容
[mysqld]
binlog-format=ROW
log-bin=master-bin
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=1
report-port=3306
report-host=master
plugin_load="rpl_semi_sync_master=semisync_master.so"
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000
- 编辑从库1配置
# 编辑
vi docker/mysql/slave1/conf/my.cnf
#内容
[mysqld]
binlog-format=ROW
log-bin=mysql-bin.log
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=11
report-port=3306
report-host=slave1
plugin_load="rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_slave_enabled=1
- 编辑从库2配置
# 编辑
vi docker/mysql/slave2/conf/my.cnf
#内容
[mysqld]
binlog-format=ROW
log-bin=mysql-bin.log
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=12
report-port=3306
report-host=slave1
plugin_load="rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_slave_enabled=1
- 运行多实例
# 主
docker run -itd -p 3306:3306 -v /docker/mysql/master/conf:/etc/mysql/ --name mysql-master -e MYSQL_ROOT_PASSWORD=123456 mysql
# 从1
docker run -itd -p 3307:3306 -v /docker/mysql/slave1/conf:/etc/mysql/ --name mysql-slave1 -e MYSQL_ROOT_PASSWORD=123456 mysql
# 从2
docker run -itd -p 3308:3306 -v /docker/mysql/slave2/conf:/etc/mysql/ --name mysql-slave2 -e MYSQL_ROOT_PASSWORD=123456 mysql
- 获取三个容器的IP
docker inspect --format '{{.NetworkSettings.IPAddress}}' master slave1 slave2
- 进入主库容器 配置相关账号
- 进入从库开启 slave
> CHANGE MASTER TO MASTER_HOST='172.17.0.100',MASTER_USER='slave',MASTER_PASSWORD='123456', MASTER_AUTO_POSITION=1;
> START SLAVE;
- 查看同步状态
show slave status \G;
- 验证【略】
参考博文
https://cloud.tencent.com/developer/article/1338804
https://www.cnblogs.com/songwenjie/p/9371422.html