MySQL High Availability
           Deep Dive

      Florian Haas (hastexo)
     Yves Trudeau (Percona)
HA Sprint: Get Prepared!

●   Tutorial instructions at: http://goo.gl/8ZLta
●   Follow along -- or just watch! (up to you)


If you need help: we're the guys with the blue
SPEAKER tabs, just holler!
About Us
Our virtual environment
An Overview
of the Linux HA stack
Application Interface   MySQL RA



Cluster Resource Mgmt   Pacemaker




Cluster Messaging       Corosync



Storage Replication
(optional)               DRBD
Physical           Physical
         Host               Host




        MySQL
        Master




MySQL   MySQL      MySQL    App        App
Slave   Slave      Slave   Server     Server
Physical           Physical
         Host               Host




                           MySQL
                           Master




MySQL   MySQL      MySQL    App        App
Slave   Slave      Slave   Server     Server
DRBD

      http://www.hastexo.com/knowledge/drbd
                                                 http://www.drbd.org


DRBD & the DRBD logo are registered trademarks of Linbit Information Technologies
Creating a DRBD resource

●   Name:           mysql
●   Device name:    /dev/drbd0
●   Backing disk:   /dev/pacemaker-1/lvMySQL
●   Meta data:      internal
●   Replication:    172.30.222.1 ↔ 2


●   Filesystem:       ext3
Corosync

http://www.hastexo.com/knowledge/corosync
                   http://www.corosync.org
Creating a Corosync Cluster

●   Enable secauth
●   1 ring
●   No logging to files, syslog only
●   Start Corosync
●   Check connectivity
●   Check membership
Pacemaker

http://www.hastexo.com/knowledge/pacemaker
                   http://www.clusterlabs.org
Create a Pacemaker Cluster

●   Add the “pacemaker” service to
    /etc/corosync.d
●   Use ver: 1
●   Restart corosync
●   Start pacemakerd
●   Verify both nodes have joined the cluster
    (crm_mon)
STONITH/Fencing
Setting up the cluster

●   Open the shell with crm configure
●   Set no-quorum-policy to ignore
●   Disable STONITH
    ○   Kids, don't do this at home!
●   Commit the configuration
Pacemaker Resources
Started




start             stop




        Stopped
Master/Slave Sets
Started                  Started




start             stop   start             stop




        Stopped                  Stopped
Master




                         promote             demote




         Slave                      Slave




start             stop    start               stop




        Stopped                    Stopped
Adding a DRBD Master/Slave Set

●   Create the DRBD primitive p_drbd_mysql
    ○   Use the ocf:linbit:drbd RA
    ○   Add 2 monitor operations
        (role=Master, role=Slave) with non-equal
        intervals
●   Wrap it in a master/slave set
    ○   notify=true, clone-max=2, master-max=1
●   Commit the configuration
●   Watch the cluster promote
Constraints
Creating a Filesystem

●   Add the Filesystem resource
    ○   Name:             p_fs_mysql
    ○   Device:           /dev/drbd0
    ○   Directory:        /var/lib/mysql
    ○   File system type:    ext3
●   Add required order & colocation
    constraints
Groups
Add a Group

●   Create the g_mysql resource group
●   Add p_fs_mysql and p_ip_mysql
Requirements for MySQL/DRBD

No MyISAM
log-bin
sync_binlog
Bind or No bind
innodb_log_file_size
innodb_auto_lru_dump /
innodb_buffer_pool_restore_at_startup
Add the MySQL resource

●   Run mysql_install_db
●   Create an ocf:heartbeat:mysql
    primitive p_mysql
●   Add resource level monitoring
●   Add it to the g_mysql group
●   Watch the constraints update
    automagically
●   Commit, Rejoice!
One more thing...
Physical           Physical
         Host               Host




                           MySQL
                           Master




MySQL   MySQL      MySQL    App        App
Slave   Slave      Slave   Server     Server
Physical           Physical
         Host               Host




                           MySQL
                           Master




MySQL   MySQL      MySQL    App        App
Slave   Slave      Slave   Server     Server
Physical                       Physical
                 Host                           Host




                MySQL
                Master       InnoDB Recovery




        Umm..                WTF?              Hurry up!




MySQL           MySQL        MySQL               App        App
Slave           Slave        Slave              Server     Server




                 Booooring
Physical           Physical
         Host              Host




        MySQL
        Master




MySQL   MySQL      MySQL        App      App
Slave   Slave      Slave       Server   Server
Handling MySQL replication

Read-only
Promotion of the master
Attaching slaves
Monitoring slave state
Demotion
Promote MySQL1
                              Notify Slaves
                                Final State
                              Start resources
                               Initial state


                      RVIP1
                      RVIP1                         Write master info
                      RVIP2
                      WVIP         MySQL1           set readerOK
                      RVIP3                         enable writer VIP
                      WVIP                          Turn Off Read-only
                               Start MySQL
                               --skip-slave-start




                         master_host = MySQL1
                         master_log_file=file1
                         master_log_pos=1
RVIP2                                                                    RVIP3


   MySQL2                                                          MySQL3


Read CIB
Start MySQL
Monitor                                                         Start MySQL
                                                                Read CIB
                                                                Monitor
Start Slave
--skip-slave-start
Update master score                                             --skipe-slave-start
                                                                Start slave
                                                                Update master score
Update readerOK
Update readerOK                                                 Update readerOK
Promotion failure
                               Failover finalMySQL2
                                 Master of state


                      RVIP1
                      WVIP         MySQL1




     Fencing




                          master_host = MySQL1
                                         MySQL2
RVIP2                     master_log_file=file12
                          master_log_file=file1
                          master_log_pos=123
                          master_log_pos=1
                                                             RVIP1
RVIP2
WVIP                                                         RVIP3
                                                              RVIP3


   MySQL2                                                MySQL3


Write master info
Monitor                                               Stop slave
                                                      Monitor
set readerOK
Update master score                                   read CIB Master info
                                                      Update master score
enable readerOK
Update writer VIP                                     Start salve
                                                      Update readerOK
Turn Off Read-only
Setup

MySQL Grants
Node IP attribute
MySQL primitive
VIP primitive
Master-slave ms resource
Location rules
Colocation rules
Order rule
Variation on the theme

Slave only nodes
How to add slave nodes
Setup with no VIP
Avoid cluster collapse
Further Information

                  http://www.clusterlabs.org
                         http://www.drbd.org
http://www.suse.com/products/highavailability
                    http://www.hastexo.com
Liked this talk?

●   Go to www.hastexo.com/shoutbox
●   Log in
    (you can just use your OpenID from
    Wordpress, Blogger, Yahoo, Google Apps,
    Google Profile)
●   Leave us a message!

MySQL High Availability Deep Dive

  • 1.
    MySQL High Availability Deep Dive Florian Haas (hastexo) Yves Trudeau (Percona)
  • 2.
    HA Sprint: GetPrepared! ● Tutorial instructions at: http://goo.gl/8ZLta ● Follow along -- or just watch! (up to you) If you need help: we're the guys with the blue SPEAKER tabs, just holler!
  • 3.
  • 4.
  • 5.
    An Overview of theLinux HA stack
  • 6.
    Application Interface MySQL RA Cluster Resource Mgmt Pacemaker Cluster Messaging Corosync Storage Replication (optional) DRBD
  • 7.
    Physical Physical Host Host MySQL Master MySQL MySQL MySQL App App Slave Slave Slave Server Server
  • 8.
    Physical Physical Host Host MySQL Master MySQL MySQL MySQL App App Slave Slave Slave Server Server
  • 9.
    DRBD http://www.hastexo.com/knowledge/drbd http://www.drbd.org DRBD & the DRBD logo are registered trademarks of Linbit Information Technologies
  • 10.
    Creating a DRBDresource ● Name: mysql ● Device name: /dev/drbd0 ● Backing disk: /dev/pacemaker-1/lvMySQL ● Meta data: internal ● Replication: 172.30.222.1 ↔ 2 ● Filesystem: ext3
  • 11.
  • 12.
    Creating a CorosyncCluster ● Enable secauth ● 1 ring ● No logging to files, syslog only ● Start Corosync ● Check connectivity ● Check membership
  • 13.
  • 14.
    Create a PacemakerCluster ● Add the “pacemaker” service to /etc/corosync.d ● Use ver: 1 ● Restart corosync ● Start pacemakerd ● Verify both nodes have joined the cluster (crm_mon)
  • 15.
  • 16.
    Setting up thecluster ● Open the shell with crm configure ● Set no-quorum-policy to ignore ● Disable STONITH ○ Kids, don't do this at home! ● Commit the configuration
  • 17.
  • 18.
    Started start stop Stopped
  • 19.
  • 20.
    Started Started start stop start stop Stopped Stopped
  • 21.
    Master promote demote Slave Slave start stop start stop Stopped Stopped
  • 22.
    Adding a DRBDMaster/Slave Set ● Create the DRBD primitive p_drbd_mysql ○ Use the ocf:linbit:drbd RA ○ Add 2 monitor operations (role=Master, role=Slave) with non-equal intervals ● Wrap it in a master/slave set ○ notify=true, clone-max=2, master-max=1 ● Commit the configuration ● Watch the cluster promote
  • 23.
  • 24.
    Creating a Filesystem ● Add the Filesystem resource ○ Name: p_fs_mysql ○ Device: /dev/drbd0 ○ Directory: /var/lib/mysql ○ File system type: ext3 ● Add required order & colocation constraints
  • 25.
  • 26.
    Add a Group ● Create the g_mysql resource group ● Add p_fs_mysql and p_ip_mysql
  • 27.
    Requirements for MySQL/DRBD NoMyISAM log-bin sync_binlog Bind or No bind innodb_log_file_size innodb_auto_lru_dump / innodb_buffer_pool_restore_at_startup
  • 28.
    Add the MySQLresource ● Run mysql_install_db ● Create an ocf:heartbeat:mysql primitive p_mysql ● Add resource level monitoring ● Add it to the g_mysql group ● Watch the constraints update automagically ● Commit, Rejoice!
  • 29.
  • 30.
    Physical Physical Host Host MySQL Master MySQL MySQL MySQL App App Slave Slave Slave Server Server
  • 31.
    Physical Physical Host Host MySQL Master MySQL MySQL MySQL App App Slave Slave Slave Server Server
  • 32.
    Physical Physical Host Host MySQL Master InnoDB Recovery Umm.. WTF? Hurry up! MySQL MySQL MySQL App App Slave Slave Slave Server Server Booooring
  • 33.
    Physical Physical Host Host MySQL Master MySQL MySQL MySQL App App Slave Slave Slave Server Server
  • 34.
    Handling MySQL replication Read-only Promotionof the master Attaching slaves Monitoring slave state Demotion
  • 35.
    Promote MySQL1 Notify Slaves Final State Start resources Initial state RVIP1 RVIP1 Write master info RVIP2 WVIP MySQL1 set readerOK RVIP3 enable writer VIP WVIP Turn Off Read-only Start MySQL --skip-slave-start master_host = MySQL1 master_log_file=file1 master_log_pos=1 RVIP2 RVIP3 MySQL2 MySQL3 Read CIB Start MySQL Monitor Start MySQL Read CIB Monitor Start Slave --skip-slave-start Update master score --skipe-slave-start Start slave Update master score Update readerOK Update readerOK Update readerOK
  • 36.
    Promotion failure Failover finalMySQL2 Master of state RVIP1 WVIP MySQL1 Fencing master_host = MySQL1 MySQL2 RVIP2 master_log_file=file12 master_log_file=file1 master_log_pos=123 master_log_pos=1 RVIP1 RVIP2 WVIP RVIP3 RVIP3 MySQL2 MySQL3 Write master info Monitor Stop slave Monitor set readerOK Update master score read CIB Master info Update master score enable readerOK Update writer VIP Start salve Update readerOK Turn Off Read-only
  • 37.
    Setup MySQL Grants Node IPattribute MySQL primitive VIP primitive Master-slave ms resource Location rules Colocation rules Order rule
  • 38.
    Variation on thetheme Slave only nodes How to add slave nodes Setup with no VIP Avoid cluster collapse
  • 39.
    Further Information http://www.clusterlabs.org http://www.drbd.org http://www.suse.com/products/highavailability http://www.hastexo.com
  • 40.
    Liked this talk? ● Go to www.hastexo.com/shoutbox ● Log in (you can just use your OpenID from Wordpress, Blogger, Yahoo, Google Apps, Google Profile) ● Leave us a message!