溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

數(shù)據(jù)庫集群的級聯(lián)復(fù)制完整實現(xiàn)

發(fā)布時間:2020-06-10 18:06:06 來源:網(wǎng)絡(luò) 閱讀:990 作者:烽火狼煙_Gk 欄目:MySQL數(shù)據(jù)庫

實驗前的注意:

如果要啟用級聯(lián)復(fù)制,需要在從服務(wù)器啟用以下配置;

[mysqld]
log_bin
log_slave_updates

log_slave_updates的作用:
    因為默認(rèn)從主服務(wù)器過來的二進(jìn)制日志保存在從服務(wù)器的中繼日志;并應(yīng)用到本地數(shù)據(jù)庫;
    但是中間這個從服務(wù)器是即便是開啟二進(jìn)制日志的記錄功能,他也是不記錄到本地的二進(jìn)制日志,
    那么也就不能將對數(shù)據(jù)庫的操作再傳輸?shù)綇牡膹姆?wù)器上去。當(dāng)log_slave_updates啟用后,
    從服務(wù)器也就能將對主服務(wù)器的二進(jìn)制日志在本地執(zhí)行后,也記錄到自己的二進(jìn)制日志中;


刪除數(shù)據(jù)庫就可以干凈做實驗;
[root@master ~]$systemctl stop mariadb
[root@master ~]$rm -fr /var/lib/mysql/*
[root@master ~]$systemctl start mariadb


主、從、二級從服務(wù)器的配置:

[root@master ~]$cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
innodb_file_per_table
log_bin
server-id=1

[root@slave ~]$cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
innodb_file_per_table
server_id=2
read_only
log_bin
log_slave_updates

[root@slave2 ~]$cat  /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server_id=3



主服務(wù)器和從服務(wù)器實現(xiàn)主從復(fù)制,配置和授權(quán):

主服務(wù)器:
MariaDB [(none)]> grant replication slave on *.* to repluser@'192.168.27.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show master logs;
+--------------------+-----------+
| Log_name           | File_size |
+--------------------+-----------+
| mariadb-bin.000001 |       264 |
| mariadb-bin.000002 |       401 |
+--------------------+-----------+
2 rows in set (0.00 sec)



中間的從服務(wù)器:
CHANGE MASTER TO
MASTER_HOST='192.168.27.7',
MASTER_USER='repluser',
MASTER_PASSWORD='centos',
MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS=245;

MariaDB [(none)]> CHANGE MASTER TO
    -> MASTER_HOST='192.168.27.7',
    -> MASTER_USER='repluser',
    -> MASTER_PASSWORD='centos',
    -> MASTER_LOG_FILE='mariadb-bin.000001',
    -> MASTER_LOG_POS=245;
Query OK, 0 rows affected (0.02 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.27.7
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mariadb-bin.000002
          Read_Master_Log_Pos: 401
               Relay_Log_File: mariadb-relay-bin.000003
                Relay_Log_Pos: 687
        Relay_Master_Log_File: mariadb-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
         Exec_Master_Log_Pos: 401
              Relay_Log_Space: 1269
              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

MariaDB [(none)]> select user from mysql.user;
+----------+
| user     |
+----------+
| root     |
| repluser |
| root     |
|          |
| root     |
|          |
| root     |
+----------+
7 rows in set (0.00 sec)



MariaDB [(none)]> show master logs;
+--------------------+-----------+
| Log_name           | File_size |
+--------------------+-----------+
| mariadb-bin.000001 |       401 |
+--------------------+-----------+
1 row in set (0.00 sec)


二級從服務(wù)器上的配置:

在從的從服務(wù)器上執(zhí)行:

[mysqld]
innodb_file_per_table
read-only
server-id=3


CHANGE MASTER TO
MASTER_HOST='192.168.27.17',
MASTER_USER='repluser',
MASTER_PASSWORD='centos',
MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS=401;

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI