当前位置:网站首页>Lamp Architecture - MySQL installation and deployment, MySQL Cluster and master-slave structure (1)
Lamp Architecture - MySQL installation and deployment, MySQL Cluster and master-slave structure (1)
2022-07-21 23:56:00 【More than less difference】
mysql Installation and deployment of
- One 、 Download and unzip the installation package
- Two 、 Series connection Lamp framework ,nginx+php+mysql
One 、 Download and unzip the installation package
1. Source code installation package download
Update download location
2. Install and compile software
install cmake
mysql When compiling, you need to use cmake
install gcc and gcc-c++ You can check the official installation manual during installation
compile
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/root/mysql-5.7.31/boost/boost_1_59_0
[[email protected] mysql-5.7.31]# yum install bison -y
Solve problems during compilation
recompile
make
make -j4 To express with 4 individual cpu To calculate , But not recommended , Because it's a virtual machine , Out of memory , If you open multiple core parallel computing , It will cause the problem of memory overflow .make There will be some red errors in the middle , As long as you don't stop, it won't affect , Compilation is slow . install
3. initialization mysql
establish mysql user
[[email protected] mysql-5.7.31]# useradd -s /sbin/nologin -M -d /data/mysql mysql
Copy startup script 、 Create a data directory and assign permissions
Modify the configuration file
[[email protected] mysql-5.7.31]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
mysql Put the command into the environment variable
[[email protected] mysql-5.7.31]# cd /usr/local/mysql/
[[email protected] mysql]# cd bin/
[[email protected] bin]# pwd
/usr/local/mysql/bin
[[email protected] bin]# vim ~/.bash_profile
[[email protected] bin]# source ~/.bash_profile
Use mysql User attribute initialization , And change the password
[[email protected] bin]# mysqld --initialize --user=mysql # initialization
[[email protected] bin]# /etc/init.d/mysqld start # Turn on mysql
[[email protected] bin]# mysql_secure_installation # Change Password
test
 gid=1000(mysql) groups=1000(mysql)
[[email protected] ~]# mkdir -p /data/mysql
[[email protected] ~]# chown mysql.mysql /data/mysql/
add to mysql Commands to environment variables
[[email protected] ~]# vim .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[[email protected] ~]# source .bash_profile
Initialize database
[[email protected] ~]# mysqld --initialize --user=mysql
[[email protected] ~]# /etc/init.d/mysqld start
[[email protected] ~]# mysql_secure_installation
To configure server6 Of mysql
Copy the program to server6 Copy the configuration file to server6
Copy the startup script to server6 Create users and directories , And modify the authority
add to mysql Commands to environment variables
initialization mysql Database login test
3.mysql Master-slave cluster
In fact, that is mysql Master slave copy
1) To configure master node server5
To configure server1 Of mysql Of server-id And binary log names
[[email protected] etc]# vim /etc/my.cnf
log-bin=mysql-bin
server-id=1
[[email protected] etc]# /etc/init.d/mysqld restart
View binary log files mysql Create user repl, And authorize
[[email protected] mysql]# mysql -p
Enter password:
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'westos';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
mysql> show master status;
The number indicates where the copy starts mysql> FLUSH TABLES WITH READ LOCK; # This instruction indicates locking table ,
2) To configure slave node server6
slave To configure server-id
[[email protected] ~]# vim /etc/my.cnf
[[email protected] ~]# /etc/init.d/mysqld restart
server-id=2
slave Configure replication
[[email protected] ~]# mysql -p
mysql> CHANGE MASTER TO MASTER_HOST='172.25.254.15', MASTER_USER='repl', MASTER_PASSWORD='westos', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=595;
mysql> start slave;
mysql> show slave status\G;
slave End replication requires authentication , Users previously created in the main library are required
3) test
master Add data to test
[[email protected] mysql]# mysql -p
Enter password:
mysql> create database westos;
mysql> use westos;
mysql> > create table users (
-> username varchar(20) not null,
-> password varchar(25) not null);
mysql> show tables;
mysql> desc users;
mysql> insert into users values ('user1','123');
mysql> insert into users values ('user2','456');
mysql> select * from users;
slave End view
4.mysql One master and many slaves
One master one slave structure
One master and many slaves
The architecture of one master and many slaves is suitable for the scenario of reading more and writing less , There are two modes , The first one is :A—>B&A---->C; The second kind :A---->B----->C, In this mode ,A The pressure on the node will be smaller .
IO The thread mainly saves the binary log sent to its own data directory
1. Expand one server7 Nodal work slave
Copy app 、 Configuration files and startup scripts
[[email protected] ~]# scp -r /usr/local/mysql/ server7:/usr/local/
[[email protected] mysql]# scp /etc/my.cnf server7:/etc
[[email protected] mysql]# scp /etc/init.d/mysqld server7:/etc/init.d/
establish mysql user , Create a database directory and assign permissions , take mysql Command to the environment variable , modify server-id, start-up mysql
[[email protected] ~]# useradd -s /sbin/nologin -M -d /data/mysql mysql
[[email protected] ~]# chown mysql.mysql /data/mysql/
[[email protected] ~]# vim .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[[email protected] ~]# source .bash_profil
[[email protected] ~]# vim /etc/my.cnf
server-id=3
[[email protected] ~]# cat /etc/my.cnf
[[email protected] ~]# mysqld --initialize --user=mysql
[[email protected] ~]# /etc/init.d/mysqld start
Initialize and change password
[[email protected] ~]# mysql_secure_installation
2. Create a master-slave architecture :A—>B---->C
server5 As the primary server A,server6 As slave The server B( This node also needs to have binary logs , Binary logging needs to be enabled ),server7 As a slave C
server6 Turn on binary log , because server7 When copying, the binary log is copied, not the relay log
test ,server5 Add data , see server6 The playback log will be written to the binary log Relay log index file , Record all relay logs
Use mysqldump Backup server5 Of westos database information , And copy to server7
When backing up database information, you need to lock the table , Because when the data information is large , Backup will not complete in an instant , Someone may be writing information at the time of backup , The backed up database may be inconsistent with the current information , Locking the table means that you can read but not write .
use mysqldump There is a hole in the data server7 Create a database on wesstos, And import server5 Data backed up on
server6 establish repl user , And give authority replication slaveserver7 The database specifies the replication host and file location and number
test
server5 The primary server database inserts data
边栏推荐
猜你喜欢
Does Navicat 16 support native Apple silicon M1 chips| Apple user must read
Chessboard coverage problem
Analysis of cross apply and outer apply query of SQL Server - Part I
Realize information exchange between pages
JMeter之响应断言
The shortcomings of LVS and the fourth forwarding type fullnat
Use Mysql to query logs slowly
Learn IO from simple to deep
Oracle uses data manipulation functions
About the solution of "indentation error: unindent does not match any outside indentation level"
随机推荐
Dry goods | overview of RDBMS index types
Frequently asked interview questions in software testing [2]
【网络协议常见面试题】
Peoplecode variable
"JMeter uses the XPath extractor to obtain the value value in the request response as the input of the next request" case
Practical exercise | a simple method to retrieve odd or even rows in the database
[software test model evolution]
Dbeaver vs Navicat: database tool duel
How to evaluate the test quality?
JMeter之JDBC连接/操作数据库
How to do smoke test
How to write use cases when uploading files?
Day01 software testing foundation summary
Lamp Architecture - MySQL Cluster and group replication (3)
Integer transformation problem
页面重定向
Test case management tool recommendation
LR load balancer management, distributed load generator
How to write the use case of APP registration function?
Postman interface test and pressure test