当前位置:网站首页>MySQL master-slave replication docker cluster construction
MySQL master-slave replication docker cluster construction
2022-07-21 03:39:00 【A fool riding the wind and waves】
Mysql Log based master-slave replication
First installation docker Don't say the , Here we're going to 3 Servers
master | 192.168.0.100 |
---|---|
node1 | 192.168.0.101 |
node2 | 192.168.0.102 |
from docker Remote warehouse pull Mysql:5.7 Mirror source
Here we need to mount the volume and port mapping in the container , Then we can modify the corresponding configuration , Make master-slave replication docker run --name master -p 3306:3306 -p 33060:33060 -v /my/custom/:/etc/mysql/ -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
We do not have a customized configuration file when mounting , Set the configuration file directory /my/custom/
It's empty , This will cause after mounting , The files and folders that should be in the container are emptied
terms of settlement : Is to open another one mysql Containers , adopt docker cp
The order will /etc/mysql/
Copy the files and folders under the directory to the local
The soft connection here is in an invalid state , We don't need to care about it here , It's still normal in the container , The function of this file in the container is to 【mysqld】
Such configuration fields are split into multiple files , The path of the file is saved in mysqld in
The above steps should be carried out on all three hosts
Next, we will start to arrange master-slave replication
- modify mysqld.cnf Configuration fields in
stay【mysqld】
Add the following fields below
These two fields are open binlog journal , Set up services id
Be careful : The slave can not start the log , The host must be turned on , The log of the slave is provided to , service id It cannot be repeated in a cluster , Nor can it be 0,0 Indicates that master-slave replication is not enabled - Create users to copy
Each copy uses MySQL User name and password connect to source , Therefore, there must be a user account on the source where the replica can be used for connection .
Create users first . Then grant this account the privileges required for replication , Use GRANT. If you create an account for replication purposes only , This account only needs REPLICATION SLAVE jurisdiction . for example , To set up a new user , The user can connect to any host in the domain for replication , Publish the following statement on the source :mysql> CREATE USER 'repl'@'%.example.com' IDENTIFIED BY 'password'; mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.example.com';
- Get the binary log coordinates of the replication source
There are two ways 1. Restart container 2.Flush Close the table to obtain a read lock
Don't say the first , Look directly at the second type and enter the following command
Then enter the following command :mysql> FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS
This step is to get the host , At present, we have reached the number of entries in that log , The slave can start synchronization at this position . - In fact, there should be another step here is the transfer of data , But we use new hosts and slaves , Don't do this step
- The last step is to turn on the slave
First release the read lock on the hostUNLOCK TABLES;
Then modify it on the slave【mysqld】
Set upserver-id
Then configure the necessary information for connecting to the host
Modify according to the field , The first is the main sentence ip, The second is the user name created on the host , The third is the user's password , The fourth is the serial number of the current logmysql> CHANGE MASTER TO -> MASTER_HOST='source_host_name', -> MASTER_USER='replication_user_name', -> MASTER_PASSWORD='replication_password', -> MASTER_LOG_FILE='recorded_log_file_name', -> MASTER_LOG_POS=recorded_log_position;
SHOW MASTER STATUS
Found in , the last one recorded_log_position Is the number of lines in the log .
Finally, start the slave thread on the two slave nodesSTART SLAVE;
Finally, the master-slave establishment is completed
边栏推荐
猜你喜欢
基于弹性云服务器的昇腾AI应用开发随笔【与云原生的故事】
Flink datastream API (XIV) Flink output to MySQL (JDBC)
(三)PyTorch深度学习:反向传播梯度下降
MIMO-OFDM无线通信技术及MATLAB实现(2)-SISO下的室外信道模型
【CANN训练营】基于昇腾CANN平台的AI CPU算子开发
【深度学习】运用mnist数据集实例化一个简单的卷积神经网络
Docker remote connection MySQL
根据不同configuration加载不同的plist文件
(七)PyTorch深度学习:全连接层网络
Redis publishing and subscription
随机推荐
MIMO-OFDM无线通信技术及MATLAB实现(2)-SISO下的室外信道模型
Realization of data warehouse technology
Antd mobile form validation RC form usage
李宏毅2020机器学习--P17 CNN &P 14
达梦DEM的部署
[camp d'entraînement can] essai de mise en œuvre du Gan basé sur Shengsi
(四)PyTorch深度学习:PytTorch实现线性回归
(八)PyTorch深度学习:卷积神经网络(基础)---将(七)全连接神经网络改成卷积神经网络
Mysql 主从复制 docker集群搭建
【深度学习】卷积神经网络最大池化运算
Xiaobai tutorial -- Anaconda's jupyter notebook automatic completion configuration tutorial
二分图
李宏毅2020机器学习--P11 Logistic Regression
Centos8 (Linux) 安装 redis
[deep learning] instantiate a simple convolutional neural network using MNIST data set
电脑端微信有很多垃圾可以清理
小白教程--anaconda之Jupyter Notebook自动补全配置教程
Find a number between two Fibonacci series
Dameng AWR report extraction
在Pycharm中打包(.py)文件成(.exe)文件