22
High Availability MySQL Jui-Nan Lin (林瑞男) Apr. 2012

20120426 high availability MySQL

Embed Size (px)

Citation preview

Page 1: 20120426 high availability MySQL

High Availability MySQL�

Jui-Nan Lin (林瑞男) Apr. 2012 �

Page 2: 20120426 high availability MySQL

Agenda�

!  About Me !  Typical Architecture for Websites !  Why High Availability for databases? !  Degree of High Availability !  Approaches to high availability MySQL !  Our Choices !  Conclusion

Page 3: 20120426 high availability MySQL

About Me�

!  Jui-Nan Lin (林瑞男) !  Section Manager of R&D Team, R&D Dept. !  Operate MySQL for 4 years in PIXNET !  Twitter: @jnlin !  LinkedIn: jnlin !  Email: [email protected]

Page 4: 20120426 high availability MySQL

Typical Architecture (for websites) �

Page 5: 20120426 high availability MySQL

Why High Availability�

!  Hardware can fail, something can break – We have broken hardware every week in

PIXNET !  We need maintenance window

– Upgrade Operating System/MySQL server !  We don’t want to be called by our boss at

4am.

Page 6: 20120426 high availability MySQL

Our Target�

!  Fault Tolerant !  No SPOF (Single Point of Failure) !  Easy to add repaired node back !  Data Correctness !  Reduce Cost

– Human Resource – Hardware

Page 7: 20120426 high availability MySQL

Degree of High Availability�

!  Down Time – 90% uptime => 35 days down per year – 99% uptime => 4 days – 99.9% uptime => 8 hours – 99.99% uptime => 50 mins – 99.999% uptime => 5 mins�

Page 8: 20120426 high availability MySQL

Approaches to high availability MySQL�

!  Replication – Master and Slave !  DRBD !  Master-to-Master Replication !  MySQL Cluster�

Page 9: 20120426 high availability MySQL

Replication�

!   Idea: If master fails, promote one of slaves to master�

Page 10: 20120426 high availability MySQL

Replication – Concept�

Master

Slave Slave Slave Master

Fail

Promoted to master

Replication Replication

Replication

Page 11: 20120426 high availability MySQL

Replication – Pros and Cons�

!  Pros – Simple - MySQL feature

!  Cons – Data inconsistency

•  Incomplete transaction •  Replication delay

Page 12: 20120426 high availability MySQL

DRBD�

!  DRBD - Distributed Replicated Block Device – RAID 1 over the

network !  Relies on crash safe

storage engine and file system –  InnoDB and XFS

!  http://www.drbd.org/ �

Page 13: 20120426 high availability MySQL

DRBD – Concept�

Heartbeat

Active Standby

Heartbeat

Active

Fail

Page 14: 20120426 high availability MySQL

DRBD – Pros and Cons�

!  Pros – Reliable – Data Consistency

! Cros – Warm up problem

Page 15: 20120426 high availability MySQL

Master-to-Master Replication�

!  Databases to set master to each other. !  http://mysql-mmm.org/�

Page 16: 20120426 high availability MySQL

Master-to-Master Replication – Concept�

Writer Reader Writer/Reader

Fail Replication

Monitor

Healthy Check

Healthy Check

Monitor

Healthy Check

Healthy Check

Page 17: 20120426 high availability MySQL

Master-to-Master Replication – Pros and Cons�

!  Pros – No “Warm up” Problem – Better Resource Usage

!  Cons – Same as MySQL replication – Race condition

•  Solved by fixed writer node

Page 18: 20120426 high availability MySQL

Master-to-Master Replication – Pros and Cons�

!  Cons – Duplicated Key when use auto-increment

•  Solved by auto_increment_increment=2 and auto_increment_offset�

Page 19: 20120426 high availability MySQL

MySQL Cluster�

!  http://www.mysql.com/products/cluster/�

Page 20: 20120426 high availability MySQL

Failover time�

Approach� Time�

Replication� Fast�

DRBD� Slow�

Master-to-Master� Fast�

Page 21: 20120426 high availability MySQL

Our Choices�

!  DRBD for applications which require more consistency

!  Master-to-Master Replication for applications which require high performance

!  To evaluate cluster configuration in Q4�

Page 22: 20120426 high availability MySQL

Conclusion�

!  Evaluate a suitable solution – What degree of high availability do you need? – What applications do you run?

•  Web 2.0 Applications? Billing Data? Mobile Apps?

– How much budget do you have? !  Aim for what is reasonable for your needs �