To create a basic Rails deployment using RightScale's Rails FrontEnd ServerTemplate.
Table of Contents
The tutorial will show you how to configure a 4-instance setup with two loadbalanced frontends and a redundant MySQL database backend. After you have completed this initial setup, we will show you how to customize your deployment to fit your particular needs.
In order to create a high-availability loadbalanced webserver solution on EC2 we have created front-end ServerTemplates that run HAProxy. This is a high-reliability software load balancer 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 into your application through Apache on port 80. Apache 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 setup the minimum deployment requirements for a high availability site. The setup consists of a redundant Master/Slave MySQL setup and a pair of loadbalanced frontends that also serve as application servers. See the diagram below for details.
Note: Ignore the revisions of the ServerTemplates and scripts in the screenshots below. As a best practice, always import the latest revision of the specified component that's available in the MultiCloud Marketplace for a given Compatibility Release (e.g. 11H1).
The first step is to import the ServerTemplate that you're going to use to configure your Front End Servers.
Go the RightScale Component MultiCloud Marketplace. (Design -> MultiCloud Marketplace) Find and import the most recent version of the "Rails Front End" ServerTemplate to your account's 'Local' collection.
By default, the ServerTemplate is designed to pull your application code from an SVN repository. However, you can use a different script to pull your application code from a tarball stored in an S3 bucket. Depending on the script that will be used to retrieve your application, different inputs will need to be defined.
Go to the ServerTemplate that you're going to use to create your Servers and click the Add to Deployment button.
Select the cloud where the Server will be launched. (e.g. AWS US-East)
For high availability purposes you should have two Front End Servers across two different availability zones. The easiest way to create another Front End Server is to simply clone the first one that you just created.
Click on the nickname link of the Front End Server that you just created. Click the Clone button.
Change the following information on your cloned Server:
You should now have four Servers in your Production Deployment. The Deployment now has all two tiers spread across two different availability zones for failover and recovery purposes. For example, if there is a failure in one zone, you still have a running server of each tier running in another zone.
If you chose to use a cloned ServerTemplate that you modified to create the Front End Servers, you may notice that you're using Server that are using HEAD versions. It's useful to use HEAD versions for development and test purposes. However, once you deploy Servers in a production environment, you should always commit the ServerTemplates and use static "locked down" revisions.
As a best practice, you should define these missing inputs at the Deployment level so that these same values will be inherited by any additional Application Servers that are launched in the Deployment or Server Array.
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.
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.
Use the input's hover text to view its description and determine what value should be set.
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.
Now that you've defined all of the required Input parameters, you are now ready to launch the 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 Front End Servers and use the Launch action.
© 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.