当前位置:网站首页>Configure two databases in master-slave database mode (master and slave)

Configure two databases in master-slave database mode (master and slave)

2022-06-23 20:33:00 kenvie

subject

Use VMWare Create two centos7 The system's virtual machine , Install database services , The two databases are configured in the master-slave database mode (master and slave). When the configuration is complete , At the slave node , perform show status slave\G View the replication status of the slave node . Submit the returned result of viewing the service status from the node to the answer box in the form of text .( Database user name root, password 000000; All commands about the database use lowercase )

Node planning

IP

Host name

node

192.168.200.11

mysql1

Master database

192.168.200.12

mysql2

From database

Get ready

Turn off the server firewall 、SELINUX

The network configuration

Host name

Pattern

IP

mysql1

Host only

192.168.100.11

NAT

192.168.200.11

mysql2

Host only

192.168.100.12

NAT

192.168.200.12

Configure host name

1、 Configure the first host name as mysql1

[[email protected] ~]# hostnamectl set-hostname mysql1
[[email protected] ~]# bash
[[email protected] ~]# 

2、 Configure the second host name as mysql2

[[email protected] ~]# hostnamectl set-hostname mysql2
[[email protected] ~]# bash
[[email protected] ~]# 

add to host

1、 To configure mysql1 Of host, Add the following to /etc/hosts

[[email protected] ~]# vi /etc/hosts
192.168.200.11 mysql1
192.168.200.12 mysql2

2、 Using remote replication will mysql1 Of hosts File replacement mysql2 Medium hosts file

[[email protected] ~]# scp /etc/hosts 192.168.200.12:/etc/hosts
The authenticity of host '192.168.200.12 (192.168.200.12)' can't be established.
ECDSA key fingerprint is 14:57:da:84:0b:98:67:83:88:d7:c4:62:bf:87:60:f6.
Are you sure you want to continue connecting (yes/no)?  #yes
Warning: Permanently added '192.168.200.12' (ECDSA) to the list of known hosts.
[email protected]'s password:  # Input password 
hosts                                    100%  202     0.2KB/s   00:00  

To configure yum Source (mysql1)

1、 Back up the original yum Source

[[email protected] ~]# mkdir /etc/yumback
[[email protected] ~]# mv /etc/yum.repos.d/* /etc/yumback

2、 Mount the image

[[email protected] ~]# mkdir /opt/centos
[[email protected] ~]# vi /etc/fstab    # Add the following command to the last line 
/root/CentOS-7-x86_64-DVD-1511.iso /opt/centos/ iso9660 defaults,loop 0 0
# Don't restart yet , Run the following command to verify that the mount is successful 
[[email protected] ~]# mount -a   

3、 To configure yum

[[email protected] ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1

4、 Clean cache , Build cache

[[email protected] ~]# yum clean all
[[email protected] ~]# yum makecache

install FTP(mysql1)

Installation configuration ftp

[[email protected] ~]# yum install -y vsftpd
[[email protected] ~]# vi /etc/vsftpd/vsftpd.conf
# Add the following line in the last line 
anon_root=/opt

[[email protected] ~]# systemctl start vsftpd
[[email protected] ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

To configure yum(mysql2)

1、 Back up the original yum Source

[[email protected] ~]# mkdir /opt/yumback
[[email protected] ~]# mv /etc/yum.repos.d/* /opt/yumback

2、 To configure yum

[[email protected] ~]# vi /etc/yum.repos.d/ftp.repo
[mysql1]
name=mysql1
baseurl=ftp://192.168.100.11/centos
gpgcheck=0
enabled=1

3、 Clean cache , Build cache

[[email protected] ~]# yum clean all
[[email protected] ~]# yum makecache

Primary node installation mariadb

install mariadb And mariadb service

[[email protected] ~]# yum install mariadb mariadb-server -y
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb
# Initialize database 
#!!!!!!!!! Be sure to start mariadb Service reinitialization !!!!!!!!!
[[email protected] ~]# mysql_secure_installation

Install from node mariadb

install mariadb And mariadb service

[[email protected] ~]# yum install mariadb mariadb-server -y
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb
# Initialize database 
#!!!!!!!!! Be sure to start mariadb Service reinitialization !!!!!!!!!
[[email protected] ~]# mysql_secure_installation

Master node configuration database

1、 Modify the database configuration file

[[email protected] ~]# vi /etc/my.cnf
# stay [mysqld] To add the following ( You don't need to add what you already have ):
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log_bin = mysql-bin   #  Open the log ( The host needs to be turned on ), This mysql-bin  Customizable , You can also add paths 
binlog_ignore_db = mysql   # Libraries that do not give slave synchronization ( Write multiple lines )
server_id = 11
[[email protected] ~]# systemctl restart mariadb

2、 to open up mysql1 Database permissions

[[email protected] ~]# mysql -uroot -p000000
MariaDB [(none)]> grant all privileges on *.* to [email protected]'%' identified by "000000";
MariaDB [(none)]> grant replication slave on *.* to 'user'@'mysql2' identified by '000000';
MariaDB [(none)]> exit

Configure the database from the node

1、 Modify the database configuration file

[[email protected] ~]# vi /etc/my.cnf
 stay [mysqld] To add the following ( You don't need to add what you already have ):
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log_bin = mysql-bin    #  Open the log ( The host needs to be turned on ), This mysql-bin  Customizable , You can also add paths 
binlog_ignore_db = mysql  # Libraries that do not give slave synchronization ( Write multiple lines )
server_id = 12
[[email protected] ~]# systemctl restart mariadb

2、 to open up mysql2 Database permissions

[[email protected] ~]# mysql -uroot -p000000
MariaDB [(none)]> change master to master_host='mysql1',master_user='user',master_password='000000';
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G;

Submission

MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: mysql1
                  Master_User: user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 529
               Relay_Log_File: mariadb-relay-bin.000002
                Relay_Log_Pos: 813
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 529
              Relay_Log_Space: 1109
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 11
1 row in set (0.00 sec)
原网站

版权声明
本文为[kenvie]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112301037126675.html