Describes how replication works in a MySQL cluster.

Source: Internet
Author: User

7. Cluster Replication

7.1. Brief Description

Since MySQL 5.1, cluster + replication is supported, which is undoubtedly a surprise for users who want to build a high-availability solution. In this mode, both real-time master-slave backup and cluster-based load balancing are available. The disadvantage is that the performance of this solution is not too high according to my test results, improvements are yet to be made.

The configuration of cluster + replication is actually very simple, that is, after configuring two independent clusters, you can use one of the SQL nodes as the slave of the other cluster SQL node. You can even use the following architectures:

Three clusters and six SQL nodes form a three-point circular replication.

Three clusters and six SQL nodes form a 6-Point Circular replication, and use another SQL node.

7.2. Start Configuration

7.2.1. configuration on master

Because the replication in the cluster is based on row-based replication, you must set the logbin-format to ROW or MIXED.
Compared with the general mysqld server configuration, you only need to add the following two lines:

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

7.2.2. slave Configuration

The new version of MySQL no longer uses my. cnf to specify information about the master, but is managed by changing the MASTER command. Therefore, you only need to add lines similar to the following on the slave:

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

7.3. Start slave

Start mysqld on the master and slave in the normal way, and run show processlist. You can see that there are only two mysqld processes:

 
 
  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) 

Execute SHOW slave STATUS on SLAVE and check again:

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

As you can see, there are no replication-related configurations. Therefore, we need to add an account on the master for replication:

 
 
  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) 

Then, we use the change master command to specify the master-related parameters:

 
 
  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) 

Run start slave to START it.

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

Let's take a look:

 
 
  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. Simple Test

This is left for the reader to complete according to the regular test.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.