搭建主备MySQL
拉取镜像
docker pull mysql:5.7
创建主备容器
docker run -itd --name mysql-master --cpu-period=1000000 --cpu-quota=500000 --memory 512M --rm -e MYSQL_ROOT_PASSWORD=root mysql:5.7
docker run -itd --name mysql-slave --cpu-period=1000000 --cpu-quota=500000 --memory 512M --rm -e MYSQL_ROOT_PASSWORD=root mysql:5.7
安装vim命令
docker exec -it mysql-master yum install -y vim
docker exec -it mysql-slave yum install -y vim
修改主库配置文件
docker exec -it mysql-master vim /etc/mysql/conf.d/my.cnf
[mysqld]
server-id=1
log-bin=mysql-bin
增加同步用户repl
docker exec -it mysql-master mysql -h localhost -u root -proot
CREATE USER 'repl'@'%' identified by '123456';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
docker restart mysql-master
修改备库配置文件
docker exec -it mysql-slave vim /etc/mysql/conf.d/my.cnf
[mysqld]
server-id=2
启动slave
docker restart mysql-slave
docker exec -it mysql-slave mysql -h localhost -u root -proot
CHANGE MASTER TO MASTER_HOST='172.17.0.2', MASTER_PORT=3306,MASTER_USER='repl',MASTER_PASSWORD='123456';
start slave;
参考资料