db01
docker load -i mysql57.tar
db01
docker run --net=host --name db01 -v /data1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
docker cp db01:/etc/mysql/mysql.conf.d/mysqld.cnf /tmp/mysqld_1.cnf
vi /tmp/mysqld_1.cnf #编辑添加以下
server-id = 101
log-bin = mysql-bin
max_connections = 1000
gtid_mode = on
enforce_gtid_consistency = 1
auto_increment_offset = 1
auto_increment_increment = 2
docker cp /tmp/mysqld_1.cnf db01:/etc/mysql/mysql.conf.d/mysqld.cnf
docker restart db01
db02
docker load -i mysql57.tar
docker run --net=host --name db02 -v /data2:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
docker cp db02:/etc/mysql/mysql.conf.d/mysqld.cnf /tmp/mysqld_2.cnf
vi /tmp/mysqld_2.cnf
server-id = 102log-bin = mysql-bin
max_connections = 1000gtid_mode = on
enforce_gtid_consistency = 1
auto_increment_offset = 2
auto_increment_increment =2
docker cp /tmp/mysqld_2.cnf db02:/etc/mysql/mysql.conf.d/mysqld.cnf
docker restart db02
连接db01
docker exec -it db01 bash
mysql -uroot -P 3301 -p123456
grant replication slave on *.* to 'rep'@'%' identified by '123456';
连接db02
docker exec -it db02 bash
mysql -uroot -P 3301 -p123456
grant replication slave on *.* to 'rep'@'%' identified by '123456';
在db01上
change master to master_host='192.168.40.217',master_port=3306,master_user='rep',master_password='123456',MASTER_AUTO_POSITION=1;
start slave;
show slave statusG
在db02上
change master to master_host='192.168.40.216',master_port=3306,master_user='rep',master_password='123456',MASTER_AUTO_POSITION=1;
start slave;
show slave statusG
检查状态
检查状态
Slave_IO_Running和Slave_SQL_Running 两个值都为YES,说明复制状态正常
Seconds_Behind_Master 为0,说明没有同步延迟
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
在db01 db02 创建远程连接用户
dacs
grant all on *.* to dacs@'%' identified by '123456' with grant option;
导入数据
mysql -h127.0.0.1 -udacs -p123456 < server.sql
mysql -h127.0.0.1 -udacs -p123456 < server_V1.0.9.sql
mysql -h127.0.0.1 -udacs -p123456 < server_V1.1.0.sql
mysql -h127.0.0.1 -udacs -p123456 < data.sql
mysql -h127.0.0.1 -udacs -p123456 < data_V1.0.9.sql
本文摘自 :https://blog.51cto.com/u