当前位置:网站首页>[MySQL] installation tutorial and master-slave configuration
[MySQL] installation tutorial and master-slave configuration
2022-07-24 08:04:00 【Small source】
List of articles
Configuring master-slave libraries in an enterprise is an essential link , It can avoid the database downtime caused by many wonderful operations, which will cause the application to hang up .mysql The master-slave configuration of is relatively simple , Follow the document step by step , It's easy to use . I hope it will be of some help to you !
List of articles
Catalog
Two 、 Master slave configuration
1 Turn off firewall ( It can be modified to allow port communication )
2 Whether the master-slave test can be accessed remotely
3 Master database creation user slave And authorize ( Password complexity )
4 Master database query service ID And Master state
5 Set the master library from the Library
3、 ... and Limit user failure retry time
1、 Execute... From the library :
3、 Install the plug-in after login :
4、 The main library modifies the configuration file my.cnf Add two lines :
6、 Execute... From the library :
7、 Install the plug-in after login :
8、 Modify the configuration file from the Library my.cnf Add two lines :
9、 Restart from library mysql:
10、 Execute... From the library :
Preface
Installation package : mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
operating system : Centos8 And Kirin ( All have been tested and work well )
Server address :10.10.109.8 10.10.109.9
One 、 install
# decompression
tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
# Move
mv /opt/mysql-8.0.26-linux-glibc2.12-x86_64 /data
cd /data
mv mysql-8.0.26-linux-glibc2.12-x86_64 mysql
# Create a folder for storing data ( disk array )
mkdir -p /mysql/data
chmod -R 777 /mysql /data
# Create user ( Complexity requirements )
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /data/mysql
# Initialize database
cd /data/mysql/
./bin/mysqld --user=mysql --lower-case-table-names=1 --basedir=/data/mysql/ --datadir=/mysql/data/ --initialize ;
# Configure the main library my.cnf ( Modify the default port )
vi /etc/my.cnf
[client]
port=3209
socket=/data/mysql/mysql.sock
[mysqld]
port=3209
basedir=/data/mysql
datadir=/mysql/data
pid-file=/data/mysql/mysql.pid
socket=/data/mysql/mysql.sock
log_error=/data/mysql/error.log
server-id=1
character-set-server=utf8
lower-case-table-names=1
log-bin=mysql-bin
binlog-ignore-db=sys
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog_format=STATEMENT
open-files-limit=65000
default_authentication_plugin=mysql_native_password
innodb_buffer_pool_size=3GB# start-up mysql
cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
Check whether the service is effective
chkconfig --list mysql
create a file
chmod -R 777 /mysql/data/
cd /data/mysql
touch error.log
touch mysql.pid
chmod –R 777 /data/mysql
start-up 、 stop it 、 restart
service mysql start
service mysql stop
chown -R mysql.mysql /data/mysql
service mysql restart
# Create a soft connection
ln -s /data/mysql/bin/mysql /usr/bin
ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
# modify root password ( Complexity requirements )
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new password';
# Increase remote link permissions
use mysql
update user set host ='%' where user='root';
select user,host from user;
Two 、 Master slave configuration
1 Turn off firewall ( It can be modified to allow port communication )
# View firewall status
systemctl status firewalld
# Turn off firewall
systemctl stop firewalld
2 Whether the master-slave test can be accessed remotely
mysql -uroot -p -h10.10.109.8
mysql -uroot -p -h10.10.109.9
3 Master database creation user slave And authorize ( Password complexity )
mysql -uroot -p
create user 'slave'@'%' identified with mysql_native_password by 'password';
grant replication slave on *.* to 'slave'@'%';
flush privileges;
4 Master database query service ID And Master state
# Sign in
mysql -uroot -p
# Inquire about server_id Whether it can be consistent in the configuration file
show variables like 'server_id';
# If it's not the same , Temporary settings can be set ID( Restart failure )
set global server_id = 1;
# Inquire about Master state , And record File and Position Value
show master status;
5 Set the master library from the Library
mysql -uroot -p
# Inquire about server_id Whether it can be consistent in the configuration file
show variables like 'server_id';
# If it's not the same , Temporary settings can be set ID( Restart failure )
set global server_id = 2;
# Set main database parameters
change master to master_host='10.10.109.8',master_port=3209,master_user='slave',master_password=' password ',master_log_file='mysql-bin.000006',master_log_pos=2812;
# Start syncing
start slave;
# Supported operations
stop slave;
reset slave;
start slave;
# Inquire about slave state
show slave status\G;
# If the master and slave databases are inconsistent , When deleting the master database, the slave database will report an error , Solution :
stop slave;
# skip 1 A mistake ( Multiple can be set 2.3……)
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
start slave;
# In query status , If there are still mistakes, continue to skip
show slave status\G;
The final status is as follows :

3、 ... and Limit user failure retry time
1、 Execute... From the library :
stop slave;
2、 Main library execution :
mysql -u root -p
3、 Install the plug-in after login :
installplugin CONNECTION_CONTROL soname'connection_control.so';
installplugin CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS soname'connection_control.so';
4、 The main library modifies the configuration file my.cnf Add two lines :
connection-control-failed-connections-threshold=5# Limit the number of login failures
connection-control-min-connection-delay=300000# Limit retrying time , Here is the millisecond , Pay attention to conversion according to demand , Here is 5 minute
5 restart mysql:
service mysql restart
Log in to the main database , See if it works
show variables like '%connection_control%'; 
6、 Execute... From the library :
mysql -u root -p
7、 Install the plug-in after login :
installplugin CONNECTION_CONTROL soname'connection_control.so';
installplugin CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS soname'connection_control.so';
8、 Modify the configuration file from the Library my.cnf Add two lines :
connection-control-failed-connections-threshold=5# Limit the number of login failures connection-control-min-connection-delay=300000# Limit retrying time , Here is the millisecond , Pay attention to conversion according to demand , Here is 5 minute
9、 Restart from library mysql:
service mysql restart
Log in from the library database , See if it works
show variables like '%connection_control%'; 
10、 Execute... From the library :
start slave;
11、 Inquire about slave state
show slave status\G;
The end
summary
I hope it will help you , Don't forget to support Xiaobian !
边栏推荐
- 33 introduction to sparksql, dataframe and dataset
- POJ3278抓住那头牛题解
- Use of ArrayList
- Eight part essay on software testing
- [Beijiao] image processing: basic concepts, image enhancement, morphological processing, image segmentation
- The growth path of software testing
- DGL库中一些函数或者方法的介绍
- [linear algebra] deeply understand matrix multiplication, symmetric matrix, positive definite matrix
- Debug No4 use renderdoc to troubleshoot bugs
- 生成模型与判别模型
猜你喜欢

*Code understanding * common function parsing in pytoch

Movie recommendation system

NFT是什么?一篇文章搞懂NFT的概念

Image feature SIFT (scale invariant feature transform)

Do you want to have a robot that can make cartoon avatars in three steps?

Debug No4 use renderdoc to troubleshoot bugs

Function analysis of e-commerce website development and construction

hcip第八天笔记
![[Beijiao] image processing: basic concepts, image enhancement, morphological processing, image segmentation](/img/b3/76d2bcdf4b9769fb6308b7dac9ceb5.jpg)
[Beijiao] image processing: basic concepts, image enhancement, morphological processing, image segmentation

Saining Techtalk attack and defense drill: attack combination fist "stable, accurate and ruthless" penetration
随机推荐
Introduction to webmethods
MySQL update uses case when to update the value of another field according to the value of one field
Telecom Customer Churn Prediction challenge baseline [AI competition]
P1305新二叉树题解
Opencv project practice - credit card recognition
我在微软的这六个月
Debug No1 summarizes common solutions to bugs
Hcip day 9 notes
Do you want to have a robot that can make cartoon avatars in three steps?
Super simple countdown code writing
The vision group of Hegong University Sky team trained Day1 - machine learning, and learned to use the Yolo model
Intelligent robots and intelligent systems (Professor Zhengzheng of Dalian University of Technology) -- 3. Industrial robots
避坑,职场远离PUA,PUA常见的套路与话术你得了解一下!
HCIP第十天笔记
Natural language processing hanlp
abstract class
hcip第九天笔记
Hegong sky team vision training day4 - traditional vision, contour recognition
*Project recurrence * project implementation of thesis based on contextbasedemotionrecognitionusingematicdataset
【线性代数】深入理解矩阵乘法、对称矩阵、正定矩阵