自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

詳解MySQL集群下的復(fù)制(replicate)原理

數(shù)據(jù)庫 MySQL 數(shù)據(jù)庫運(yùn)維
MySQL集群與復(fù)制是本文的重要內(nèi)容,在這種模式下,既有主從的實(shí)時(shí)備份,又有基于集群的負(fù)載均衡。希望對(duì)大家有所幫助。

7. 集群下的復(fù)制

7.1. 簡(jiǎn)述

從MySQL 5.1 開始,就支持集群+復(fù)制了,這對(duì)于想要構(gòu)建一個(gè)高可用方案的用戶來說,無疑是個(gè)驚喜。在這種模式下,既有主從的實(shí)時(shí)備份,又有基于集群的負(fù)載均衡,不足指出在于,從我的測(cè)試結(jié)果來看,這種方案下的性能還不是太高,仍有待改進(jìn)。

集群+復(fù)制的配置其實(shí)很簡(jiǎn)單,就是配置好2個(gè)獨(dú)立的集群后,把其中一個(gè)的SQL節(jié)點(diǎn)作為另一個(gè)集群SQL節(jié)點(diǎn)的slave即可。甚至可以使用下面幾種架構(gòu):

3個(gè)集群,6個(gè)SQL節(jié)點(diǎn),形成一個(gè)3個(gè)點(diǎn)環(huán)形的復(fù)制。

3個(gè)集群,6個(gè)SQL節(jié)點(diǎn),形成一個(gè)6個(gè)點(diǎn)環(huán)形的復(fù)制,把另一個(gè)SQL節(jié)點(diǎn)也利用起來。

7.2. 開始配置

7.2.1. master上的配置

由于集群下的復(fù)制是基于row-based復(fù)制的,因此需要設(shè)置logbin-format的格式為:ROW 或者 MIXED。
相對(duì)于普通的mysqld服務(wù)器配置,只需要增加類似如下2行:

  1. server-id = 1  
  2. binlog_format = "ROW" #or MIXED 

7.2.2. slave上的配置

新版本的MySQL已經(jīng)不再通過 my.cnf 來指定master相關(guān)的信息了,而是通過 CHANGE MASTER 指令來管理。因此,slave上只需簡(jiǎn)單增加類似如下幾行:

  1. server-id = 2 
  2. relay-log-purge=1 
  3. skip-slave-start  
  4. replicate-ignore-db=mysql 

7.3. 啟動(dòng)slave

先按照正常的方式啟動(dòng)master和slave上的mysqld后,執(zhí)行SHOW PROCESSLIST 可以看到2個(gè)mysqld都只有2個(gè)進(jìn)程:

  1. mysql> SHOW PROCESSLIST;  
  2. +----+-------------+-----------+------+---------+------+-----------------------------------+------------------+  
  3. | Id | User        | Host      | db   | Command | Time | State                             | Info             |  
  4. +----+-------------+-----------+------+---------+------+-----------------------------------+------------------+  
  5. |  1 | system user |           |      | Daemon  |    0 | Waiting for event from ndbcluster | NULL             |  
  6. |  2 | root        | localhost | NULL | Query   |    0 | NULL                              | show processlist |  
  7. +----+-------------+-----------+------+---------+------+-----------------------------------+------------------+  
  8. 2 rows in set (0.00 sec) 

在slave上執(zhí)行 SHOW SLAVE STATUS 再看看:

  1. mysql> show slave status\G  
  2. Empty set (0.00 sec) 

可以看到,現(xiàn)在還沒有任何復(fù)制相關(guān)的配置。因此,我們需要先在master上添加一個(gè)賬戶用于復(fù)制:

  1. mysql> GRANT REPLICATION SLAVE, GRANT REPLICATION CLIENT ON *.* TO rep@’192.168.1.2’ IDENTIFIED BY ‘rep’;  
  2. Query OK, 0 rows affected (0.00 sec) 

然后,我們用 CHANGE MASTER 指令來指定一下 master 相關(guān)的參數(shù):

  1. mysql> CHANGE MASTER TO MASTER_HOST='192.168.0.2'MASTER_USER='rep'MASTER_PASSWORD='rep';   
  2. Query OK, 0 rows affected (0.01 sec)  
  3.  
  4. mysql> SHOW SLAVE STATUS\G  
  5. *************************** 1. row ***************************  
  6.                Slave_IO_State:   
  7.                   Master_Host: 192.168.0.2  
  8.                   Master_User: rep  
  9.                   Master_Port: 3306  
  10.                 Connect_Retry: 60  
  11.               Master_Log_File:   
  12.           Read_Master_Log_Pos: 4  
  13.                Relay_Log_File: slave-relay-bin.000001  
  14.                 Relay_Log_Pos: 4  
  15.         Relay_Master_Log_File:   
  16.              Slave_IO_Running: No  
  17.             Slave_SQL_Running: No  
  18.               Replicate_Do_DB:   
  19.           Replicate_Ignore_DB: mysql  
  20.            Replicate_Do_Table:   
  21.        Replicate_Ignore_Table:   
  22.       Replicate_Wild_Do_Table:   
  23.   Replicate_Wild_Ignore_Table:   
  24.                    Last_Errno: 0  
  25.                    Last_Error:   
  26.                  Skip_Counter: 0  
  27.           Exec_Master_Log_Pos: 0  
  28.               Relay_Log_Space: 106  
  29.               Until_Condition: None  
  30.                Until_Log_File:   
  31.                 Until_Log_Pos: 0  
  32.            Master_SSL_Allowed: No  
  33.            Master_SSL_CA_File:   
  34.            Master_SSL_CA_Path:   
  35.               Master_SSL_Cert:   
  36.             Master_SSL_Cipher:   
  37.                Master_SSL_Key:   
  38.         Seconds_Behind_Master: NULL  
  39. Master_SSL_Verify_Server_Cert: No  
  40.                 Last_IO_Errno: 0  
  41.                 Last_IO_Error:   
  42.                Last_SQL_Errno: 0  
  43.                Last_SQL_Error:   
  44. 1 row in set (0.00 sec) 

執(zhí)行 START SLAVE 來啟動(dòng)它。

  1. mysql> start slave;  
  2. Query OK, 0 rows affected (0.00 sec) 

再來看看:

  1. mysql> SHOW SLAVE STATUS\G  
  2. *************************** 1. row ***************************  
  3.                Slave_IO_State: Waiting for master to send event  
  4.                   Master_Host: 192.168.0.2  
  5.                   Master_User: rep  
  6.                   Master_Port: 3306  
  7.                 Connect_Retry: 60  
  8.               Master_Log_File: binlog.000001  
  9.           Read_Master_Log_Pos: 256  
  10.                Relay_Log_File: slave-relay-bin.000002  
  11.                 Relay_Log_Pos: 398  
  12.         Relay_Master_Log_File: binlog.000001  
  13.              Slave_IO_Running: Yes  
  14.             Slave_SQL_Running: Yes  
  15.               Replicate_Do_DB:   
  16.           Replicate_Ignore_DB: mysql  
  17.            Replicate_Do_Table:   
  18.        Replicate_Ignore_Table:   
  19.       Replicate_Wild_Do_Table:   
  20.   Replicate_Wild_Ignore_Table:   
  21.                    Last_Errno: 0  
  22.                    Last_Error:   
  23.                  Skip_Counter: 0  
  24.           Exec_Master_Log_Pos: 256  
  25.               Relay_Log_Space: 557  
  26.               Until_Condition: None  
  27.                Until_Log_File:   
  28.                 Until_Log_Pos: 0  
  29.            Master_SSL_Allowed: No  
  30.            Master_SSL_CA_File:   
  31.            Master_SSL_CA_Path:   
  32.               Master_SSL_Cert:   
  33.             Master_SSL_Cipher:   
  34.                Master_SSL_Key:   
  35.         Seconds_Behind_Master: 0  
  36. Master_SSL_Verify_Server_Cert: No  
  37.                 Last_IO_Errno: 0  
  38.                 Last_IO_Error:   
  39.                Last_SQL_Errno: 0  
  40.                Last_SQL_Error:   
  41. 1 row in set (0.00 sec) 

7.4. 簡(jiǎn)單測(cè)試

這個(gè)留給讀者自己按照常規(guī)的測(cè)試去完成吧。

 

【編輯推薦】

  1. MySQL數(shù)據(jù)庫集群進(jìn)行正確配置步驟
  2. MySQL 集群在Server1與Server2上如何安裝MySQL
  3. MySQL集群配置
  4. MySQL集群自動(dòng)安裝腳本
  5. MySQL觸發(fā)器如何正確使用

 

 

責(zé)任編輯:彭凡 來源: MySQL中文網(wǎng)
相關(guān)推薦

2020-06-01 16:05:17

MongoDB復(fù)制集數(shù)據(jù)庫

2024-07-04 08:00:24

2020-12-22 10:11:13

MySQL數(shù)據(jù)庫復(fù)制原理

2024-05-27 00:04:00

2015-05-06 13:34:14

MySQL集群搭建

2023-12-29 13:45:00

2024-02-21 16:42:00

2019-09-16 16:05:13

Redis集群模式

2017-09-05 16:00:49

MySQL主從復(fù)制備份

2017-07-07 10:40:24

MySQL備份原理

2025-01-15 15:47:36

2024-03-01 18:33:59

MySQL節(jié)點(diǎn)數(shù)據(jù)

2021-06-08 07:48:27

MySQL主從配置

2021-01-12 09:03:17

MySQL復(fù)制半同步

2020-04-14 16:26:22

MySQL線程同步

2017-06-23 11:17:24

MySQL搭建配置

2010-10-19 16:32:46

MySQL

2010-08-12 13:15:26

MySQL集群

2020-04-14 21:12:42

Redis集群Linux

2024-07-19 09:10:37

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)