high availability solutions with mysql
DESCRIPTION
MySQL replication MySQL cluster DRBD/HeartBeat/MySQL Shared DiskTRANSCRIPT
![Page 1: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/1.jpg)
<Insert Picture Here>
Copyright Oracle 2010
Решения высокой надежности и
производительности для MySQL
Александр Рубин
Principal Consultant
![Page 2: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/2.jpg)
5 девяток
9 9 9 99
35 days 4 days 50 mins 5 mins8 hours
Unmanaged
Replication
Technologies
Clustering
Technologies
Clustering &
Geographical
Redundancy
software upgrades
hardware upgrades
maintenance operations
software failures
network failures
power
failures
disasters
Well-Managed
hardware failures
Small
Business
ISPs &
Mainstream
Business
Data
Centers
Banking
Medical
Telco
Military
Defense
%.
![Page 3: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/3.jpg)
Scale-Up vs. Scale-Out
• Более производиельный сервер (Scale-Up)
• Vertical
• Дорогие сервера
• Сложный апгрейд
• Больше серверов (Scale-Out)
• Horizontal
• Обычные сервера (как в Google)
• «Просто добавь сервер»
Low Cost
Hig
h C
os
t
![Page 4: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/4.jpg)
Репликация в MySQL
Web/App
Server
Web/App
Server
Writes & Reads
MySQL Master
I/O
Thread
SQL
Thread
Writes
relay
binlog
MySQL Slave
mysqld
data
index &
binlogs
mysqld
databinlogReplication
![Page 5: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/5.jpg)
Распределение нагрузки (Scale-Out)
Master Server Slave Server
Writes
Index &
Bin Log
Rotation
Writes
MySQL Replication
Reads
Possible Roles• Fail over server
• Used for performing backups
• Read/Write load balancing
• Additional slaves allow Scale-Out
BackupsBackups
Writes & Reads
Web/App
Server
Web/App
Server
![Page 6: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/6.jpg)
Отказоустойчивость (Fail Over)
Master Server Slave Server
Writes
Index &
Bin Log
Rotation
Writes
MySQL Replication
Reads
Possible Roles• Fail over server
• Used for performing backups
• Read/Write load balancing
• Additional slaves allow Scale-Out
BackupsBackups
Web/App
Server
Web/App
Server
Manual
Fail Over
X
X
X
Fail Over
![Page 7: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/7.jpg)
Linux Heartbeat, DRBD & MySQL
= Private IP =
10.10.10.21
Active Server Passive Server
= Private IP =
10.10.10.20
Primary DRBD Secondary DRBDDRBD
Linux Heartbeat= Virtual IP =
10.10.10.10
Web/App
Server
Web/App
Server
![Page 8: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/8.jpg)
= Private IP =
10.10.10.21
Active Server Passive Server
= Private IP =
10.10.10.20
DRBDPrimary DRBD Secondary DRBD
X
X
Active
Primary DRBD
X
Linux Heartbeat= Virtual IP =
10.10.10.10
Web/App
Server
Web/App
Server
Linux Heartbeat, DRBD & MySQL
![Page 9: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/9.jpg)
Кластер (MySQL Cluster)
MySQL
Server
MySQL
Server
Data
Node
Data
Node
Data
Node
Data
Node
NDB
Storage Engine
Management
Server
Management
Server
NDB APINDB API
MySQL Cluster
Data
Node
Data
NodeData
Node
Data
Node
MySQL
Server
MySQL
Server
MySQL
Server
MySQL
Server
Management
Server
Management
Server
MySQL
Server
MySQL
Server
MySQL
Server
MySQL
Server
![Page 10: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/10.jpg)
Архитектура данных в кластере
• Four Data Nodes
• Two Replicas
• Two Node Groups
8ChinaBeijing8
2NorwayOslo7
4RussiaMoscow6
2GreeceAthens5
9JapanTokyo4
-5USANew York City3
2GermanyBerlin2
2DenmarkCopenhagen1
UTCCountryCapitalID
8ChinaBeijing8
2NorwayOslo7
4RussiaMoscow6
2GreeceAthens5
9JapanTokyo4
-5USANew York City3
2GermanyBerlin2
2DenmarkCopenhagen1
UTCCountryCapitalID
Partition 1
Partition 2
Partition 3
Partition 4
Data
Node
Data
Node
P1-Primary
P2-Secondary
P1-Secondary
P2-Primary
Data
Node
Data
Node
Node Group 1
Data
Node
Data
Node
P3-Primary
P4-Secondary
P3-Secondary
P4-Primary
Data
Node
Data
Node
Node Group 2
![Page 11: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/11.jpg)
Отказоустойчивость
MySQL
Server
MySQL
Server
Data
Node
Data
Node
Data
Node
Data
Node
NDB
Storage Engine
Management
Server
Management
Server
NDB APINDB API
MySQL Cluster
Data
Node
Data
NodeData
Node
Data
Node
MySQL
Server
MySQL
Server
MySQL
Server
MySQL
Server
Management
Server
Management
Server
MySQL
Server
MySQL
Server
MySQL
Server
MySQL
ServerXX X
X
XX
![Page 12: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/12.jpg)
Решения
• Репликация Master/Slave
• Slaves только для чтения
• Master<->Master
• Репликация типа «кольцо» (ring)
• DRDB HA
• DRBD Master и Read Only Slaves
• Master to Master Cross Datacenter + DRDB
• Шардинг (Sharding)
• Шардинг + DRDB + Geo Redundancy
![Page 13: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/13.jpg)
ТопологияMaster > Slave
Masters > Slave (Multi-Source)
Master < > Master (Multi-Master)
Master > Slaves
Circular (Multi-Master)
Master > Slave > Slaves
![Page 14: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/14.jpg)
Решение: Репликация Master/Slave
• Преимущества– Чтение с любого сервера
– распределение нагрузки
– Простота установки– Отказоустойчивость ~99.9% (3 девятки)
• Недостатки: Асинхронная репликация (!)– Slave может не получить изменения вовремя– Записываем, читаем записанное со Slave –
Oooops!– Запись – ТОЛЬКО на Master
Master SlaveAsynchronous
MySQL
Replication
![Page 15: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/15.jpg)
Решениe: Master и много Slaves
• Master может иметь много Slaves
• Чтение данных (select) – 4-5 девяток (HA)
• Распределение нагрузки – чтение с любого slaves
• Увеличилась нагрузка – добавим Slave
• Сложные запросы (отчеты) – гоняем на Slave
• Backup
Master
Slave 1 Slave 4
Slave 3Slave 2
![Page 16: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/16.jpg)
Репликация Master-Master
• Преимущества• Чтение с любого сервера• Простота установки• Отказоустойчивость (осторожно!)• Надежность на уровне ~99.9%
• Недостатки• Нет распределения нагрузки для записи• При отказе – потеря транзакций!
Master 1 Master 2
![Page 17: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/17.jpg)
Pattern: Ring Replication
• Недостатки
– Легко ломается – сложно востановить данные
– Запись на Master 4 придет после записи на Master
3
• Не рекомендуется
Master 1 Master 3
Master 2 Master 4
Asynchronous
MySQL
Replication
![Page 18: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/18.jpg)
Решение: DRBD и Slaves для
чтения
• Отказоустойчивость для Master
• Чтение с любого Slave
• Slave автоматически пере-подключаются после
сбоя мастера
Hot Primary Warm SecondarySynchronous
DRBD
Replication
Master Pair
![Page 19: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/19.jpg)
DRBD и балансировка нагрузки
![Page 20: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/20.jpg)
Географическая отказоустойчивость
![Page 21: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/21.jpg)
Sharding (Шардинг)
Shard A Shard B Shard DShard C
![Page 22: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/22.jpg)
Шардинг с DRBD
![Page 23: High Availability Solutions with MySQL](https://reader034.vdocuments.mx/reader034/viewer/2022051210/54c9017b4a7959963a8b45a6/html5/thumbnails/23.jpg)
The presentation is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.