Transcript
Page 1: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

MySQL HA Solutions Keeping it simple, kinda!

By: Chris Schneider MySQL Architect

Ning.com

1

Page 2: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

What we’ll cover today  High Availability Terms and Concepts

  Levels of Availability

 What technologies are there for MySQL High Availability

  Examples of how different levels of availability are implemented

 How we leverage High Availability

2

Page 3: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

HA Overview   High Availability is the availability of a system or

service despite hardware failures   When you think of HA you think of five nines

(99.999%)   A lot of companies are ok with three nines (99.9%)

  Two ways to gain High Availability   Redundant hardware and software   Commercial software

3

Page 4: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

HA Terms   Continuous Availability  No disruption of service during failover

  Single point of failure  Can one part of a system bring the whole

system down

  Failover and or Failover Situations

  Service Level Agreement (SLA)

4

Page 5: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Scaling Up   Vertically scaling your hardware

  Bigger, better, faster, stronger!

  Cost of Scaling up

  Maintaining Vertical Scale

  Two Example Companies who specialize in Vertical Scale   Schooner – Schoonerinfotech.com

  Fusion I/O Fusionio.com

B i gg e r

H a r d w a r e

5

Page 6: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Scaling Out   Scaling out Horizontally is what

you see in most Web 2.0 companies today

  Commodity hardware  Dell, HP, SUN (Oracle) – 1U – 4U

servers

  Add servers or shard for increase capacity and or performance

nX

N1

N …

6

Page 7: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Scaling Out – Tier Approach

b1

b2

bX

a1

a2

aX

• It’s FREE, Scale Out • Open source software • CentOS • MySQL • DRBD + Heartbeat • MySQL Cluster

7

Page 8: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Synchronous vs. Asynchronous Replication

  Synchronous   Asynchronous

Node1

Node2

Node1

Node2

WWW WWW

Both Nodes at the same time

Node1 first, then Node2

8

Page 9: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Lower Levels of Availability  Available - Single Node

 Availability – Unmanaged Replication  Master/Slave

 More Availability – Managed Replication with possible third-party software  Master/Slave  Heartbeat or Keepalived

9

Page 10: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Higher Levels of Availability  Even More Availability – Managed Multi-

Master  Hot Standby or Passive Master  Replication with custom and or third party

software

 High Availability – DRBD

 High Availability – MySQL Cluster

10

Page 11: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Levels of Availability

11

Page 12: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

The Nines’ of Uptime in Downtime

 The NINES in Downtime per Year  90.000% = 35 Days  99.000% = 4 Days  99.900% = 8 Hours  99.990% = 50 Minutes  99.999% = 5 Minutes

 Measurements  By Node, Cluster, System, Data Center?

12

Page 13: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Unmanaged Replication   Where most Web 2.0 companies start

  A lot of risk   Low end, non-redundant hardware

  Asynchronous One Way Replication

  One Master server   Write and Reads

  One Slave server   Just sits there

  No automated Break-Fix   Manual intervention for everything

Master

Slave

13

Page 14: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Managed Replication   Production Ready but not the best

  Less risk   Higher end, redundant hardware

  Asynchronous One Way Replication   One Master server

  Writes and Read   One Slave server

  Possible reads   Backups   ETL Processes

  Automated Break-Fix   Fully Monitored

Master

Slave

14

Page 15: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Replication Failovers   Unmanaged Replication

  Excessive Customer Downtime   Manual process that involves multiple teams or

individuals   Rebuilding the old master server after failover   Hard to keep everything straight at 3am

  Managed Replication   Excessive Customer Downtime   Rebuilding the old master server after failover   Hard to keep straight at 3am

15

Page 16: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Multi-Master/Hot Standby   One Master server

  Reads and writes   Possible backups - Xtrabackup   Mk-query-digest

  One Hot Standby server   Read activity   Backups - MySQLDump   ETL

  Asynchronous Two Way Replication   Automated Break-Fix   Semi-Automated or Fully Automated Failover

  Keepalived with a floating IP (VIP)

Master

Hot Standby

16

Page 17: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Rack 2 Rack 1

Multi-Master/Hot Standby

  Redundant hot swappable hardware   NICs: two, 2 port

Bonded   Disks (RAID 10)   Power Supply

  Redundant Switches   Different Racks   Different UPS   Mk-Query-Digest

Master Hot Standby

Switch 2 Switch 1

Replication

UPS 2 UPS 1

Read/Write Read

17

Page 18: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

What’s Important in Multi-Master/Hot Standby

  Redundant hardware   Eliminating single point of failure is crucial

  Bidirectional Replication   Read-only can be set on Hot Standby Server

  Keepalived   VIP is attached to the Master server   The application talks to the VIP for WRITES

  Mk-Query-Digest

  Xtrabackup

18

Page 19: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Keeping Cache Hot / Ensuring Data Integrity

  Mk-query-digest (Keeping Hot Standby Cache HOT)   Takes read activity on the Master server and runs it on the

Slave server   This keeps the caches on the Slave server hot

  Mk-table-checksum (Data Integrity)   Perform an online replication consistency check, or

checksum MySQL tables efficiently on one or many servers   Be sure to use the –replicate flag

  Mk-table-sync (Data Integrity)   Synchronize MySQL tables efficiently   This tool changes data, so for maximum safety, you should

back up your data before you use it

19

Page 20: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Keepalived – VIP Management   Not the only solution but works great for this example

  You should also look at:   Heatbeat   MySQL Proxy   HA Proxy

  Use Keepalived for:   Hardware failures   Kernel panics   Custom monitoring script to detect InnoDB corruption or

other MySQL problems

  Plus, the probability of both servers experiencing a catastrophic failure are remote

20

Page 21: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Keepalived – VIP Management   We want single, one way failover to prevent VIP flapping

(happens in odd cases) and to maintain data integrity   Priority of servers

  Both nodes are set up with the same priority in the keepalived.conf file for ONE way failover

  Master   state BACKUP   priority 100

  Slave   state BACKUP   priority 100

  Priority could cause problems when in a Master / Backup configuration

21

Page 22: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Multi-Master Replication Manager for MySQL (MMM)   Great set of scripts if you don’t want to build your own from

scratch   No keepalived needed   No custom monitoring script for MySQL

  Will perform monitoring, failover and management of MySQL master-master replication (with only one node writable at any time)

  Read balance standard master/slave configurations   Can handle 1 to many slave servers in a cluster   Moves VIP around read servers if they are behind

  Requires at least two MySQL hosts and one monitoring host

  Agent Based monitoring

22

Page 23: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Leveraging HA Failovers   A real world example on how multi-master can help

  Altering a table or multiple tables

  Large tables (5GB to over 100GB)

  Limited amount of allotted customer facing downtime, less than 5 minutes

  Problems with the above situation   If you’ve ever tried to run ALTER table on a 100GB table I

bet it never finished

  Do you have enough disk space

  InnoDB Table Space growth and fragmentation

  How much customer downtime do you have to play with

23

Page 24: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Schema Change – Large tables   Example Process (Very loose process)

  Stop replication   Run an alter or full dump out and reload on the slave server

  With ALTER you may or may not want to specify set sql_log = 0;   With a dump out and reload you should use the following two

features:   SELECT INTO OUT FILE

  LOAD DATA INFILE

  NOTE: Make sure you dump out by Primary key order

  Fail the VIP over   Depending on how you ran the schema change you’ll either:

  Start replication

  Run the same change on the FORMER Master server

24

Page 25: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Process Benefits   The customer will only see seconds of downtime if

any at all   The downtime will be during the VIP failover   Make sure to run this during off peek

  If you choose to use the dump out and reload method   Defragmentation   InnoDB Table Space will not grow out of control

  Disk space could be regained

25

Page 26: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Replication Challenges   Single Threaded

  Bottle Neck

  Asynchronous   Master, then Slave

  Can break in a lot of ways   Duplicate Key   Max Allowed Packet   Replication can fall behind

  Can be unreliable

Master

Slave

IO Thread

SQL Thread

Binary.log

Relay.log

26

Page 27: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

DRBD – Overview   Components Needed for Success

  MySQL, Heartbeat and DRBD

  Distributed Storage

  Synchronous Replication

  No special networking components like HBA’s needed

  Great Performance (Block vs Statement)

  Manages inconsistencies of data during a failure

  Streamlines many recovery actions

  Automated IP failover and management of VIPs through Heartbeat

27

Page 28: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

DRBD – Diagram

Active Server

Passive Server

Synchronous Block Level Replication

Cross-Over

VIP Management Over LAN

NOTE: Heartbeat needs multiple paths to avoid a split brain scenario

NOTE: Two, 2-port gigabit Ethernet cards on each node

WWW

28

Page 29: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

DRBD Failover

DOWN Active Server

VIP Management Over LAN

X

X

WWW

29

Page 30: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Re-syncing Data After Failure

Passive Server

Active Server

Data Re-Sync

VIP Management Over LAN

DRBD

NOTE: No interruption of services during data re-sync

WWW

30

Page 31: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Scaling out with DRBD   DRBD replicates an entire block device

  This includes Master information   binary logs

  Slaves can attach to the Virtual IP Address managed by Heartbeat

  MySQL Replication allows the slaves to continue with the new Active machine as their master with no intervention needed

31

Page 32: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Scaling Out with DRBD

Active Server

Passive Server

Synchronous Block Level Replication

Cross-Over

VIP Management Over LAN

WWW

MySQL MySQL MySQL

32

Page 33: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

MySQL Cluster Pros   Redundant nodes provide service when components fail   Eliminate single points of failure with redundant hardware

  Multiple network connections   SAN or RAID storage

  Share nothing storage   Automatic data failover built in   Synchronous Replication   Transactional   Online Backups   Easy node addition   No VIP failover required   Automatic resynchronization of Data   Scale up and Scale out made easy

33

Page 34: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

MySQL Cluster Cons   Geographical redundancy through MySQL

replication (Asynchronous)   Can be a single point of failure

  In Memory data storage   Does not work well for large datasets

  Complex normalized schemas with JOIN don’t do well

34

Page 35: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Node Group1 Node Group2

MySQL Cluster Diagram

API API

Mgmt

NDB

Management Server - Arbitrator

SQL Nodes MySQL Servers/NDB API Server

Data Nodes NDB NDB NDB

MySQL MySQL

WWW

35

Page 36: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

When to use MySQL Cluster   High Availability is a MUST have

  Very large amount of update and selects

  Mostly searching on a Clustered Index

  Fast failover and crash recovery is needed

  Geographical redundancy is needed or will be needed

36

Page 37: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

When NOT to use MySQL Cluster

  As a replacement for another storage engine, MyISAM or InnoDB

  When caching would work better (not a replacement for Memcached)

  When you have complex Schemas with a lot of JOINS

  When you have large data sets

37

Page 38: MySQL HA Solutions - Ningapi.ning.com/files/uazetnZo93ds-bzkg8VfluTRq*gRsskzlaDGrMm7pRpn… · MySQL HA Solutions Keeping it simple, ... 17 . What’s Important ... Moves VIP around

Questions??   My Information:

  Chris Schneider   [email protected]

38


Top Related