MySQL高可用架構對比分析 頂 原

1、概述

MySQL是一個非常好的開源數據庫,它的歷史最早可以追溯到1979年,詳細歷史就不在這裏介紹了。自從越來越多的行業客戶用上MySQL來跑生產,MySQL高可用的問題就凸顯出來的,在傳統商業數據庫解決方案中,Informix的HDR、IBM Db2的HADR、Oracle的Dataguard都能保證有一個物理上數據分佈相同的熱備的功能,而MySQL卻沒有這種解決方案。 但是MySQL的開放性給出了無限的可能性。

2、市面上常用的解決方案

2.1 官方的異步與半同步方案

2.1.1 異步複製方案

官方的解決方案最大的優點就是結構簡單、方便搭建;缺點很明顯,同步的時候丟數據的概率非常高,如果在同步的時候主庫掛掉,沒辦法保證備庫的一致性。單個事務的同步如下圖所示:A transaction received by the master is executed, written to the binary log, then committed, and a response is sent to the client application. The record from the binary log is sent to the relay logs on Slave 1 and Slave 2 before the commit takes place on the master. On each of the slaves, the transaction is applied, written to the slave's binary log, and committed. The commit on the master and the commits on the slaves are all independent and asynchronous.

2.1.2 半同步複製方案

針對以上缺點,官方又推出了一個半同步的方案,進一步降低的同步過程中丟數據的概率,但是在某些情況下仍然存在丟數據的可能性。如下圖所示: A transaction received by the master is executed and written to the binary log. The record from the binary log is sent to the relay logs on Slave 1 and Slave 2. The master then waits for an acknowledgement from the slaves. When both of the slaves have returned the acknowledgement, the master commits the transaction, and a response is sent to the client application. After each slave has returned its acknowlegement, it applies the transaction, writes it to the binary log, and commits it. The commit on the master depends on the acknowledgement from the slaves, but the commits on the slaves are independent from each other and from the commit on the master.

2.2 MySQL集羣方案

MySQL Cluster 由一組計算機構成,每臺計算機上均運行着多種進程,包括 MySQL 服務器,NDB Cluster的數據節點,管理服務器,以及專用的數據訪問程序。 由於MySQL Cluster架構複雜,部署費時(通常需要DBA幾個小時的時間才能完成搭建),而依靠 MySQL Cluster Manager 只需一個命令即可完成,但 MySQL Cluster Manager 是收費的。並且業內資深人士認爲NDB 不適合大多數業務場景,而且有安全問題。因此,使用的人數較少。

MySQL Cluster

2.3 MySQL+DRBD方案

DRBD是應用級別的磁盤IO同步工具,Linux新版本內核提供了一個鉤子,每一次IO都通知到DRBD,然後DRBD將該IO同步至備機,並且返回ACK,主機纔會認爲該IO操作完成。所以MySQL+DRBD的方案優點就是數據可以保證完全的一致,缺點則是犧牲了MySQL的擴展性以及極大的降低了磁盤IO的性能。

MySQL+DRBD

2.4 Mariadb Galera Cluster方案

Mariadb是MySQL的一個變種,由原MySQL之父主導的項目。官方介紹這種方案是完全的同步複製多主方案,好處就是能夠完全保證數據的一致性,壞處就是整個集羣的性能受限於性能最差的節點。同時該解決方案在國內還較少,支持力度有限。

galera_small

3、總結和思考

MySQL的無法提供一個適合所有場景的高可用方案,需要結合不同的應用場景和應用習慣來選擇合適的高可用方案。

針對強一致性而又需要保留一定擴展性的應用場景,暫時還沒找到合適的高可用解決方案。

參考資料

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章