1.计划用两台host来部署,分别部署一台 mysql,一主一从,
2.配置好主从mysql配置文件,更改文件名即可
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
log-bin = mysql-bin
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
主与从server-id = 1 修改为server-id = 2
3.启动 mysql 容器,两个主机的容器都要启动,端口分别为3306,3307
docker run -d -e MYSQL_ROOT_PASSWORD=123456 --name mysql-master -v /root/docker-mysql-data/mysql-master:/var/lib/mysql -v /root/docker-mysql-data/my-master.cnf:/etc/mysql/my.cnf -p 3306:3306 mysql:5.6
测试:mysql -uroot -p123456 -h127.0.0.1登录本机的mysql容器内
4.进入主mysql 容器
创建一个用户,并授予权限,replication slave ,
grant replication slave on *.* to ‘slave’@’%’ identified by ‘123456’; flush privileges;
show master status;
5. 从mysql容器配置
change master to master_host='172.17.0.2',master_user='slave',master_password='slave',
master_log_file='mysql-bin.000004',master_log_pos=1160,master_port=3306;
mysql> start slave;
mysql> show slave status \G;
相关文章
- 08-10Ubuntu 16.04下使用docker部署MySQL主从复制
- 08-10使用docker部署mysql主从复制集群
- 08-101.Mysql集群------Docker下的Mysql主从复制
- 08-10docker 容器模式下部署mysql 主从复制
- 08-10CentOS双机中Docker下安装Mysql并配置互为主从模式
- 08-10Nginx+Docker部署模式下 asp.net core 获取真实的客户端ip
- 08-10Docker Compose部署项目到容器-基于Tomcat和mysql的项目yml配置文件代码
- 08-10在windows下使用jenkins部署docker容器
- 08-10win10 docker部署mysql容器
- 08-10centos 7.5 使用docker-compose部署mysql7.5后如何登录容器中操作mysql