当前位置:网站首页>Docker-mysql8-master-slave
Docker-mysql8-master-slave
2022-06-24 23:12:00 【Wang Daochang's way of programming】
One 、 Prepare official image
official docker Mirror image https://hub.docker.com/_/mysql
docker pull mysql:latest
# establish mysql The Internet
docker network create mysql-net --subnet 172.1.2.0/24
docker volume rm $(docker volume list |awk '{if(NR>0) print $2}')
Master slave planning
| role | ip | port | Copy accounts | password |
|---|---|---|---|---|
| master | 172.1.2.2 | 3306 | Slave | slave |
| slave | 172.1.2.3 | 3307 | - | - |
Two 、 Prepare the configuration file
cd ~
mkdir mysql mysql/master mysql/slave
cd mysql
# master The configuration file
echo "[mysqld] server-id=1 log-bin=mysql-bin" >> master/mysql.cnf
# slave The configuration file
echo "[mysqld] server-id=2 relay_log = /usr/local/mysql/data/mysql-relay-bin relay_log-index = /usr/local/mysql/data/mysql-relay-bin.index log_slave_updates = 1 read_only=1" >> slave/mysql.cnf
3、 ... and 、 Master slave configuration
step :
- Modify the master-slave mysql.cnf The configuration file
- Master-slave mysql Service to restart
- The master and slave firewalls are closed
- Establish authorized on the host slave Login account
- Configure from the machine master Information about
3.1 maste To configure
docker run --network mysql-net --name master -p 3306:3306 --ip 172.1.2.3 -e MYSQL_ROOT_PASSWORD=mysecret -d mysql:latest
# establish slave user , And configure permissions
CREATE USER 'slave'@'172.1.2.%' IDENTIFIED WITH mysql_native_password BY 'slave';
select user,host,plugin from mysql.user;
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'172.1.2.%';
# mysql master To configure mysql.cnf
docker cp master/mysql.cnf master:/etc/mysql/conf.d/mysql.cnf
# After modifying the configuration , Make sure you reboot
docker restart master
# verification binlog Open file or not
show global variables like '%log_bin%';
remarks :
[mysqld]
server-id= 1 -- Unique to the primary server id
log-bin=mysql-bin -- Start binary log file
binlog-ignore-db=mysql -- Set ignored database ( Multiple can be set )
binlog-do-db=dbname -- Name of the primary database to be replicated
binlog_format=STATEMENT -- Set up binlog The log format of
establish slave The login account permissions of the node
-- Host computer MySQL To carry out the authorization order in the library
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY '123123';
-- Inquire about master The state of
show master status;
-- Record file and position value , And stop master Our external services , Prevent the master server status value from changing
3.2 slave To configure
docker run --network mysql-net --name slave -p 3307:3306 --ip 172.1.2.4 -e MYSQL_ROOT_PASSWORD=mysecret -d mysql:latest
# mysql slave To configure mysql.cnf
docker cp slave/mysql.cnf slave:/etc/mysql/conf.d/mysql.cnf
# After modifying the configuration , Make sure you reboot
docker restart slave
# Specify master ip, port , user , And configure master and slave
change master to master_host='172.1.2.3',master_port=3306,master_user='slave',master_password='slave';
# Or partially copied
change master to master_host='192.168.81.132',master_port=3306,master_user='slave',master_password='slave',master_log_file='mysql- bin.000002',master_log_pos=155;
start slave;
# testing
show slave status;
remarks :
[mysqld]
server-id=2 -- Unique from the server id
relay-log=mysql-replay -- Enable relay logging
The slave configures the master node information
change master to master_host=" host ip Address “;
master_user="slave"
master_password="123123"
master_log_file="mysql-bin. Specific figures "
master_log_pos=" Specific value “;
-- Start the replication function from the server
start slave;
-- View the status of the slave server
show slave status\G;
-- Only slave_io_running and slave_sql_running A fellow yes The configuration is successful
Additional information :
-- Stop the copy function from the server
stop slave;
-- Reconfigure master-slave
reset master;
Four 、 Dual master configuration
4.1 master To configure
4.1.1 master1 To configure
#vim /etc/my.cnf
server-id=1 # The primary server is unique ID
log-bin=mysql-bin # Enable binary logging
binlog-ignore-db=mysql # Set up the database not to be copied ( Multiple... Can be set )
binlog-ignore-db=information_schema
binlog-do-db= The name of the database to be copied # Set up the database to be copied
binlog_format=STATEMENT # Set up logbin Format
# As a slave database , Write operations also need to update binary log files
log-slave-updates # The amount of each increment of the table self growth field , It refers to the starting value of the auto increment field , The default value is 1, The value range is 1..65535
auto-increment-increment=2
# The table starts from which number the growth field starts , Refers to how many fields are incremented at a time , The value range is 1..65535
auto-increment-offset=1
4.1.2 master2 To configure
#vim /etc/my.cnf
server-id=3 # The primary server is unique ID
log-bin=mysql-bin # Enable binary logging
# Set up the database not to be copied ( Multiple can be set )
binlog-ignore-db=mysql
binlog-ignore-db=information_schema # Set up the database to be copied
binlog-do-db= The name of the master database to be copied # Set up logbin Format
binlog_format=STATEMENT
# When acting as a slave database , Update binary log files when there are write operations
log-slave-updates # The amount of each increment of the table auto increment field , It refers to the starting value of the auto increment field , Default 1, The value range is 1..65535
auto-increment-increment=2
# The table starts from which number the growth field starts , Refers to how many fields are incremented at a time , The value range is 1..65535
auto-increment-offset=2
4.2 Dual slave configuration
4.2.1 slave1 To configure
#vim /etc/my.cnf
# From the server only ID
server-id=2
# Enable relay logging
relay-log=mysql-relay
Dual host 、 Double slave restart mysql service
The host and slave turn off the firewall
Set up accounts on both hosts and authorize slave
4.3 Master-slave authorization
4.3.1 Dual master authorization
-- Host computer MySQL To carry out the authorization order in the library
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY '123123'; -- Inquire about Master1 The state of
show master status;
-- Inquire about Master2 The state of show master status;
-- Record separately File and Position Value
-- Do not operate the master server after this step MYSQL, Prevent the state value of the primary server from changing
4.3.2 Dual slave authorization
Slava1 Copy Master1,Slava2 Copy Master2
-- slave1、slave2
CHANGE MASTER TO MASTER_HOST=' The host IP', MASTER_USER='slave',
MASTER_PASSWORD='123123', MASTER_LOG_FILE='mysql-bin. Specific figures ',MASTER_LOG_POS= Specific value ;
-- Start the replication function of two slaves
start slave;
-- View the status of the slave server
show slave status\G;
#Slava1 Copy Master1
# The following two parameters are Yes, The master-slave configuration is successful !
# Slave_IO_Running: Yes
# Slave_SQL_Running: Yes
4.4 Master master copy
-- master1、master2
CHANGE MASTER TO MASTER_HOST=' host 2 Of IP',
MASTER_USER='slave',
MASTER_PASSWORD='123123',
MASTER_LOG_FILE='mysql-bin. Specific figures ',MASTER_LOG_POS= Specific value ;
-- master2
CHANGE MASTER TO MASTER_HOST=' host 1 Of IP',
MASTER_USER='slave',
MASTER_PASSWORD='123123',
MASTER_LOG_FILE='mysql-bin. Specific figures ',
MASTER_LOG_POS= Specific value ;
fen Start the replication function of two primary servers respectively
start slave;
-- View the status of the standby database
show slave status \G;
# The following two parameters are Yes, The master-slave configuration is successful !
# Slave_IO_Running: Yes
# Slave_SQL_Running: Yes
边栏推荐
- 案例解析:用「度量」提升企业研发效能|ONES Talk
- canvas 实现图片新增水印
- laravel 消息队列
- How to integrate Huawei cloud function services in fluent
- 15 lines of code using mathematical formulas in wangeditor V5
- 剑指 Offer 13. 机器人的运动范围
- Sword finger offer 42 Maximum sum of successive subarrays
- 对抗训练理论分析:自适应步长快速对抗训练
- Construction equipment [6]
- Mycms we media CMS V3.0, resource push optimization, new free template
猜你喜欢

What kind of processor architecture is ARM architecture?

Talk about GC mechanism often asked in interview

canvas 实现图片新增水印

Getting started with the go Cobra command line tool

对抗训练理论分析:自适应步长快速对抗训练

EPICS记录参考4--所有输入记录都有的字段和所有输出记录都有的字段

推送Markdown格式信息到釘釘機器人

23研考生注意啦!备考期间最容易中招的骗局,居然是它们?!

2022 safety officer-a certificate examination questions and answers

vulnhub Vegeta: 1
随机推荐
Environment configuration | vs2017 configuring openmesh source code and environment
Selection (026) - what is the output of the following code?
【nvm】
07_ Springboot for restful style
Cat write multiline content to file
研究生宿舍大盘点!令人羡慕的研究生宿舍来了!
Beijiafu (p+f) R2000 modified radar IP
laravel用户授权
【nvm】
[WSL] SSH Remote Connection and host port forwarding configuration
EPICS记录参考2--EPICS过程数据库概念
2022年高压电工考试模拟100题及在线模拟考试
Servlet
How to integrate Huawei cloud function services in fluent
Building Survey [2]
How to submit the shopee opening and settlement flow?
EPICS记录参考3 -- 所有记录都有的字段
EPICS record Reference 3 - - field available for all Records
大厂面试必问:如何解决TCP可靠传输问题?8张图带你详细学习
Market trend report, technical innovation and market forecast of solar roof system in China