images\cherry_red.png1 Docker的学习-gaogaoTwo
      images\cherry_blue.png1.1 docker常见问题故障
         images\cherry_orange.png1.1.1 docker容器无法远程连接MySQL
      images\cherry_blue.png1.2 Docker基础命令
         images\cherry_orange.png1.2.1 docker logs
         images\cherry_orange.png1.2.2 镜像构建优化
         images\cherry_orange.png1.2.3 network
         images\cherry_orange.png1.2.4 内部安装应用命令
         images\cherry_orange.png1.2.5 docker ps
      images\cherry_blue.png1.3 Docker网络模式
      images\cherry_blue.png1.4 docker compose
         images\cherry_orange.png1.4.1 docker-compose安装
      images\cherry_blue.png1.5 部署Tomcat 运行环境
      images\cherry_blue.png1.6 docker(compose) LNMP环境的部署
      images\cherry_blue.png1.7 docker 搭建部署Redis集群
      images\cherry_blue.png1.8 docker 搭建部署MongoDB集群
         images\cherry_orange.png1.8.1 MongoDB(configsvr)配置服务器
         images\cherry_orange.png1.8.2 MongoDB(shared) 分片初始化操作
         images\cherry_orange.png1.8.3 配置MongoDB(Mongos)路由服务器
         images\cherry_orange.png1.8.4 MongoDB测试集群可用性
      images\cherry_blue.png1.9 docker 搭建部署MySQL主从复用
      images\cherry_blue.png1.10 docker+Keepalived+Nginx高可用
      images\cherry_blue.png1.11 docker+Ansible多节点集群管理
      images\cherry_blue.png1.12 docker(compose)+Zabbix 多节点监控服务
      images\cherry_blue.png1.13 docker 部署文件目录下载
      images\cherry_blue.png1.14 docker
         images\cherry_orange.png1.14.1 docker镜像管理
         images\cherry_orange.png1.14.2 docker容器
         images\cherry_orange.png1.14.3 docker容器高级操作
1,
启动容器MySQL

Master(主)容器

docker run -p 3310:3306 --name mysql-master -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

Slave(从) 容器

docker run -p 3311:3306 --name mysql-child -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

images\12-1.png


2,
以交互的形式进入容器

docker exec -it mysql-master /bin/bash

apt-get update 更新安装包
apt-get install vim 安装vim

vim /etc/mysql/my.cnf (修改配置文件)

主节点配置
images\12-2.png

cat >> /etc/mysql/my.cnf <<EOF
[mysqld]
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysqld.sock
datadir=/var/lib/mysql
secure-file-priv=NULL
server-id=100
log-bin=mysql-bin
EOF

从节点配置
images\12-3.png


cat >>/etc/mysql/my.cnf <<EOF
[mysqld]
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysqld.sock
datadir=/var/lib/mysql
secure-file-priv=NULL
server-id=101
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
EOF

exit

退出重启MySQL容器
docker stop mysql-master
docker start mysql-master



docker stop mysql-child
docker start mysql-child

并且重新进入容器

mysql -uroot -p123456
images\12-4.png


create user 'slave'@'%' identified by '123456';
grant replication slave,replication client on *.* to 'slave'@'%';

images\12-5.png

images\12-6.png



登录从服务容器

docker exec -it mysql-child /bin/bash
mysql -uroot -p123456


change master to master_host='[Master ip]', master_user='[授权的用户名]', master_password='123456', master_port=3306, master_log_file='[注意了主Bin-log日志文件 File]', master_log_pos= [Position号], master_connect_retry=30;

注意需要依依对应 !!
master_host Master节点ip
master_user Master 授权使用的用户名
master_password Master 密码端口号
master_port 端口号
master_log_file 注意了主Bin-log日志文件 File
master_log_pos Position号

否则可能会出现

Got fatal error 1236 from master when reading data from binary log: 'Could not open log file'

解决方案:

主节点
flush logs;
show master status;
images\12-7.png


从节点 首先
1.stop slave;
2.change master to master_log_file='【Master bin log 日志】' . master_log_pos=【Position号】;
3.start slave;
images\12-8.png



启动成功