> Deploy MySQL 5.7 cluster master & slave (for testing only) Image version 5.7 1. Create an overlay network docker network create --driver overlay common-network --attachable 2. Edit two configuration files master.cnf and slave.cnf !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ [mysqld] log-bin=mysql-bin server-id=1 gtid-mode=ON enforce-gtid-consistency=ON !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ [mysqld] server-id=2 gtid-mode=ON enforce-gtid-consistency=ON 3. Start 2 MYSQL: mysql-master, mysql-slave docker run -d \ --name mysql-master \ --network common-network \ -e MYSQL_ROOT_PASSWORD=Passw0rd \ -v `pwd`/master.cnf:/etc/mysql/my.cnf \ -p 3306:3306 \ -d mysql:5.7 docker run -d \ --name mysql-slave \ --network common-network \ -e MYSQL_ROOT_PASSWORD=Passw0rd \ -v `pwd`/slave.cnf:/etc/mysql/my.cnf \ -p 3307:3306 \ -d mysql:5.7 4. Add users from the library for replication docker run -it --rm --network common-network mysql mysql -hmysql-master -uroot -pPassw0rd \ -e "CREATE USER 'repl'@'%' IDENTIFIED BY 'password' REQUIRE SSL; " \ -e "GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';" 5. Connect master & slave docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -pPassw0rd \ -e "CHANGE MASTER TO MASTER_HOST='mysql-master', MASTER_PORT=3306, MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_AUTO_POSITION=1, MASTER_SSL=1;" \ -e "START SLAVE;" 6. Verify slave status docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -pPassw0rd -e "show slave status\G" The following status is normal: Slave_IO_Running: Yes Slave_SQL_Running: Yes > Deploy MySQL 8.0 cluster master & slave (for testing only) Mirror version mysql:8.0 1. Create an overlay network docker network create --driver overlay common-network --attachable 2. Start 2 MYSQL: mysql-master, mysql-slave docker run -d \ --name mysql-master \ --network common-network \ -e MYSQL_ROOT_PASSWORD=Passw0rd \ -p 3306:3306 \ -d mysql --default-authentication-plugin=mysql_native_password docker run -d \ --name mysql-slave \ --network common-network \ -e MYSQL_ROOT_PASSWORD=Passw0rd \ -p 3307:3306 \ -d mysql --default-authentication-plugin=mysql_native_password 3. Configure master & slave docker run -it --rm --network common-network mysql mysql -hmysql-master -uroot -pPassw0rd \ -e "SET PERSIST server_id=1;" \ -e "SET PERSIST_ONLY gtid_mode=ON;" \ -e "SET PERSIST_ONLY enforce_gtid_consistency=true; " \ -e "CREATE USER 'repl'@'%' IDENTIFIED BY 'password' REQUIRE SSL; " \ -e "GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';" docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -pPassw0rd \ -e "SET PERSIST server_id=2;" \ -e "SET PERSIST_ONLY gtid_mode=ON;" \ -e "SET PERSIST_ONLY enforce_gtid_consistency=true; " 4. Restart master & slave docker restart mysql-master mysql-slave 5. Connect master & slave docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -pPassw0rd \ -e "CHANGE MASTER TO MASTER_HOST='mysql-master', MASTER_PORT=3306, MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_AUTO_POSITION=1, MASTER_SSL=1;" \ -e "START SLAVE;" 6. Verify slave status docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -pPassw0rd -e "show slave status\G" The following status is normal: Slave_IO_Running: Yes Slave_SQL_Running: Yes > Verify data synchronization Create database anoyi on master docker run -it --rm --network common-network mysql mysql -hmysql-master -uroot -pPassw0rd \ -e "create database anoyi default character set utf8mb4 collate utf8mb4_general_ci;" View the database list on the slave docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -pPassw0rd \ -e "show databases;" mysql: [Warning] Using a password on the command line interface can be insecure. +--------------------+ | Database | +--------------------+ |anoyi | | information_schema | |mysql | | performance_schema | |sys| +--------------------+ Related information: MySQL 5.7: https://dev.mysql.com/doc/refman/5.7/en/replication.html The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of JavaScript data types
>>: The simplest MySQL data backup and restore tutorial in history (Part 2) (Part 36)
This article shares with you the detailed install...
No way, no way, it turns out that there are peopl...
Effect html <body> <div class="cont...
01. Command Overview The seq command is used to g...
In this article, we will look at how to develop a...
This blog is a work note environment: nginx versi...
Preface For file or directory permissions in Linu...
Friends who have used the Linux system must have ...
Origin of the problem When using docker, I unfort...
Find the running container id docker ps Find the ...
Table of contents Problem description: Cause Anal...
Today, let's introduce several common text pr...
This article shares the specific code for JavaScr...
As shown below: The test command determines wheth...
1. Introduction Nginx is a free, open source, hig...