当前位置:网站首页>Docker MySQL master-slave backup
Docker MySQL master-slave backup
2022-04-23 11:27:00 【Oaa114 dragon boy】
1. download mysql:5.7 Mirror image
docker pull mysql:5.7
2. Create mount directory
vi mk.sh
mkdir -p install /root/mysqlms/data
mkdir -p install /root/mysqlms/conf.d
mkdir -p install /root/mysqlms/mysql-files
mkdir -p install /root/mysqlsl/data
mkdir -p install /root/mysqlsl/conf.d
mkdir -p install /root/mysqlsl/mysql-files
./mk.sh
3. Create the master server
Create the main container
docker run --name sqlms -p 3306:3306 -d -v /root/mysqlms/data:/var/lib/mysql/ -v /root/mysqlms/mysql-files:/var/lib/mysql-files/ -v /root/mysqlms/conf.d:/etc/mysql/conf.d/ -e MYSQL_ROOT_PASSWORD=root mysql:5.7
Enter the main container and place my.cnf Delete
docker exec -it sqlms bin/bash
rm -rf my.cnf
exit
Exit the container
Configure the master server in the host
Go to the mount Directory
cd /root/sqlms/conf.d
Create a mysql The configuration file
vi my.cnf
# Turn on bin-log Log and give a id
[mysqld]
server-id=1
log-bin=mysql-bin
Then enter the main container to my.cnf Move to the original directory
mv my.cnf /etc/mysql/
docker restart sqlms
Create from service container
Create slave server
docker run --name sqlsl -p 3307:3306 -d -v /root/mysqlsl/data:/var/lib/mysql/ -v /root/mysqlsl/mysql-files:/var/lib/mysql-files/ -v /root/mysqlsl/conf.d:/etc/mysql/conf.d/ -e MYSQL_ROOT_PASSWORD=root mysql:5.7
Repeat the operation of the main service container until mysql The configuration file
Change from mysql The configuration file
Go to the mount Directory
cd /root/sqlms/conf.d
Generate configuration files
vi my.cnf
[mysqld]
server-id=2
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
Restart the service
docker restart sqlsl
After the preparation phase, start the formal operation
Main service container operation
Enter the main container and start mysql
docker exec -it sqlms bin/bash
mysql -uroot -proot
Enter at the command line
CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
Create a slave The user is authorized to read and write any file , Used for master-slave backup data
show master status;
Need to be used file and pos data
Operate from the service container
mysql Command line input
change master to master_host='172.17.0.2', master_user='slave', master_password='123456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos= 154, master_connect_retry=60;
master_log_pos=154 , Is the maximum position of the value record
master_host :Master The address of , It refers to the independence of the container ip
master_port:Master Port number , Refers to the port number of the container
master_user: Users for data synchronization
master_password: Password of the user for synchronization
master_log_file: Appoint Slave From which log file to start copying data , As mentioned above File Value of field
master_log_pos: From which Position Start reading , As mentioned above Position Value of field
master_connect_retry: If the connection fails , Retry interval , The unit is seconds , The default is 60 second
start slave;
Enable master-slave backup
show slave status \G
Check the status
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
The last two values are yes Open successfully , If there is no perhaps connection It means opening failed .
版权声明
本文为[Oaa114 dragon boy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231125175871.html
边栏推荐
- 赛微微电科创板上市破发:跌幅达26% 公司市值44亿
- Advanced file IO of system programming (13) -- IO multiplexing - Select
- @Valid, @ validated learning notes
- Cognition and R & D technology of micro robot
- Analyze the rules for the use of robots with good performance
- 解析性能良好的机器人使用守则
- Three web components (servlet, filter, listener)
- redis优化系列(二)Redis主从原理、主从常用配置
- laravel-admin表单验证
- Share two practical shell scripts
猜你喜欢
Interpretation of biological recognition in robot programming course
初探 Lambda Powertools TypeScript
Nacos Basics (5): getting started with Nacos configuration
PDMS软光刻加工过程
Significance of actively participating in middle school robot competition
Share two practical shell scripts
解读2022机器人教育产业分析报告
Overall plan management mode in maker Education
系统编程之高级文件IO(十三)——IO多路复用-select
怎么进行固定资产盘点,资产盘点报告如何一键生成
随机推荐
2022爱分析· 工业互联网厂商全景报告
nacos基础(9):nacos配置管理之从单体架构到微服务
详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
全网最细的短网址系统设计与实战
积极参与中学机器人竞赛的意义
Link sorting of tutorials such as assembly language running environment setting
Prevent SQL injection in web projects
When the activity is in progress! Click the link to join the live studio to participate in "can AI really save energy?" Let's have a discussion!
QT 64 bit static version display gif
Understanding of fileprovider path configuration strategy
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
PDMS软光刻加工过程
ImportError: libX11.so.6: cannot open shared object file: No such file or directory
解读2022机器人教育产业分析报告
Canvas详解
Oracle连通性测试小工具
laravel 永远返回 JSON 响应
小程序 支付
Learning go language 0x02: understanding slice
少儿编程结构的改变之路