Skip to content

Latest commit

 

History

History
125 lines (96 loc) · 5.88 KB

File metadata and controls

125 lines (96 loc) · 5.88 KB

RightScale Apache/HAProxy Load Balancer Cookbook

DESCRIPTION:

This cookbook is available at https://github.com/rightscale/rightscale_cookbooks.

This is RightScale's load balancer cookbook for Apache/HAProxy.

This cookbook provides recipes for setting up and running an Apache/HAProxy load balancer server as well as recipes for attaching and detaching application servers to and from load balancers. There is also support for automatically detecting and reconfiguring when an application server has disappeared or reappeared without attaching itself.

DETAILS:

The load balancer and application server attach/detach recipes are designed so the servers can locate each other using RightScale machine tags. The load balancer servers have tags of the form "loadbalancer:<pool_name>=lb" where 'pool_name' is the name of the pool that the application servers are associated with; the application server attach and detach recipes use this machine tag to request that corresponding handler recipes are run on the matching load balancers when they need to attach or detach. The application servers have tags of the form "loadbalancer:<pool_name>=app", "server:uuid=", and "loadbalancer:backend_ip=<IP_ADDRESS>" where 'pool_name' is the same pool name, UUID is a unique string that identifies the server, and IP_ADDRESS is the IP address of the server; the automatic detection recipe for the load balancer servers use these tags to find which application servers are currently available. This mechanism was chosen to support machines in multiple availability zones where in the case of failures, load balancers and application servers may start while some machines, including RightScale, are not reachable and thus the configuration cannot be fully determined. For this reason, the automatic detection recipe is configured to run every 15 minutes by default.

REQUIREMENTS:

  • Requires a virtual machine launched from a RightScale managed RightImage

SETUP:

By default load balancer has only one pool called "default", which act as a default pool for all application servers which has "loadbalancer::app=default" tag. To setup multiple pools configuration, lb/pools input value must be overridden with comma-separated list of URIs or FQDNs for which the load balancer will create server pools to answer website requests. Last entry will be the default backend and will answer for all URIs and FQDNs not listed in lb/pools input. Any combination of URIs or FQDNs or web root relative path can be entered.

Application servers can provide any numbers of URIs or FQDNs to join corresponding server pool backends.

USAGE:

Application Server Attach

do_attach_request

This recipe is used by application servers to request that load balancer servers configure themselves to attach to the application server. It requests that servers with the "loadbalancer:<pool_name>=lb" tag run the corresponding 'handle_attach' recipe. The recipe sends the server's IP address and instance UUID as parameters to the remote recipe.

handle_attach recipes

This recipe is used by the load balancer servers to reconfigure HAProxy and reload it, if necessary, when an application server requests to be attached. It uses the IP address and instance UUID parameters it receives from the 'do_attach_request' recipe called on the application server to construct an individual configuration file in the haproxy.d directory with the instance UUID as the file name. If the file didn't exist before or if its contents change, the main HAProxy configuration information and all of the files in the haproxy.d directory are concatenated into the HAProxy configuration file and HAProxy is restarted.

Application Server Detach

do_detach_request

This recipe is used by application servers to request that load balancer servers configure themselves to detach from the application server. It request that servers with the "loadbalancer:<pool_name>=lb" tag run the corresponding 'handle_detach' recipe. The recipe sends the server's IP address and instance UUID as parameters to the remote recipe.

handle_detach recipes

This recipe is used by the load balancer servers to reconfigure HAProxy and reload it, if necessary, when an application server requests to be detached. It uses the instance UUID parameter it receives from the 'do_attach_request' recipe called on the application server to delete the corresponding file from the haproxy.d directory which has the instance UUID as its file name. If the file was deleted, the main HAProxy configuration information and all of the remaining files in the haproxy.d directory are concatenated into the HAProxy configuration file and HAProxy is restarted.

Automatic Server Detection

do_attach_all recipe

This recipe is used by the load balancer to automatically detect if application servers have disappeared or reappeared without detaching or reattaching using the other recipes. This recipe is set to run in the periodic reconverge which defaults to a period of 15 minutes between runs. It uses the "loadbalancer:<pool_name>=app", "server:uuid=", and "loadbalancer:backend_ip=<IP_ADDRESS>" tags to get a list of all of the application servers that are currently available and uses the list to create, update, or delete individual server configuration files in the haproxy.d directory depending on their current status. If any of the files in the haproxy.d directory have been created, changed, or deleted, the main HAProxy configuration and the new set of files in the haproxy.d directory are concatenated into the HAProxy configuration file and HAProxy is restarted.

KNOWN LIMITATIONS:

There are no known limitations.

LICENSE

Copyright RightScale, Inc. All rights reserved. All access and use subject to the RightScale Terms of Service available at http://www.rightscale.com/terms.php and, if applicable, other agreements such as a RightScale Master Subscription Agreement.