Home Database Mysql Tutorial MySQL Cluster的高可用性

MySQL Cluster的高可用性

Jun 01, 2016 pm 01:31 PM
mysql reliability network

bitsCN.com

MySQL Cluster的高可用性 - 1

 

使用mysql cluster,能达到99.999的高可靠性,在这一章节,主要介绍一些基本概念:

 

Network Partitioning

在一个mysql集群中,如果几个节点之间网络出问题了,mysql cluster能决定哪些节点应该继续提供服务。比方有两个Node Group共四个节点:SN1, SN2,SN2, SN4。

 

SN1和SN2在Node Group1, SN3和SN4在Node Group2。如果{SN1, SN3}与{SN2, SN4}失去联系,那么他们中的任何两个都拥有完整数据,都能对外提供服务。为了数据完整性,我们必须隔离一半。根据配置,一个或者几个管理节点能够提供仲裁,帮助我们选择哪一对节点继续存活。假如我们配置了两个管理节点(MGM1, MGM2)都能提供仲裁服务,我们要避免以下这样的配置:

 

路由器1: MGM1, SN1, SN3

 

路由器2:   MGM2, SN2, SN4

 

如果你有这样配置,路由器1与路由器2之间出了问题,而MGM1, MGM2都能仲裁,那么有可能两边都在对外提供服务。结果你懂的。

 

Synchronous Replication: 同步复制。

这比较好理解,在同一个Node Group内部,事务提交为two-phase commit,而且是同步的。每个数据节点内的数据都同步复制到另一个节点上。MySQL Cluster 配置通常至少有 2 个全部数据的副本,存放在不同主机上。为避免整体系统故障,系统会根据可配置的频率在磁盘上定期保存事务日志和检查点文件。如果某个节点发生故障,至少有另一个数据节点存储着相同的信息。

 

 注意:同步复制只是内存的复制,对于mysql cluster来说,他可能还没有写到硬盘(与Checkpoint和Redo, UNDO log相关)。如果同一个Node Group同时下电,那么我们就可能丢数据。Mysql cluster的数据一致性是说我们几乎没有两个节点同时over,所以我们进行部署时最好不要同一个Node Group的data node在同一个机架。

 

Failure Detection 错误检测。

通常有两种错误,communication loss 和 heartbeat failure。一是通讯丢失,可以通过tcp,共享内存等方式在各存储节点之间通讯来侦测节点是否正常这种方式是最快的故障检测方式,

 

二是心跳失败,通讯丢失的检测方法在某些特殊情况下无效,例如磁盘故障等问题.所有的存储节点通过组成一个环路,每个节点向下一个节点发送心跳信号,如果下一个节点没有收到心跳信号,则认为上一个存储节点故障,并依次向下下个节点广播此故障信息

 

Logging:

正常情况下,不管什么类型的数据库,都会有日志,它包含所有的insert/update/delete。在系统出现故障的时候我们用它来辅助恢复数据库。

 

Local Checkpoints:

Redo log是一个环形日志文件,随着数据库的操作,redo log也在增长,如果不及时清理的话,log空间很快就会用光,我们需要及时地把snapshot image写到disk,然后把redo log的tail指针向前挪。NoOfFragmentLogFiles用来控制redo log的大小,TimeBetweenLocalCheckpoints控制cluster local checkpoint的频率。这儿的Time并不指时间,而是指操作的个数,它是以指数形式增长的,比方20是4M的写操作,但是21就是8M。

 

MySQL Cluster的高可用性

 

Global Checkpoints:

Mysql cluster是一个in-memory数据库,为了性能的关系,事务都是先同步到内存,然后后面写log。GlobalCheckpoints就是每隔一段时间TimeBetweenGlobalCheckpoints,我们把一组提交的事务写到disk。Global Checkpoint就是定时将Redo log写到disk。

 

Global Checkpoint是写Redo log,Local Checkpoint是截Redo log的尾。

 

Local check需要时间,为了能够恢复的时候LCP image与LCP开始时间完全一致,mysql cluster引入Undo log。

 

MySQL Cluster的高可用性
MySQL Cluster的高可用性

 

System Recovery 系统恢复:

当恢复的时候,LCP image是LCP stop点的数据,我们执行undo log使系统回退到LCP start点。然后执行Redo log到Global checkpoint点。

 

MySQL Cluster的高可用性

 

跨地域复制 — 跨地域复制使节点能镜像到远程数据中心以便进行灾难恢复

 

 

限制

 

不支持磁盘上的持续提交。提交将被复制,但不保证在提交时会将日志写入磁盘。

 

不能在线增加或舍弃节点(此时必须重启簇)
 

bitsCN.com
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)

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to set up MySQL connection pool using PHP? How to set up MySQL connection pool using PHP? Jun 04, 2024 pm 03:28 PM

Setting up a MySQL connection pool using PHP can improve performance and scalability. The steps include: 1. Install the MySQLi extension; 2. Create a connection pool class; 3. Set the connection pool configuration; 4. Create a connection pool instance; 5. Obtain and release connections. With connection pooling, applications can avoid creating a new database connection for each request, thereby improving performance.

How to delete data from MySQL table using PHP? How to delete data from MySQL table using PHP? Jun 05, 2024 pm 12:40 PM

PHP provides the following methods to delete data in MySQL tables: DELETE statement: used to delete rows matching conditions from the table. TRUNCATETABLE statement: used to clear all data in the table, including auto-incremented IDs. Practical case: You can delete users from the database using HTML forms and PHP code. The form submits the user ID, and the PHP code uses the DELETE statement to delete the record matching the ID from the users table.

See all articles