Heartbeat is a tool for providing a high availibility resource (http, mysql, etc) from a set of two or more servers. You want heartbeat if:
- You need high availability
- Moving requests from one server to a hot spare at any point is acceptable in your application
We use this at Rails Machine for providing a hot spare for single points of failure, like software load balancers.
This Moonshine plugin allows you to easily integrate heartbeat into your deployment.
- script/plugin install git://github.com/railsmachine/moonshine_heartbeat.git
- Configure settings in config/moonshine.yml (see Configuration below)
- Invoke the recipe(s) in the Moonshine manifest for your high availaibility resource recipe :heartbeat
A basic heartbeat setup with two haproxy servers would look something like this in moonshine.yml
:heartbeat: :resources: :haproxy1: 184.108.40.206 :nodes: :haproxy1: 220.127.116.11 :haproxy2: 18.104.22.168 :password: sekret
The resources key is a hash of preferred nodes and the resources that these nodes provide. In this case, we have two servers, haproxy1 and haproxy2. haproxy1 is the preferred (or primary) node. In this case, the resource that the primary node should present is an IP address - 22.214.171.124.
- The name of the preferred node must match the output of uname -n on that server.
- All nodes below must have their firewall configured to allow incoming traffic on the ip address specified for the preferred node.
The nodes key is a hash of two or more nodes that will selected from to provide the high availibility resources specified in the resources hash. Their ip address is required here to setup heartbeat pings between them.
- The name of the each node must match the output of uname -n on that server.
The password is a simple key used for each heartbeat server to authenticate with each other.
You'd then point your DNS to the high availibiltiy resource that heartbeat monitors - 126.96.36.199. If haproxy1 goes down, haproxy2 will take over this IP and continue serving requests. When haproxy1 comes back up, it'll take back the high availibility IP.
Some examples of more custom configuration follow:
:heartbeat: :resources: :haproxy1: - 188.8.131.52 haproxy god :nodes: :haproxy1: 184.108.40.206 :haproxy2: 220.127.116.11 :password: sekret :deadtime: 10 :warntime: 5 :initdead: 20 :interface: eth1 :udpport: 6009 :auto_failback: no :ping: 18.104.22.168
Please see the "heartbeat wiki"[http://wiki.linux-ha.org/ha.cf] for more more information on these advanced config options.
This plugin defaults to UDP ucast heartbeats because we've found them to be the most reliable. There is experimental (untested) support for mcast - see the ha.cf template on Github for details
Unless otherwise specified, all content copyright © 2014, Rails Machine, LLC