Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > ServerTemplates > Archive > 11H1 > Tutorials > Load Balancer Setup

Load Balancer Setup

Objective

To create dedicated load balancer servers that will use HAProxy to send incoming client requests to one of the registered application servers in the load balancing pool.

Table of Contents

Prerequisites

  • This tutorial requires that you set up A records with your DNS provider, to allow clients to send requests to your load balancers. See Domain Setup.
  • The RightScale Load Balancer with Apache/HAProxy ServerTemplate discussed in this tutorial supports Amazon EC2 clouds only. 

Overview

php_diagram_1.gifIn order to create a high-availability load-balanced web server solution in the cloud, RightScale has published load balancer ServerTemplates that run HAProxy. This is a software load balancer with high reliability that automatically checks the health of your application and decides whether to forward traffic to a particular server based on these health checks. To provide extra functionality, we also run Apache in front of HAProxy, which allows you to serve static pages locally and establish SSL connections with only a slight increase in latency. To the right is a conceptual overview of the flow of user traffic. 

As you can see, user traffic comes in through Apache on port 80. Apache then decides which pages to serve directly and which pages to forward to HAProxy (on port 85 by default). Since HAProxy has a list of application servers and is constantly performing health checks, it knows which servers are available to handle requests. It then proxies these requests to an appropriate server. Once an application server receives the request, it generally communicates with the backend database.

 

 

This tutorial will show you how to set up the minimum deployment requirements for a "high availability" site. The setup consists of a redundant Master/Slave MySQL setup, a pair of dedicated load balancer servers, and two application servers.  See the diagram below for details.

diag-3tier-v1.png

Steps

Add Load Balancers to the Production Deployment

Go to Manage > Deployments.  Click on your "production" Deployment. 

Next, we will add two load balancer servers using the same ServerTemplate.  Go to Design > MultiCloud Marketplace > ServerTemplates. Import the latest "RightScale Load Balancer with Apache/HAProxy" ServerTemplate (RightScale is the publisher) so that a copy is saved in your RightScale account's 'Local' collection. (DesignServerTemplates)

Since these ServerTemplates are fairly straightforward in their configuration and typically do not need to be customized, you can use the ServerTemplate as-is to add servers to the Deployment.  When viewing the ServerTemplate, click the Add to Deployment button. 

Select into which cloud/region you want to launch the Server.

Next, select your "production" Deployment.  Since you're going to launch two load balancers in different availability zones for high-availability purposes, name the first load balancer something like my-lb1, select the same availability zone as your Master-DB, and select the first Elastic IP that you reserved earlier in the Create Elastic IPs (EIP) tutorial.  You can also select the same SSH Key and Security Group that you created in earlier steps.

For more information on adding a server, see the Add Server Assistant.

Although you could repeat this process to add the second load balancer server, an easier way would be to simply clone the first load balancer.  Click the nickname link of the first load balancer (e.g. my-lb1) and click the Clone button.

Change the following information on your cloned Server:

  • Rename the Server (e.g. my-lb2)
  • Change the Availability Zone so that it matches the zone of the Slave-DB (e.g. us east-1b)
  • Change the Elastic IP to use the second reserved EIP  (e.g. lb-2)


You should now have two dedicated Load Balancer Servers and two MySQL Database Servers in your Production Deployment.  Notice that both tiers are equally dispersed across multiple zones.

screen-ServerTab-v1.png

Define Inputs

Now you need to define the Input parameters for your Deployment.   Click on the deployment's Inputs tab.  As a best practice, we recommend defining Input parameters at the Deployment level. 

By defining Inputs at the Deployment level, you can view and define all Input parameters that need to be set for all Servers in your Deployment in one place.  Use the following guidelines to help you properly configure inputs. 

screen-InputCallouts-v1.png

  • View Input Types for descriptions of each type. (Ignore, Env, Text, Array, Cred, Key) 
  • View List of Environment Inputs to see an exhaustive list of all Environment Inputs ("Env").
  • As a general guideline to determine what Inputs you will need to edit:
    • ManageDeploymentsYourDeployment Inputs
    • Look over all the Inputs, paying particular attention to "unset" Inputs (although in some instances you may need to override values set at the ServerTemplate level).  See Inheritance of Inputs.
    • Input names preceded with "OPT_" usually indicate an optional Input, and you may be able to leave it blank.

Notice that most inputs already have default values that were set at the ServerTemplate level.  Inputs will be inherited from a ServerTemplate unless they are defined at the Deployment or Server level. 

When you are ready to set your Input values, click Edit.  Once you have configured all of the Inputs click Save.

Once again, most of the generic inputs have been defined for you at the ServerTemplate level.  However, there are a few new inputs that are user-specific and need to be defined at the Deployment level.  Use the input's hover text File:15-References/Tables/Dashboard_Icons/wiki_icon_info.gif to view its description and determine what value should be set.

Inputs

Name Input Type
Description
 APPLICATION Text/Cred

Sets the directory for your application's web files.  (/home/webapps/APPLICATION/current/)

e.g. myapp

 HEALTH_CHECK_URI Text/Cred

The URI of the health check page, used by HAProxy for checking whether the site is up or not.  You must create your own health check page, which returns an HTTP status of OK 200. The contents of the page are not important, but its name should be unique (preferably containing a random number). The same page is used for all application servers to determine whether the server is running (up). For example, if the page were http://www.mydomain.com:80/hlthchk378923.html, you would simply specify a HEALTH_CHECK_URI of: /hlthchk378923.html. (Note: Be sure to include the slash before the file name.) The page content could simply be the text: "OK."

If you do not have a health check page, select "ignore."

 LB_HOSTNAME Text/Cred

The fully qualified hostname of all the servers that have HAProxy installed on them for load balancing purposes. For example, if www.domain.com has two dedicated load balancers with HAProxy installed on them, you would enter www.domain.com as the LB_HOSTNAME. It is necessary that these hosts be registered with DNS with matching A Records so that the application servers will be able to connect to and disconnect from all the HAProxy servers and update their configuration files.

e.g. www.domain.com

 WEBSITE_DNS Text/Cred

The fully qualified domain name that the server will accept traffic for.

e.g. www.domain.com

 

Warning: If you want HAProxy to perform health checks on your web site, remember to include the health-check file in your application bundle. If you do not do this, you will receive errors similar to the following in your log file:  

"GET /health_check.jsp HTTP/1.0" 404 1003 "-" "-"

For more information on this, please see the Health Check Page.


Launch the Servers

Now that you've defined all of the required Input parameters, you are now ready to launch the Load Balancer Servers.  Since you defined all of the required inputs at the Deployment level, you can launch both of them at the same time. 

Go to the Deployment's Servers tab.  Check the Load Balancers and use the Launch action.

screen-LaunchLoadBalancers-v1.png

Next Steps

Now that you've set up your database and load balancing tiers, you can now set up a dedicated application tier.

See also

You must to post a comment.
Last modified
21:01, 16 May 2013

Tags

This page has no custom tags.

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.