Home Database Mysql Tutorial MySQL 5.5半同步复制_MySQL

MySQL 5.5半同步复制_MySQL

Jun 01, 2016 pm 01:13 PM
mysql

一、实验目的:

mysql在主从复制还支持半同步复制,mysql复制是异步的,因为同步性能非常差。主库分发事件以后必须等待从库复制数据结束并收到从库正常响应以后,才能进行下一步操作。异步模式导致从库落后主库时,主库无从得知。因此mysql5.5后引入google补丁半同步复制,2个插件:semisync_master.so与semisync_slave.so。半同步:一主多从架构中,主库只等待一台从库复制完成数据并返回正常响应,就认为同步完成进行下一步操作,这样即有异步的高速,又有同步的安全。一旦主库等待从库响应超时,半同步复制自动降级为异步复制。半同步复制前提至少有一台从库与主库在同一机房,保证足够带宽,数据复制也足够快。因为对写性能影响极大又需要同步确认等待。

 

二、实验步骤

1.mysql支持的模块/插件

[root@master~]# ls -t /usr/local/mysql/lib/plugin/

debug  semisync_slave.so  mypluglib.so  qa_auth_interface.so  qa_auth_client.so  adt_null.so daemon_example.ini  semisync_master.so  libdaemon_example.so  qa_auth_server.so  auth_test_plugin.so  auth_socket.so  auth.so

2.半同步模块安装

2.1主库

mysql>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';

mysql>SHOW GLOBAL VARIABLES LIKE '%semi%';  服务器变量

+------------------------------------+-------+

|Variable_name                      |Value |

+------------------------------------+-------+

|rpl_semi_sync_master_enabled      |OFF  |

|rpl_semi_sync_master_timeout      |10000 | 主从库连接超时过值,自动降为异步。毫秒

|rpl_semi_sync_master_trace_level  |32    |

|rpl_semi_sync_master_wait_no_slave | ON  | 没有从库也要等一下

+------------------------------------+-------+

mysql>SET GLOBAL rpl_semi_sync_master_enabled=1;

mysql>SET GLOBAL rpl_semi_sync_master_timeout=1000;

mysql>SHOW GLOBAL STATUS LIKE '%semi%';

+--------------------------------------------+-------+

|Variable_name                              | Value |

+--------------------------------------------+-------+

|Rpl_semi_sync_master_clients              | 1    | 从节点1个

|Rpl_semi_sync_master_net_avg_wait_time    | 0    |

|Rpl_semi_sync_master_net_wait_time        | 0    |

|Rpl_semi_sync_master_net_waits            | 0    |

|Rpl_semi_sync_master_no_times            | 0    |

|Rpl_semi_sync_master_no_tx                | 0    |

|Rpl_semi_sync_master_status              | ON    |

|Rpl_semi_sync_master_timefunc_failures    | 0    |

|Rpl_semi_sync_master_tx_avg_wait_time    | 0    |

|Rpl_semi_sync_master_tx_wait_time        | 0    |

|Rpl_semi_sync_master_tx_waits            | 0    |

|Rpl_semi_sync_master_wait_pos_backtraverse | 0    |

|Rpl_semi_sync_master_wait_sessions        | 0    |

|Rpl_semi_sync_master_yes_tx              | 0    |

+--------------------------------------------+-------+

mysql>USE school;

mysql>CREATE TABLE tb2(name CHAR(20));

mysql>SHOW GLOBAL STATUS LIKE '%semi%';

+--------------------------------------------+-------+

|Variable_name                            | Value |

+--------------------------------------------+-------+

|Rpl_semi_sync_master_clients              | 1    |

|Rpl_semi_sync_master_net_avg_wait_time    | 800  | 等待从服返回报告时间

|Rpl_semi_sync_master_net_wait_time        | 800  |

|Rpl_semi_sync_master_net_waits            | 1    |

|Rpl_semi_sync_master_no_times            | 0    |

|Rpl_semi_sync_master_no_tx                | 0    |

|Rpl_semi_sync_master_status              | ON    |

|Rpl_semi_sync_master_timefunc_failures    | 0    |

|Rpl_semi_sync_master_tx_avg_wait_time    | 715  | 等待从服事务返回报告时间

|Rpl_semi_sync_master_tx_wait_time        | 715  |

|Rpl_semi_sync_master_tx_waits            | 1    |

|Rpl_semi_sync_master_wait_pos_backtraverse | 0    |

|Rpl_semi_sync_master_wait_sessions        | 0    |

|Rpl_semi_sync_master_yes_tx              | 1    |

+--------------------------------------------+-------+

mysql>INSERT INTO tb2 VALUES ('tom'),('jerry'),('jack');

mysql>SHOW GLOBAL STATUS LIKE '%semi%';

+--------------------------------------------+-------+

|Variable_name                            | Value |

+--------------------------------------------+-------+

|Rpl_semi_sync_master_clients              | 1    |

|Rpl_semi_sync_master_net_avg_wait_time    | 1518  |

|Rpl_semi_sync_master_net_wait_time        | 3037  |

|Rpl_semi_sync_master_net_waits            | 2    |

|Rpl_semi_sync_master_no_times            | 0    |

|Rpl_semi_sync_master_no_tx                | 0    |

|Rpl_semi_sync_master_status              | ON    |

|Rpl_semi_sync_master_timefunc_failures    | 0    |

|Rpl_semi_sync_master_tx_avg_wait_time    | 715  |

|Rpl_semi_sync_master_tx_wait_time          | 715  |

|Rpl_semi_sync_master_tx_waits            | 1    |

|Rpl_semi_sync_master_wait_pos_backtraverse | 0    |

|Rpl_semi_sync_master_wait_sessions        | 0    |

|Rpl_semi_sync_master_yes_tx              | 2    |

+--------------------------------------------+-------+

从库

mysql>INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

mysql>SHOW GLOBAL VARIABLES LIKE '%semi%';

+---------------------------------+-------+

|Variable_name                  | Value |

+---------------------------------+-------+

|rpl_semi_sync_slave_enabled    |OFF  |

|rpl_semi_sync_slave_trace_level | 32    |

+---------------------------------+-------+

mysql>SET GLOBAL rpl_semi_sync_slave_enabled=1;

mysql>STOP SLAVE;

mysql>START SLAVE;

mysql>SHOW GLOBAL STATUS LIKE '%semi%';

+----------------------------+-------+

|Variable_name              | Value |

+----------------------------+-------+

|Rpl_semi_sync_slave_status | ON    |

+----------------------------+-------+

永久配置在Master和Slave的my.cnf中编辑:

# OnMaster

[root@master~]# vim /etc/my.cnf

[mysqld]

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000# 1 second

验证

mysql>SHOW GLOBAL VARIABLES LIKE '%semi%';

+------------------------------------+-------+

|Variable_name                      | Value |

+------------------------------------+-------+

|rpl_semi_sync_master_enabled      |ON    |

|rpl_semi_sync_master_timeout      |1000  |

|rpl_semi_sync_master_trace_level  |32    |

|rpl_semi_sync_master_wait_no_slave | ON  |

+------------------------------------+-------+

# OnSlave

[root@slave~]# vim /etc/my.cnf

[mysqld]

rpl_semi_sync_slave_enabled=1

验证

mysql>SHOW GLOBAL VARIABLES LIKE '%semi%';

+---------------------------------+-------+

|Variable_name                  | Value |

+---------------------------------+-------+

|rpl_semi_sync_slave_enabled    | ON    |

|rpl_semi_sync_slave_trace_level | 32    |

+---------------------------------+-------+

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The page is blank after PHP is connected to MySQL. What is the reason for the invalid die() function? The page is blank after PHP is connected to MySQL. What is the reason for the invalid die() function? Apr 01, 2025 pm 03:03 PM

The page is blank after PHP connects to MySQL, and the reason why die() function fails. When learning the connection between PHP and MySQL database, you often encounter some confusing things...

How to efficiently integrate Node.js or Python services under LAMP architecture? How to efficiently integrate Node.js or Python services under LAMP architecture? Apr 01, 2025 pm 02:48 PM

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

Is Debian Strings compatible with multiple browsers Is Debian Strings compatible with multiple browsers Apr 02, 2025 am 08:30 AM

"DebianStrings" is not a standard term, and its specific meaning is still unclear. This article cannot directly comment on its browser compatibility. However, if "DebianStrings" refers to a web application running on a Debian system, its browser compatibility depends on the technical architecture of the application itself. Most modern web applications are committed to cross-browser compatibility. This relies on following web standards and using well-compatible front-end technologies (such as HTML, CSS, JavaScript) and back-end technologies (such as PHP, Python, Node.js, etc.). To ensure that the application is compatible with multiple browsers, developers often need to conduct cross-browser testing and use responsiveness

Docker builds LNMP environment: Is a single Dockerfile or Docker Compose better? Docker builds LNMP environment: Is a single Dockerfile or Docker Compose better? Apr 01, 2025 pm 02:09 PM

Dockerfile Best Practice for Building LNMP Environment Learning During Docker, many developers try to build their own LNMP (Linux, Nginx, MySQL, PHP)...

Comparison of Redis queues and MySQL stability: Why is Redis prone to data loss? Comparison of Redis queues and MySQL stability: Why is Redis prone to data loss? Apr 01, 2025 pm 02:24 PM

Comparison of Redis queues and MySQL stability: Why is Redis prone to data loss? In the development environment, using PHP7.2 and ThinkPHP frameworks, we often face the choice of cooperation...

When using Django and MySQL to process hundreds of thousands to one or two million pieces of data, what kind of cache solution should a 4-core 8G memory server choose? When using Django and MySQL to process hundreds of thousands to one or two million pieces of data, what kind of cache solution should a 4-core 8G memory server choose? Apr 01, 2025 pm 11:36 PM

Using Django and MySQL to process large data volumes When using Django and MySQL databases, if your data volume reaches hundreds of thousands to one or two million...

How to specify the database associated with the model in Beego ORM? How to specify the database associated with the model in Beego ORM? Apr 02, 2025 pm 03:54 PM

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

How to apply Debian Strings in a website How to apply Debian Strings in a website Apr 02, 2025 am 08:21 AM

This article discusses how to optimize website performance on Debian systems. "DebianStrings" is not a standard term and may refer to tools or technologies used in Debian systems to improve website performance. The following are some practical tips: 1. It is recommended to use the Pagoda panel to simplify the installation and configuration process for web server and PHP environment configuration. It is recommended to install Nginx1.22.1 as the web server, PHP8.2 as the script interpreter, and MySQL10.7.3-MariaDB as the database system. Be sure to enable the necessary PHP extensions, such as fileinfo, opcache, memcached, red

See all articles