High Availability with MySQL
-
Upload
thavamuni -
Category
Technology
-
view
113 -
download
1
description
Transcript of High Availability with MySQL
![Page 1: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/1.jpg)
THAVA ALAGU
Staff Engineer, Database Group,
Sun Microsystems, Bangalore
http://blogs.sun.com/thava/
Oct 2008
HIGH AVAILABILITY WITH MYSQL
![Page 2: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/2.jpg)
Welcome !Welcome !
2
![Page 3: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/3.jpg)
LET US DISCUSS ABOUT …
Aspects of High AvailabilityAspects of High AvailabilityMySQL ReplicationMySQL ReplicationMySQL ClusterMySQL ClusterApplication HAApplication HAResourcesResources
3
![Page 4: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/4.jpg)
ARCHITECTURE OVERVIEW
4
![Page 5: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/5.jpg)
HIGH AVAILABILITY
Data Must Not be LostData + Application Must be
Available Always
5
![Page 6: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/6.jpg)
MYSQL SOLUTIONS …
MySQL Replication (Asynchronous)
MySQL Cluster (Synchronous)
Supporting Solutions: MySQL Proxy (Alpha) MySQL Load Balancer (Based on Proxy) 3rd Party Solutions from Partners and Others
6
![Page 7: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/7.jpg)
MYSQL REPLICATION HIGHLIGHTS
Binary Log Updates From Master Applied at Slave
Usually One Master Multiple Slaves Asynchronous Copy Slave could be used as Read-Only Geographically Distributed, Slow Links, OK Can be chained –
Master Slave/Master Slave
7
![Page 8: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/8.jpg)
MYSQL REPLICATION BENEFITS
Hot Standby Node for Fail-Over Can be Used for transparent Backups Load Balancing – Slaves Can be Active for Read Automated copy across geographically
distributed sites
8
![Page 9: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/9.jpg)
REPLICATION ARCHITECTURE
9
![Page 10: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/10.jpg)
REPLICATION TECHNIQUES AND TIPS
10
![Page 11: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/11.jpg)
REPLICATION NOTES
Binary logs rotated every 1GB You should clean/purge old logs Master/Slave similar architecture
11
![Page 12: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/12.jpg)
REPLICATION FORMATS
3 Types:Statement Based ReplicationRow-based ReplicationMixed Based Replication
Depends on MySQL Version, Storage Engine
Can override the defaults e.g. use row-format=row option
Usually row based replication is saferBut exceptions exist
12
![Page 13: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/13.jpg)
REPLICATION FOR BACKUPS
Slave can be shutdown for Cold Backup Logical or File System backups Backup Logs too Logs can be used for Point-In-Time Recovery
13
![Page 14: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/14.jpg)
REPLICATE ACROSS STORAGE ENGINES
Slave can be ARCHIVE Engine Insurance against SE specific failuresFaster Slave with No Transaction Engine
e.g. InnoDB to MyISAMHow:
Use storage_engine system variable Mysqldump; edit; reload Stop slave; Alter table …; Start Slave Disable some storage engines at Slave Create new tables with default engine
14
![Page 15: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/15.jpg)
REPLICATE FOR SCALING
Use Multiple Slaves For Read Load Dedicate Master for Write Load Perfect for Load Balancing
15
![Page 16: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/16.jpg)
REPLICATE SELECTIVELY
Filter at Slave – Database, Tables, specify in my.cnf replicate-wild-do-table=sales.% replicate-wild-do-table=finance.%
Master Filters: binlog-do-db, binlog-ignore-db
16
![Page 17: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/17.jpg)
REPLICATE MULTILEVEL
Less Load at MasterCan Use Blackhole Engine for Master2Use log-slave-updates option at Master2
17
![Page 18: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/18.jpg)
MULTIMASTER (AVOID)
2 Masters updating each otherRing of MastersUpdates on disjoint setsUsually, Stay Away
18
![Page 19: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/19.jpg)
REPLICATION TOPOLOGIES SUMMARY
19
![Page 20: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/20.jpg)
REPLICATE USING SSL
For High SecurityUses Certificate-Authority Certificate,
Server Public Key, Server Private Key
20
![Page 21: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/21.jpg)
REPLICATION SETUP UPGRADE
Upgrade Slaves First, Then MasterShutdown, Upgrade, RestartWatch out Versions Upgradability
21
![Page 22: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/22.jpg)
REPLICATION COMMANDS
On Master: Show master status Flush logs Show master logs Show binlog events Purge master logs to ‘mysql-bin.005’;
22
On Slave: Change Master To master_host=‘hostA’ master_user=‘slave’
master_password=‘slavepassword’ ;
Show slave status
Load Data From Master ; # MyISAM only. Locks Tables on master
![Page 23: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/23.jpg)
REPLICATION FAILOVER
Does not happen automaticallyMany solutions exist like virtual IP, Sun
Cluster, Linux-HA Heartbeat, etcApplication should retry
23
![Page 24: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/24.jpg)
MYSQL CLUSTER HIGHLIGHTS
Synchronous Ultra High AvailabilityThink Telecom, Banking Memory (mostly) and Disk basedNo Single Point Of FailureAutomatic Failover
24
![Page 25: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/25.jpg)
MYSQL CLUSTER ARCHITECTURE
25
![Page 26: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/26.jpg)
MYSQL CLUSTER NODEGROUP
26
![Page 27: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/27.jpg)
MYSQL CLUSTER SIMPLE CONFIG
27
![Page 28: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/28.jpg)
MYSQL CLUSTER NOTES
ACID transactions Supports READ COMMITTED only Synchronous replication uses 2 Phase Commit Local and Global Checkpoints to disk Data access through SQL or NDB API Online Backups supported All nodes same architecture – big endian or little endian
28
![Page 29: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/29.jpg)
MYSQL CLUSTER NOTES (CONTD)
Max number of data nodes = 48; Max(data nodes + management nodes )=63 Max total number of all = 256 (including SQL nodes) Tables highly recommended to have primary keys for
cluster replication.
29
![Page 30: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/30.jpg)
MYSQL CLUSTER CONFIGURATION
NDB config File = config.ini Number Of Replicas : 1 upto 4 [ usually 2 ] Memory Sizing
Per Node Memory = (DataSize * Replicas * 1.1) / Nodes
Default Port number for Mgmt Node = 2202 Default Port Number for Data Node = 1186
SQL Node Config File = my.cnf [mysqld] ndbcluster ndb-connectstring=mgmt-hostname
30
![Page 31: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/31.jpg)
NODE FAILURE DETECTION
Uses Heartbeats Failed Node Excluded Node taken over by another in same node group Failed node tries to repair itself and then joins
cluster
31
![Page 32: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/32.jpg)
NETWORK PARTITIONING
Also Called Split Brain condition 2 Sets of Nodes Diverges with writes Management node acts as arbitrator by default Nodes with maximum votes survive
32
![Page 33: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/33.jpg)
CLUSTER CHECKPOINTS
Transactions Commits in memory Local checkpoint writes all node data and UNDO
log written to disk; old REDO logs can be deleted Global Checkpoint: Frequency controlled by
TimeBetweenGlobalCheckpoints (default 2000 millisecs)
33
![Page 34: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/34.jpg)
CLUSTER COMMANDS
ndb_mgmd –f config.ini # start management daemon ndbd --connect-string=mgmt_hostname # start data node mysqld_safe & # Start SQL node ndb_mgm -c mgmt_hostname –e “show” mysql> show engine ndb status;
34
![Page 35: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/35.jpg)
CLUSTER ROLLING UPGRADE/DOWNGRADE
Online Upgrae/Downgrade supported. Shutdown node, replace binary, bring it up One node at a time in this order:
Management Node(s) Data Nodes SQL Nodes
Watch out for upgradability/downgradbility of versions
35
![Page 36: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/36.jpg)
REPLICATING CLUSTERS
36
Note: Row-based logging must be enabled for this to work
![Page 37: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/37.jpg)
ANOTHER HA SOLUTION:DISTRIBUTED REPLICATED BLOCK DEVICE
Available on Linux. Provides synchronous data copy. Uses virtual block device Replicated from primary server to secondary Implemented with kernel level and user level software Often used with Heartbeat Linux Cluster manager Secondary server is passive – Not for load balancing Like RAID but software based
37
![Page 38: High Availability with MySQL](https://reader034.fdocuments.in/reader034/viewer/2022051515/54c6478a4a7959ee4e8b4579/html5/thumbnails/38.jpg)
RESOURCES …
Developer Zone: Developer Articles, etc. http://dev.mysql.com
MySQL White Papers http://www.mysql.com/why-mysql/white-papers/
MySQL Forums: http://forums.mysql.com
Planet MySQL – Blog aggregator http://planetmysql.org
38