The main master synchronization configuration and the master-slave configuration is very similar, only need a little modification on it, the master-slave configuration in doubt to view the previous article.
Before the Docker operation, set up the directory, my path is d:/docker/mysql, the directory structure is as follows:
1. Primary master configuration file
Mone:my.cnf
[mysqld]server_id = 1log-bin= mysql-binbinlog-do-db=bloggingreplicate-ignore-db=mysqlreplicate-ignore-db= sysreplicate-ignore-db=information_schemareplicate-ignore-db=performance_schemaread-only=0relay_log= mysql-relay-binlog-slave-updates=onauto-increment-offset=1auto-increment-increment=2!includedir/etc/mysql/ conf.d/!includedir/etc/mysql/mysql.conf.d/
Mtwo:my.cnf
[mysqld]server_id = 2log-bin= mysql-binbinlog-do-db=bloggingreplicate-ignore-db=mysqlreplicate-ignore-db= sysreplicate-ignore-db=information_schemareplicate-ignore-db=performance_schemaread-only=0relay_log= mysql-relay-binlog-slave-updates=onauto-increment-offset=2auto-increment-increment=2!includedir/etc/mysql/ conf.d/!includedir/etc/mysql/mysql.conf.d/
Description
Log-bin: Need to enable binary logging
SERVER_ID: Used to identify different database servers, and unique
BINLOG-DO-DB: Database that needs to be logged to the binary log
BINLOG-IGNORE-DB: Ignoring the database that records the binary log
Auto-increment-offset: The initial value of the server self-increment column
Auto-increment-increment: The server self-incrementing increment
REPLICATE-DO-DB: Specifying the replicated database
REPLICATE-IGNORE-DB: Databases that are not replicated
Relay_log: From the library's trunk log, the main library log is written to the relay log, and the relay log is re-made from the library
Log-slave-updates: Whether to write binary logs from the library, or enable if necessary to become a multi-master. Read-only can not be required
If you are a multi-master, pay attention to setting Auto-increment-offset and Auto-increment-increment
If the above is a double-master setting:
Server 152 self-increment is displayed as: 1,3,5,7,...... (offset=1,increment=2)
Server 153 self-increment is displayed as: 2,4,6,8,...... (offset=2,increment=2)
2. Start creating Master and slave containers
Get base image Docker pull MySQL//create and start master-slave container;//monedocker run--name monemysql-d-P 3317:3306-e mysql_root_password=anech-v D: /docker/mysql/mone/data:/var/lib/mysql-v d:/docker/mysql/mone/conf/my.cnf:/etc/mysql/my.cnf MySQL//mtwodocker run --name mtwomysql-d-P 3318:3306-e mysql_root_password=anech-v d:/docker/mysql/mtwo/data:/var/lib/mysql-v d:/docker/ MYSQL/MTWO/CONF/MY.CNF:/ETC/MYSQL/MY.CNF MySQL
To make it easier to see the data, I exposed two ports to the main host.
3, Mone and Mtwo settings
Go to Mone container Docker exec-it monemysql bash//start MySQL command, just when creating the window we set the password to: anechmysql-u root-p//Create a user to synchronize data grant REPLICATION SLAVE on * * to ' backup ' @ ' percent ' identified by ' 123456 ';//This means creating a slaver Sync account backup, allowing access to an IP address of%,% for wildcards// For example: 192.168.0.% means that 192.168.0.0-192.168.0.255 mtwo can log on to mone with the backup user//View status, remember the value of file, position, will be used in Mtwo show master Status
Go to Mtwo container docker exec-it mtwomysql bash//start MySQL command, just when creating the window we set the password to: anechmysql-u root-p//Set main Library link change master to master _host= ' 172.17.0.2 ', master_user= ' backup ', master_password= ' 123456 ', master_log_file= ' mysql-bin.000001 ', Master_log _pos=0,master_port=3306;
Create a user to synchronize data
GRANT REPLICATION SLAVE on * * to ' backup ' @ ' percent ' identified by ' 123456 ';
This means creating a slaver Sync account backup, which allows access to an IP address of%,% for wildcard characters
For example: 192.168.0.% means that 192.168.0.0-192.168.0.255 Mone can log on to mtwo with a backup user
Start sync start master; View status show Master status;
Once setup is complete, enter the Mone container again
Go to Mone container Docker exec-it monemysql bash//start MySQL command, just when creating the window we set the password to: anechmysql-u root-p//Set main Library link change master to master _host= ' 172.17.0.3 ', master_user= ' backup ', master_password= ' 123456 ', master_log_file= ' mysql-bin.000001 ', Master_log _pos=0,master_port=3306;
Description
Master_host: Main Library Address
Master_user: Sync account created by the main library
Master_password: Sync password created by the main library
Master_log_file: Log generated by the main library
Master_log_pos: Main Library log record offset
Master_port: Port used by the main library, default is 3306
After Setup, restart the MySQL service for the Mone container, and then test to see the results!
Article Source: http://www.cnblogs.com/anech/p/6780949.html
Docker MySQL Master sync configuration Setup Demo