当前位置:网站首页>3: MySQL master-slave replication setup
3: MySQL master-slave replication setup
2022-07-28 06:06:00 【Performer】
1: First, introduce the environment
Two alicloud servers : Master(34) Alibaba cloud Slave(226) Alibaba cloud
operating system :CentOS 7.9 64 position
Mysql edition :8.0.28
signal communication : Adopt Intranet IP
2: Installation per server Mysql
I wrote an article about installation before Mysql Tutorials available
3: Build master-slave replication
1: Construction of master node
(1): Edit profile
vim /etc/my.conf file , stay [mysqld] Add below
# Mysql Of bin-log Name
log-bin=mysql-bin
# Mysql Globally unique in the instance , And greater than 0
server-id=34
# Ban Mysql Server For external connections DNS analysis , Use this option to eliminate Mysql Conduct DNS Time of resolution . But all remote connections should use IP Address
skip_name_resolve=ON

(2): see binlog Open or not
restart mysql service , And connect mysql, see binlog Open or not
restart mysql service
systemctl restart mysqld
Inquire about binlog Open or not
show global variables like '%log%';

(3): see binlog Log list
show master logs;

(4): View the server-id Whether to take effect
show global variables like '%server%';

(5): Create a backup account on the primary node
create user 'username'@'%' identified by 'password';
GRANT REPLICATION SLAVE ON *.* TO 'username'@'%';
flush privileges;

2: Construction of slave nodes
(1): Edit profile
vim /etc/my.conf file , stay [mysqld] Add below
# relay log Many aspects and binary log almost , The difference lies in From node's I/O The thread reads the binary log of the main server and records it to the local file of the server , then SQL The thread will read relay-log The contents of the log are applied to the slave node , Thus, the data of the slave node and the master node are consistent
# Definition relay_log Location and name of
relay-log=relay-log
# Definition relay_log Location and name of
relay-log-index=relay-log.index
# Close from node binlog journal
skip-log-bin
# Mysql Globally unique in the instance , And greater than 0
server-id=226
# Ban Mysql Server For external connections DNS analysis , Use this option to eliminate Mysql Conduct DNS Time of resolution . But all remote connections should use IP Address
skip_name_resolve=ON
# You can modify InnoDB Is independent tablespace mode , Each table in each database generates a data space .
innodb_file_per_table=ON

(2): Check the relay log
restart mysql service , And connect mysql, Check whether the relay log is enabled
restart mysql service
systemctl restart mysqld
show global variables like '%log%';

(3): see server-id Whether to take effect
show global variables like '%server%';

(4): The slave node configures the master-slave connection information
The master node needs to find binlog Log the latest files and indexes
show master logs;
myster_log_file and master_log_pos Through the of the master node
Command view . Corresponding Log_name and File_size
Command from node
CHANGE MASTER TO MASTER_HOST='172.29.114.155',
MASTER_USER='username',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=875;

(5): Turn on synchronization
View synchronization status information
show slave status\G;

Turn on synchronization
start slave;

Check the status information again , So far, the master-slave replication configuration is completed 
4: test
Operation on the master node
create database mydb1;
show master status;
Main node diagram 
Operate from the node
show databases;
show slave status\G;
Slave node graph 
5: Some problems encountered
1: Close from node binlog
If it's not closed , Will result in invalid replication
vim /etc/my.cnf
# Set to off binlog
skip-log-bin
2: Connect master error , A secure connection is required
Error message
2022-03-07T08:41:23.047640Z 139 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 34 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection. Error_code: MY-002061
The solution at that time :
stop slave; Close slave node
stay master Put this slave Delete the account , Re create the authorization and refresh it .
stay slave Do it again 【 Command from node 】 That's all right. .
3: I don't know where the error log is , There is no way to check
terms of settlement : from my.cnf find log-error Configuration item , Value is the error log
vim /etc/my.cnf
This is the path of the error log
log-error=/var/log/mysqld.log
4: It's restarted mysql after , You need to restart the read / write configuration from the node
start slave;
6:Java Application testing
(1): Using frames
SpringBoot(2.1.5.RELEASE)
Mybatis-Plus(3.3.0)
Sharding-Jdbc-spring-boot(4.0.0-RC2)
HikariCP(3.2.0)
(2): Success map

(3): Source code ( contain sql)
边栏推荐
- Distributed cluster architecture scenario optimization solution: session sharing problem
- Mars数*字*藏*品*平*台守卫者计划细节公布
- 手撸一个简单的RPC(<-_<-)
- 用于排序的sort方法
- Data warehouse tool superset installation (fully available)
- Create a virtual environment using pycharm
- 撞脸ins? Mars数字藏品平台探索数字藏品轻社交
- 数字藏品成文旅产业新热点
- Flume installation and use
- xml解析实体工具类
猜你喜欢
随机推荐
小程序搭建制作流程是怎样的?
Briefly understand MVC and three-tier architecture
小程序开发要多少钱?两种开发方法分析!
Addition, deletion and modification of data processing; constraint
XShell突然间无法连接虚拟机
小程序开发
Chapter IX sub query (key)
第九章 子查询(重点)
高端大气的小程序开发设计有哪些注意点?
Flume安装及使用
使用pyhon封装一个定时发送邮件的工具类
Assembly打包
数字藏品以虚强实,赋能实体经济发展
JS promise implementation logic
Sales notice: on July 22, the "great heat" will be sold, and the [traditional national wind 24 solar terms] will be sold in summer.
Interface anti duplicate submission
手撸一个简单的RPC(<-_<-)
小程序商城制作一个需要多少钱?一般包括哪些费用?
DataX安装及使用
Variables, process control and cursors








