欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

實現(xiàn)mysql級聯(lián)復制的方法示例

 更新時間:2019年05月08日 09:37:18   作者:小李子博客  
這篇文章主要介紹了實現(xiàn)mysql級聯(lián)復制的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

所謂級聯(lián)復制就是master服務(wù)器,只給一臺slave服務(wù)器同步數(shù)據(jù),然后slave服務(wù)器在向后端的所有slave服務(wù)器同步數(shù)據(jù),降低master服務(wù)器的寫壓力,和復制數(shù)據(jù)的網(wǎng)絡(luò)IO。

一,配置master服務(wù)器

1,修改主配置文件

vim /etc/my.cnf

在[mysql]配置塊下添加如下兩行配置

[mysql]
log_bin     #開啟二進制日志功能
server_id=1   #為當前節(jié)點設(shè)置一個全局惟一的ID號 

2,重啟mysql服務(wù),使配置生效

systemctl restart mairadb

3,創(chuàng)建有復制權(quán)限的用戶賬號

GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'HOST' IDENTIFIED BY 'replpass'; 

命令解析:

  • 'repluser'@'HOST' :設(shè)置用戶名即主機ip或網(wǎng)段,網(wǎng)段用%表示 例如10.0.0.%
  •  IDENTIFIED BY:設(shè)置密碼
  • *.* :表示所有數(shù)據(jù)庫,所有表
  • GRANT REPLCATION SLAVE:就是允許該用戶復制數(shù)據(jù)

該命令作用就是授權(quán)repluser能拷貝數(shù)據(jù)庫的所有內(nèi)容

二,中繼slave服務(wù)器配置

1,修改主配置文件

vim /etc/my.cnf

在[mysql]配置塊中添加如下兩行配置

[mysqld]  
 log_bin
server_id=2   #為當前節(jié)點設(shè)置一個全局惟一的ID號 
read_only=ON #限制從服務(wù)器為只讀."注意:此限制對擁有SUPER權(quán)限的用戶均無效"
log_slave_updates #該項的作用是把master服務(wù)器的二進制日志計入到本機,然后再把二進制日志復制給后端的其他slave服務(wù)器

2,重啟mysql服務(wù),使配置生效

systemctl restart mariadb

3,使用有復制權(quán)限的用戶賬號連接至主服務(wù)器,并啟動復制線程

   CHANGE MASTER TO 
   MASTER_HOST='host',    #指定master主機IP
   MASTER_USER='repluser',  #指定master被授權(quán)的用戶名
   MASTER_PASSWORD='replpass',#指定被授權(quán)的用戶密碼 MASTER_LOG_FILE='mysql-bin.xxxxx', #指定從master服務(wù)器的那個二進制日志開始復制
   MASTER_LOG_POS=#;     #二進制日志位置,可以在master服務(wù)器上執(zhí)行該命令查看,show master logs;

   啟動復制線程IO_THREAD和SQL_THREAD
   START SLAVE; 

4,查看中繼slave服務(wù)器狀態(tài)

  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.68.7
           Master_User: repluser
           Master_Port: 3306
          Connect_Retry: 60
         Master_Log_File: mariadb-bin.000001
       Read_Master_Log_Pos: 557
          Relay_Log_File: mariadb-relay-bin.000002
          Relay_Log_Pos: 843
      Relay_Master_Log_File: mariadb-bin.000001
         Slave_IO_Running: Yes "重點關(guān)注如果是NO表示線程沒起來"
        Slave_SQL_Running: Yes "重點關(guān)注 如果是NO表示該線程沒起來"
         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: 557
         Relay_Log_Space: 1139
         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 "該項表示同步時間 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: 1

三,后端slave配置

1,修改配置文件

vim /etc/my.cnf

在[mysql]配置塊中添加如下兩行配置

[mysqld]  
server_id=3   #為當前節(jié)點設(shè)置一個全局惟一的ID號
read_only=ON #限制從服務(wù)器為只讀."注意:此限制對擁有SUPER權(quán)限的用戶均無效"

2,重啟mysql服務(wù),使配置生效

systemctl restart mariadb

3,使用有復制權(quán)限的用戶賬號連接至主服務(wù)器,并啟動復制線程

CHANGE MASTER TO 
   MASTER_HOST='中繼host',    #指定中繼slave主機IP
   MASTER_USER='repluser',  #指定master被授權(quán)的用戶名
   MASTER_PASSWORD='replpass',#指定被授權(quán)的用戶密碼 MASTER_LOG_FILE='mysql-bin.xxxxx', #指定從中繼slave服務(wù)器的那個二進制日志開始復制
   MASTER_LOG_POS=#;     #二進制日志位置,可以在slave服務(wù)器上執(zhí)行該命令查看,show master logs;

   啟動復制線程IO_THREAD和SQL_THREAD
   START SLAVE; 

4,查看slave服務(wù)器狀態(tài)

  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.68.17
           Master_User: repluser
           Master_Port: 3306
          Connect_Retry: 60
         Master_Log_File: mariadb-bin.000001
       Read_Master_Log_Pos: 557
          Relay_Log_File: mariadb-relay-bin.000002
          Relay_Log_Pos: 843
      Relay_Master_Log_File: mariadb-bin.000001
         Slave_IO_Running: Yes "重點關(guān)注如果是NO表示線程沒起來"
        Slave_SQL_Running: Yes "重點關(guān)注 如果是NO表示該線程沒起來"
         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: 557
         Relay_Log_Space: 1139
         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 "該項表示同步時間 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: 1

5,最后在master服務(wù)器上創(chuàng)建數(shù)據(jù)庫測試即可查看是否同步

級聯(lián)復制特點

  • 降低master服務(wù)器的壓力,網(wǎng)絡(luò)io壓力
  • 但是會產(chǎn)生數(shù)據(jù)不一致的問題

總結(jié)

  • 中繼slave需要打開二進制日志,必須加上log_slave_updates配置項
  • 注意read_only=ON作用,限制從服務(wù)器為只讀."注意:此限制對擁有SUPER權(quán)限的用戶均無效"

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論