mysql ha - heinlein-support.de · percona xtrabackup: konsistente backups ohne downtime. 7 mysql ha...

39
MySQL HA Lösungen für Front- und Backend Matthias Klein

Upload: others

Post on 24-Jul-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

MySQL HALösungen für Front- und Backend

Matthias Klein

Page 2: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

2

MySQL HA – About InnoGames

About InnoGames

● Betreibt und entwickelt Browser- und Mobile Games seit 2007 für über 200 Millionen Spieler

● Mehr als 400 Mitarbeiter aus über 30 Nationen sind an den Standorten Hamburg und Düsseldorf tätig

Page 3: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

3

MySQL HA – About Me

About Me

● Seit 2009 als Administrator in der Gaming Industrie tätig● Zuständig für das Payment System● Ansprechpartner für MySQL, Mail, ELK

Page 4: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

4

MySQL HA - Topics

Backend2

Grundsätzliches1

Frontend3

Migrationspfade4

Page 5: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

5

MySQL HA - Grundsätzliches

Was ist eigentlich...

● HA: High Availability – Im Idealfall ist es uns egal, was ausfällt● Frontend: Die Schnittstelle unserer Datenbank(en) zu unserer App● Backend: Unsere Datenbanken

Page 6: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

6

MySQL HA - Grundsätzliches

Sysadmins Helferlein

● Percona toolkit: pt-online-schema-change für DDL● Percona Xtrabackup: konsistente Backups ohne Downtime

Page 7: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

7

MySQL HA - Grundsätzliches

Flavours of MySQL

Page 8: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

8

MySQL HA - Grundsätzliches

MySQL != InnoDB

● MySQL unterstützt unterschiedliche Engines, die jeweils ihre eigenen Vor- und Nachteile haben

● InnoDB ist eine sehr gute „All Purpose“ Engine

Page 9: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

9

MySQL HA - Grundsätzliches

MySQL Engines - MyISAM

● Text Indizes● Schnelle SELECTs● Nicht transaktionssicher● neigt zur Selbstzerstörung

Page 10: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

10

MySQL HA - Grundsätzliches

MySQL Engines - Blackhole

● Null device● Sehr nützlich bei der klassischen Replikation

Page 11: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

11

MySQL HA - Grundsätzliches

MySQL Engines - Archive

● Automatische Kompression● Unterstützt ausschließlich INSERT / REPLACE / SELECT● Ein SELECT verursacht immer einen full table scan

Page 12: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

12

MySQL HA - Backend

Klassische Replikation

● Verfügbar seit 2001● Asynchrones Verfahren● Wird häufg optimiert und erhält neue Features

Page 13: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

SlaveMaster

13

MySQL HA - Backend

Klassische Replikation - Funktionsweise

MySQL binlog relay log MySQL

Page 14: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

14

MySQL HA - Backend

Klassische Replikation – Features

● Replikationsketten und -ringe sind möglich (Master – Master, Intermediate Master)

● Unterschiedliche Filterregeln auf Master und Slave● Unterschiedliche Engines auf Master und Slave● Unterschiedliche Datenbank- / Tabellennamen auf Master und Slave

Page 15: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

15

MySQL HA - Backend

Klassische Replikation – Klassische Probleme

● Slave Lag → slave_parallel_workers● binlog_format STATEMENT / MIXED / ROW● Binlog Positionen bei Slave Promotion → GTID / Master - Master● Aufsetzen eines Slaves bei laufendem Produktivbetrieb →

Percona Xtrabackup● Schreiben auf mehreren Hosts

Page 16: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

16

MySQL HA - Backend

ndb cluster

● Verfügbar seit 2001● Synchrones Verfahren● Multi Master, Auto Sharding, (fast) ohne SpoF● In-Memory und/oder On-Disk

Page 17: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

17

MySQL HA - Backend

ndb cluster - Funktionsweise

managementmanagement

sql / apisql / api

datadata datadata

Page 18: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

18

MySQL HA - Backend

ndb cluster - Funktionsweise

data data data data

A B C D

A A‘ B B‘

CC‘ DD‘

Page 19: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

19

MySQL HA - Backend

ndb cluster - Nachteile

● Durch die Architektur sind bestimmte Operationen extrem teuer (z.B. join / group by / limit), wird aber stetig optimiert.

● Verursacht sehr hohe Netzwerkauslastung, ein dediziertes >= 1Gb/s Netzwerk für die data nodes ist ratsam

Page 20: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

20

MySQL HA - Backend

Galera Cluster / MySQL Group Replication

● Virtuell Synchrones Verfahren● Multi Master ohne Sharding● Automatische Synchronisation neuer Nodes mit dem Cluster● Es wird eine ungerade Anzahl nodes benötigt (Split Brain)

Page 21: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

21

MySQL HA - Backend

Galera Cluster / MySQL Group Replication

● Bootstrap für den ersten Node nötig (Wichtig, wenn alles kaputt ist)● „Single Primary Mode“ empfehlenswert● Galera ist besser bei WAN-Replikation● Galera hat den Vorteil des früheren Starts, MySQL kann seine Lösung

besser ins System integrieren

Page 22: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

22

MySQL HA - Backend

Galera Cluster / MySQL Group Replication - Funktionsweise

Page 23: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

23

MySQL HA - Backend

Galera Cluster / MySQL Group Replication - Unterschiede

● Bei Konfikten liefert Galera einen „Deadlock“ zurück● Gruppenkommunikation bei Galera über Totem Single Ring,

MySQL über Paxos → Galera wird mit mehr nodes langsamer● Arbiter gibt es bei MySQL (noch) nicht

Page 24: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

24

MySQL HA - Backend

Was soll ich wählen?

Kommt drauf an:● Ich muß sharden: ndb cluster● Ich habe große Writesets (>128k/row, >1GB total):

klassische Replikation● Ich möchte ein robustes System: Cluster

Page 25: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

25

MySQL HA - Frontend

Warum Frontend HA?

node1 node2

Applikation

Applikation

Page 26: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

26

MySQL HA - Frontend

Frontend HA - Möglichkeiten

● „Virtuelle“ IPs mit Manager (mmm, mha, orchestrator)● Proxy / Loadbalancer (ProxySQL, haproxy, testtool)

Page 27: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

27

MySQL HA - Frontend

Virtuelle IPs - Funktionsweise

● Zur Laufzeit wird die IP, auf die die Applikation sich verbindet, auf einen Datenbankhost gebunden

● Im Fehlerfall wird diese IP auf einen anderen Host gebunden● Problem: Trennen bestehender Verbindungen (mmm)● Problem: Es darf nur einen Manager geben → StandBy möglich

Page 28: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

28

MySQL HA - Frontend

MySQL-Multi-Master-Monitor (mmm)

Page 29: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

29

MySQL HA - Frontend

Master High Availability Manager (mha)

● Wird jetzt wieder weiterentwickelt● Kann jetzt auch GTID und IPv6 ● Bringt eigene Tools zum Monitoring und Failover mit● Output ist mit Nagios nutzbar● Klare Empfehlung für eine einfache Lösung ohne SchnickSchnack

Page 30: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

30

MySQL HA - Frontend

Orchestrator

● Unter ständiger Entwicklung● Nettes Frontend zum Monitoring und Management ● Scripts / Tools zum Failover müssen selbst erstellt werden● Auto Discovery von hosts

Page 31: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

31

MySQL HA - Frontend

ProxySQL

● Hat Failover nur als Nebenefekt, muß mit anderen Tools vervollständigt werden (z.B. keepalived)

● Query Caching● Query Routing● Query Firewall

Page 32: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

32

MySQL HA - Frontend

haproxy

● Monitoring Scripte müssen selbst erstellt werden (Beispiele vorhanden), werden meist über xinetd getriggert

● Eigener Failover wird über keepalived realisiert● Ist für Galera / Group Replication geeignet● Probleme mit Permissions in der Datenbank möglich (TCP-Forward)

Page 33: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

33

MySQL HA - Frontend

Loadbalancing mit pf (Eigenentwicklung)

● Loadbalancer mit Failover (BGP) sind schon vorhanden● Tool zur Steuerung von pf wird schon lange für Webserver

eingesetzt● Scripte für MySQL (xinetd) müssen selbst erstellt werden

Page 34: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

34

MySQL HA - Frontend

Was soll ich wählen?

Kommt drauf an:● Cluster: haproxy oder Eigenlösung● Klassische Replikation: mha oder orchestrator● Ich brauche ProxySQL features: ProxySQL + keepalived

Page 35: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

35

MySQL HA - Migration

Migrationspfade

● Im Frontend relativ einfach, da● Tools zum IP Management besitzen einen „observer“ Modus● Bei Proxy / Loadbalancer kann die Applikation umgestellt werden

● Im Backend nur dann ohne Downtime, wenn das binlog schon an ist

Page 36: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

36

MySQL HA - Migration

Binlog Positions zu GTID

● In MySQL 5.7 online möglich● In MySQL 5.6 (Percona) über Zwischenschritte online möglich:

● gtid_mode=ON; gitd_deployment_step=ON; auf den slaves● Einen Slave mit gtid_mode=ON; gitd_deployment_step=OFF; zum

Master promoten● Restliche Server auf gtid_mode=ON; gitd_deployment_step=OFF;

stellen

Page 37: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

37

MySQL HA - Migration

Asynchron zu Synchron (und zurück)

● Die Replikationsarten lassen sich mischen● Das Zielsystem wird komplett (mit den Daten) aufgesetzt

und läuft als Slave mit (Master – Master für mutige)● Switch erfolgt über das Frontend

Page 38: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

NOCH FRAGEN?

Page 39: MySQL HA - heinlein-support.de · Percona Xtrabackup: konsistente Backups ohne Downtime. 7 MySQL HA - Grundsätzliches Flavours of MySQL. 8 MySQL HA - Grundsätzliches MySQL != InnoDB

VIELEN DANK FÜR EURE AUFMERKSAMKEIT!

@innogames /innogames /innogames

[email protected]

INNOGAMES IS HIRING:

WWW.INNOGAMES.COM

INNOGAMES @GITHUB:

WWW.GITHUB.COM/INNOGAMES