Implementation of MySQL semi-synchronous replication

Source: Internet
Author: User
Tags mysql command line

The differences between MySQL semi-synchronous and asynchronous replication are as shown in the architecture diagram above: In the case of MySQL asynchronous replication, MySQL master server transfers its binary log through the replication thread, MySQL Master Sever automatically returns data to the client, regardless of whether the binary log is accepted on slave. In a semi-synchronous replication architecture, when master sends its own binlog to slave, make sure that slave has accepted the binary log before returning the data to the client. Compare two architectures: Asynchronous replication can ensure a fast response structure for the user, but does not ensure that the binary logs actually reach the slave; half-synchronous replication is slightly slower for the customer's request response, but he can guarantee the integrity of the binary log.


The following is a master-slave architecture for configuring a semi-synchronous replication implementation:
192.168.1.141 is the primary server for MySQL
192.168.1.142 for MySQL from the server

1. Provide configuration for MySQL master server
Edit/ETC/MY.CNF, which provides the following configuration
Log_bin=index
Server_id=1
Authorizing on the primary server
# mysql> Grant replication slave,replication client on [email protected] ' 192.168.1.142 ' identified by ' 123456 ';
# mysql> flush Privileges;


2. Provision configuration for MySQL from the service
Edit/ETC/MY.CNF, which provides the following configuration
server_id=10
Relay_log=relay
Read_only=on
Skip-slave-start=1
Go to MySQL command line interface
# mysql > Change master to master_host= "192.168.1.141", master_user= "USER", master_password= "123456", Master_log_ File= "index.000004", master_log_pos=429;
# mysql > Start slave;
If you can see the Slave_io_running:yes and Slave_sql_running:yes two lines of information, it proves that the master-slave configuration has been successful.

To use MySQL's semi-synchronous replication feature requires a MySQL plugin, mysql default supported plug-in/usr/local/mysql/lib/plugin/, which has two semisync_master.so and semisync_ Slave.so's shared library is the key to our MySQL semi-synchronous replication


3. Set up semi-synchronous replication
Execute the following code under the command line interface of the MySQL master server:
# mysql > Install plugin rpl_semi_sync_master SONAME ' semisync_master.so ';
# mysql > Show variables like "%semi%"; (If you see a new semi variable, the installation module succeeds)
| rpl_semi_sync_master_enabled | OFF | Whether to start the semi-synchronous replication, which is off by default
| Rpl_semi_sync_master_timeout | 10000 | Wait for the timeout to be received from the server, and if the time is up, it is not yet accepted, automatically downgraded to asynchronous
| Rpl_semi_sync_master_trace_level | 32 | Run level
| Rpl_semi_sync_master_wait_no_slave | On | If there is no slave time to wait, the default is also need to wait
# mysql > Set global rpl_semi_sync_master_enabled = 1;
# mysql > Set global rpl_semi_sync_master_timeout = 1000;
In MySQL, execute the following code from the command line interface of the server:
# mysql > Install plugin rpl_semi_sync_slave SONAME ' semisync_slave.so ';
# mysql > Show variables like "%semi%"; (If you see a new semi variable, the installation module succeeds)
# mysql > Set global rpl_semi_sync_slave_enabled = 1;
# stop Slave;
# start Slave;
Finally, the common configuration parameters are written in the configuration file:
192.168.1.141:
[Mysqld]
Rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000

192.168.1.142:
[Mysqld]
Rpl_semi_sync_slave_enabled=1


4. View status information for semi-synchronous replication
Execute the following command in 192.168.1.141:
Mysql> Show status like "%semi%";
+-------------------------------------------------------------------+----------+
| variable_name | Value |
+-------------------------------------------------------------------+----------+
| rpl_semi_sync_master_clients |   1 | Number of semi-synchronous replication clients
| Rpl_semi_sync_master_net_avg_wait_time |   555 | Average wait time (default milliseconds)
| Rpl_semi_sync_master_net_wait_time |   1665 | Total Waiting time
| Rpl_semi_sync_master_net_waits |   3 | Number of Waits
| Rpl_semi_sync_master_no_times |   0 | Number of times to turn off semi-synchronous replication
| Rpl_semi_sync_master_no_tx |   0 | Indicates the number of times a slave commit was not successfully received
| Rpl_semi_sync_master_status |   On | Indicates whether the mode is currently asynchronous or semi-synchronous, on is semi-synchronous
| Rpl_semi_sync_master_timefunc_failures |   0 | Number of times the call time function failed
| Rpl_semi_sync_master_tx_avg_wait_time |   575 | Average transfer time of a thing
| Rpl_semi_sync_master_tx_wait_time |   1725 | Total transfer time of a thing
| Rpl_semi_sync_master_tx_waits |   3 | Number of things waiting
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| rpl_semi_sync_master_wait_sessions |   0 | How many sessions are currently waiting due to Slave's reply
| Rpl_semi_sync_master_yes_tx |   3 | The number of times a successful response to a slave thing has been received
+-------------------------------------------------------------------+---------+

5. Cancel the semi-synchronous copy of the plugin
On 192.168.1.141:
# mysql > Uninstall plugin rpl_semi_sync_master;
# mysql > Show status like "%semi%"

On 192.168.1.142:
# mysql > Uninstall plugin rpl_semi_sync_slave;
# mysql > Show status like "%semi%"
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.