July 12, 2010

High availability for MySQL on Amazon EC2 – Part 3 – Configuring the HA resources

Posted by Yves Trudeau |

This post is the third of a series that started here.

From the previous of this series, we now have two working EC2 instances that are EBS based. The first instance is the monitor, usually an m1.small type instance and the second instance is hamysql, a large instance type. So far, we have configured Heartbeat for communication between the nodes. Now, it is time to configure the HA resources in Pacemaker. Here are the requirements for the HA resources:

On Monitor

  • Kill the other instance
  • Free the share resources
  • Start a new hamysql instance
  • Reconfigure the clients
  • Give away the resources

On hamysql

  • Run MySQL
  • Monitor MySQL
  • Get out of way if MySQL is not running

From the above requirements, the resource we will create will need to have an "affinity" or preference to run on hamysql. This is accomplished by location directives. I chose to put a weight of 1000 to hamysql and 1 for monitor. Also the resource is obviously not doing the same thing on both hosts so I decided to use a resource of type anything which is just a script. Same script name and path on each host but different content. To configure Pacemaker, assuming both nodes are online, just performs these steps:

Place holders for the resources scripts
On each host:

CODE:
  1. root@monitor:~# touch /usr/local/bin/mysql
  2. root@monitor:~# chmod u+x /usr/local/bin/mysql

We will come back in the next posts to these scripts. Then, on one of the host:

CODE:
  1. root@monitor:~# crm_attribute -t crm_config -n stonith-enabled -v false
  2. root@monitor:~# crm_attribute --attr-name symmetric-cluster --attr-value false
  3. root@monitor:~# crm configure
  4. crm(live)configure# primitive mysql ocf:heartbeat:anything \
  5.                             params binfile="/usr/local/bin/mysql" pidfile="/var/run/heartbeat/mysql.pid" \
  6.                             op start interval="0" timeout="300s"
  7. crm(live)configure# location loc-1 mysql 1000: hamysql
  8. crm(live)configure# location loc-2 mysql 1: monitor
  9. crm(live)configure# commit

and that's it. We know have a resource which is just a shell script that will preferably run on hamysql but, if hamysql is not available, will be able to run on monitor. That's the basis we will expand on in the next posts.

Related posts: :High availability for MySQL on Amazon EC2 – Part 1 – Intro::High availability for MySQL on Amazon EC2 – Part 2 – Setting up the initial instances::Percona at PHP Quebec 09:
 

4 Comments »

  1. Yves, why use ocf:heartbeat:anything when you could just as well use ocf:heartbeat:mysql with “params binary=/usr/local/bin/mysql”, and actually get MySQL specific resource monitoring?

    Comment :: July 12, 2010 @ 9:49 am

  2. Florian, waits a bit, you’ll see why later. The mysql script manages instances, not mysql directly.

    Comment :: July 12, 2010 @ 10:25 am

  3. 3. Jimmy Soho

    I’m reading at quite a few places that HA doesn’t work with EC2, but this post suggests it does work. Curious about your next posts..

    Comment :: July 31, 2010 @ 1:36 am

  4. 4. Jimmy Soho

    For example, this article:

    http://agiletesting.blogspot.com/2009/02/load-balancing-in-amazon-ec2-with.html

    “You could use Linux-HA, or Wackamole and the Spread toolkit. However, this is not possible in Amazon EC2 because IP addresses cannot be shared among instances in the manner that heartbeat-type protocols expect.”

    Comment :: July 31, 2010 @ 1:37 am

 

Subscribe without commenting

Trackbacks/Pingbacks