当前位置:网站首页>Centos7 builds MySQL master-slave replication from scratch (avoid stepping on the pit)
Centos7 builds MySQL master-slave replication from scratch (avoid stepping on the pit)
2022-04-23 20:59:00 【Descosmos】
This article is written by the author on some materials of others , When you combine yourself “ Mining pit ” Lessons learned .
First , The main content of this paper comes from MySQL Master slave replication configuration demonstration ,MySQL Master slave replication configuration steps etc. .
Most of the content of the article is the same as that of the previous article and a video , But in some aspects, due to different systems and other reasons, the author's own practice .
Software :VMware Workstation 15 Player
operating system :Centos7
edition :Percona-Server-5.6(MySQL Branch version )
Pattern : One master and two slaves
- build Centos7 System
- download Percona-Server-5.6
- build
One master and two slaves ,master 192.168.133.138; slave1 192.168.133.139; slave2 192.168.133.140 - MySQL Install package upload :
rz
# here Mysql Installation package for master Of ~ Under the table of contents , Use mv Command to move it to /usr/local/src Catalog
mv Percona-Server-5.6.49-89.0-rd043d30-el7-x86_64-bundle.tar /usr/local/src
# take master Of mysql Copy the installation package to two slave servers
scp Percona-Server-5.6.49-89.0-rd043d30-el7-x86_64-bundle.tar [email protected]:/usr/local/src/
scp Percona-Server-5.6.49-89.0-rd043d30-el7-x86_64-bundle.tar [email protected]:/usr/local/src/
- mysql install
# Respectively in master, slave1, slave2 Execute the following statement under
tar xvf Percona-Server-5.6.49-89.0-rd043d30-el7-x86_64-bundle.tar
rpm -ivh Percona-Server-5.6.49-89.0-rd043d30-el7-x86_64-bundle.tar
rpm -ivh Percona-Server-5.6.49-89.0-rd043d30-el7-x86_64-bundle.tar
rpm -ivh Percona-Server-5.6.49-89.0-rd043d30-el7-x86_64-bundle.tar
Be careful : When the author himself executes the last article , Encountered an error error: Failed dependencies: mariadb-libs is obsoleted by MySQL-shared-compat-5.6.46-1.el7.x86_64, The question is because Centos Originally mysql Of mariadb Installation package , Delete it :
yum -y remove mariadb-libs
The problem can be solved after execution ;
6.mysql start-up
service mysql start
# The author can't use it on the system , Redirect directly to the following command
/bin/systemctl start mysql.service
7. Set up mysql password
mysqladmin -u root password "123"
8. Set up mysql Boot up
chkconfig mysql on
# The author redirects the system to
systemctl enable mysql.service
9. to open up 3306 port ( All four sets should be set )
Refer to the article CentOS 7.5 How to open up 80、8080、3306 Wait for the port .
# because centos7 The default firewall is firewalld, Therefore, you need to uninstall firewalld, install iptables
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
yum install iptables-services -y
systemctl enable iptables
systemctl start iptables
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
systemctl restart iptables.service # Restart the firewall for the configuration to take effect
systemctl enable iptables.service # Set the firewall to power on
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
10. Turn on mysql Remote access rights ( All four sets should be set )
grant all on *.* to 'root'@'%' identified by 'root';
11. To configure master
vim /etc/my.cnf
###################################
stay [mysqld] Add two lines of configuration under the node
server-id=1
log-bin=mysql-bin # Enable binary logging
restart
systemctl restart mysqld.service
Sign in
mysql -u root -p
Database lock table , Don't let write data
mysql> flush tables with read lock;
see MASTER state ( remember File Values and Position value , Follow up on Slave Middle configuration )
mysql> show master status;
12. To configure slave
# open slave1 Set it up
vim /etc/my.cnf
##########################
stay [mysqld] Add a line of configuration under the node :
server-id=2 # In the cluster server-id Can't repeat
# open slave2 Set it up
vim /etc/my.cnf
##########################
stay [mysqld] Add a line of configuration under the node :
server-id=3 # In the cluster server-id Can't repeat
Restart two slave The server
systemctl restart mysqld.service
adopt mysql The command configures the direction of the synchronization log :
mysql> change master to master_host='192.168.133.138', master_port=3306, master_user='root', master_password='123', master_log_file='mysql-bin.000002', master_log_pos=120;
----------------------------
master_host Of the main server IP Address
master_port Of the main server PORT port
master_log_file And the main server show master status Medium File Field values are the same
master_log_pos And the main server show master status Medium Position Field values are the same
start-up slave
mysql> start slave;
mysql> show slave status\G;
here , The problem arises , The author's own system is not as described in the article IO Threads and SQL Threads show "YES", It is IO Thread has been in “CONNECTING”, The author looked it up all afternoon , Finally found the reason :
mysql Unable to connect remotely. Problem (ERROR 1045 (28000): Access denied for user ‘root’)
According to this article , Execute the following command to :
create user 'root'@'172.17.0.%' identified by '123456'; grant all privileges on *.* to 'root'@'172.17.0.%' with grant option;
At the end of the day , The problem is actually MySQL Version problem , Changes caused by modifying external access rights .
After execution , Restart slave The server will find IO Threads in the “YES” state ;
Set up Slave As read-only ( but root Users can still make modifications ):
mysql> set global read_only = 1;
13. Contact master lock
mysql> unlock tables;
Now it's done MySQL Master slave copy , And the operation of read-write separation ( Next issue write Redis And MySQL Sync ).
版权声明
本文为[Descosmos]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/111/202204210545298203.html
边栏推荐
- Deep analysis of C language function
- MySQL basic collection
- Matlab matrix index problem
- Is qiniu school useful and is the recommended securities account safe
- Explore ASP Net core read request The correct way of body
- 41. 缺失的第一个正数
- An error occurs when the addressable assets system project is packaged. Runtimedata is null
- Google tries to use rust in Chrome
- Rust更适合经验较少的程序员?
- Introduce structured concurrency and release swift 5.5!
猜你喜欢
Addition, deletion, modification and query of MySQL advanced table
On the three paradigms of database design
Common commands of MySQL in Linux
Deep analysis of C language function
[SQL] string series 2: split a string into multiple lines according to specific characters
airbase 初步分析
Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties
Matlab: psychtoolbox installation
Unity solves Z-fighting
Write table of MySQL Foundation (create table)
随机推荐
启牛学堂有用吗,推荐的证券账户是否安全
wait、waitpid
Zhongchuang storage | how to choose a useful distributed storage cloud disk
Addition, deletion, modification and query of advanced MySQL data (DML)
亚马逊和Epic将入驻,微软应用商城向第三方开放
Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties
Reentrant function
管道和xargs
Reference of custom message in ROS function pack failed
Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose
Unity animation creates sequence frame code and generates animationclip
MySQL基础之写表(创建表)
Solve importerror: cannot import name 'imread' from 'SciPy misc‘
Tensorflow realizes gradient accumulation, and then returns
Deep analysis of C language function
Selenium 显示等待WebDriverWait
Crisis is opportunity. Why will the efficiency of telecommuting improve?
thinkphp5+数据大屏展示效果
How to learn software testing? Self study or training? After reading this article, you will understand
Question brushing plan -- backtracking method (I)