In this tutorial you will customize a RightScale ServerTemplate to build your own LAMP (Linux Apache MySQL and PHP/Perl/Python or other Programming language) server.
Table of Contents
For best results, use Firefox, IE8+ or Chrome. The Dashboard no longer supports IE6-7.
This tutorial will help you understand the basics of our pre-built ServerTemplates and other assets. It will also explain how to take full advantage of these benefits by cloning and customizing RightScale ServerTemplates. The key benefits are that ServerTemplates help you get up and running quickly, while also giving you the flexibility to clone and customize them so that you can reuse and leverage all the pre-existing assets. There is no reason to "reinvent the wheel" so to speak.
RightScale offers several ServerTemplates that are publicly available to all users. Since you cannot make changes to these public ServerTemplates directly, you'll first have to import the ServerTemplate locally to your Rightscale account, then clone it and customize it accordingly. These public ServerTemplates are an excellent way to get a head start instead of trying to build your own ServerTemplate from scratch.
In this example we will customize one of the LAMP ServerTemplates to launch a basic LAMP server on Amazon's EC2.
Note: ServerTemplates are cloud-agnostic. You can use the same ServerTemplate to launch instances into multiple clouds or AWS regions. In this tutorial, you will launch an instance in the AWS US-East region.
Let's take a closer look at what's already inside the LAMP ServerTemplate.
Notice the list of boot, operational, and decommission scripts. The default version of the ServerTemplate is designed to load an application and a MySQL dump from an S3 bucket. You can also retrieve the file from another location by specifying a URL by using a different type of script, which we will create later on in this tutorial. In this tutorial you are going to change how the web server is going to retrieve its database dump file and application code by replacing a couple of the boot scripts with Rightscripts that you're going to create.
Now you can customize the cloned ServerTemplate to satisfy our needs by adding, removing, and rearranging RightScripts.
We will be modifying the ServerTemplate so that you can specify the URL of a specific web application and a MySQL dump file that you want to load.
You'll need to create two new RightScripts that do the following:
#!/bin/bash -e cd /tmp wget $DUMP_GZIP_URL -O dump gunzip -c dump | mysql
Click the Save action button when ready.
#!/bin/bash -e ## Check if optional application root is specified if [ -z "$OPT_WWW_DOCUMENT_ROOT" ]; then content_dir="/home/webapps/$APPLICATION/current" else content_dir=$OPT_WWW_DOCUMENT_ROOT fi mkdir -p $content_dir cd /tmp #get application tarball from S3 wget $APP_TAR_URL -O app #install applicaton tar -xzf app -C $content_dir
The script above does the following:
Click the Save action button when ready.
Now you need to add the new RightScripts to the cloned ServerTemplate and then remove/reorder some of the other RightScripts.
First we want to add the new RightScripts that we just created: "get and apply phptest db" and "get and apply phptest app."
Select the Add Script action button again and repeat the process for the second RightScript.
To rearrange the order of RightScripts, use the up/down arrow icon next to the boot RightScript of choice and simply drag and drop it into place.
Since we are performing the same actions as two existing scripts on this template, we also want to remove the following two RightScripts:
To access the database, you will need to grant access to a user. Instead of entering a username/password in plain text, RightScale has developed a Credential store to safely hold your passwords. Let's create two credentials for the DB username and password. The "Value" field is where you enter your username or password.
Repeat the process, but this time create a second credential named DBAPPLICATION_USER and enter app_user for the value.
You now have two credentials that will be used in order to access the database.
The ServerTemplate is designed to create regular backups of the database and save them as gzip files to an S3 bucket that you specify using the DB_MYSQLDUMP_BUCKET input. To create an S3 bucket, go to Clouds > AWS Global > S3 Browser and click on the New Bucket action button, then provide a Bucket Name and Location e.g., 'myname-db'
Now we are ready to configure the Input parameters.
Now you will define values for these Inputs at the ServerTemplate level. By defining these values at the ServerTemplate level, any servers that are created with this version of the ServerTemplate will inherit these values.
Fortunately, a lot of the Inputs have already been set, but since you just added two new RightScripts, there are a couple of Inputs that need to be set with the correct value.
Note:
Edit the following inputs accordingly:
Input Name | Input Type | Value |
APPLICATION | Text | Provide an arbitrary name for your application. (e.g. myapp) |
APP_TAR_URL | Text | Enter http://support.rightscale.com/@api/deki/files/5257/testapp.tgz However, you could use this script to similarly pull the application code from another location on the web. e.g., http://www.site.com/app.tgz |
DBAPPLICATION_PASSWORD | Cred | cred: DBAPPLICATION_PASSWORD Or if you don't want to use the Credential you could also use:
Text: app_password |
DBAPPLICATION_USER | Cred | cred: DBAPPLICATION_USER Or if you don't want to use the Credential you could also use:
Text: app_user |
DB_MYSQLDUMP_BUCKET | Text | This ServerTemplate is currently designed to save continuous backups of the database to an S3 bucket. Provide the name of an S3 bucket to store backups in e.g., mybucket-db. |
DB_MYSQLDUMP_PREFIX | Text | Defines the prefix that will be used to name the backups of the database e.g., mydb Backups of the database will be saved to the specified S3 bucket specified in the DB_MYSQLDUMP_BUCKET Input. The prefix will be used to name the backup file accordingly e.g., mydb-timestamp.gz |
DB_SCHEMA_NAME | Provide the following database schema name:
text: world | |
DUMP_GZIP_URL | Text | text: http://downloads.mysql.com/docs/world_innodb.sql.gz However, you could use this script to similarly pull the application code from another location on the web. (e.g. http://www.site.com/db.gz) |
WEBSITE_DNS | Env | If you set up DNS A Records for this instance, you could specify a fully qualified hostname, but since this is only a test, set it to an EC2 environment variable for public hostname, like so:
env: EC2_PUBLIC_HOSTNAME. |
If everything looks accurate, click the Save button.
Now that you have customized your ServerTemplate and defined its default input parameters, it is time to create a server. In RightScale, you create a server from a ServerTemplate so that it can inherit a majority of its core configurations from the template. You cannot create a server from scratch. Since we just finished customizing our ServerTemplate we are now ready to add (create) a server to a deployment. When you create a server, you must specify into which deployment the server will be added. A server cannot exist outside the context of a deployment. Click the Add Server button when viewing the ServerTemplate's Info tab. Since this tutorial is for demo purposes, you can just add it to the "Default" deployment if you wish. When adding/creating the server:
After you have added a server to a deployment, you are ready to launch the server.
Click the Launch action button towards the top of the server's Info tab
Next, you may see a list of Input values for the server you are about to launch (depending if you have 'verify inputs' enabled). This screen gives you one last chance to change any of the Input parameters before launching the server. If there are any missing fields that are required, they will be highlighted in red. If you change/set a value at this point in the launch process, the changes will only take affect on this particular instance; it will not change the values set at the ServerTemplate level.
Verify your settings and click the Launch action button when ready.
To track its progress, follow the Events window on the left of the page. You should see a progression from "pending" to "booting" and eventually "operational." In about five minutes you will have a fully functioning LAMP server running on EC2!
The new instance will appear under the Default Deployment (unless you specified another deployment when adding the server from the template). To check progress in a more detailed fashion:
In our example, you can see the server's status progress under the "Summary" column of the table. Select a link under Summary to view helpful troubleshooting information. For example, if your server did not progress from pending to booting to operational, the last link could be "stranded" (not operational), indicating a script failure or similar. Look at the audit entry prior to "stranded" (e.g., "boot failed: SYS Timezone set -11H1....") to view in-depth information that can help you troubleshoot the problem. You will see the boot scripts starting, logging information and more. Warnings and errors can also be displayed in the audit entries, which provide a starting point for troubleshooting and resolving issues.
Once your server is fully operational, you can preview your new LAMP server in a browser window.
You should now see index page for our test PHP application. You should also receive an email from notifier@my.rightscale.com informing you that the 'LAMP' instance is now operational:
Congratulations! You just learned how easy it is to launch a customized LAMP server on EC2 with the RightScale Dashboard. The best part about launching servers on the cloud is that you no longer have to mess with any hardware, install any OS or software programs, because the ServerTemplates will automatically complete all of these tasks for you when you launch them. ServerTemplates make it easy to launch instances on EC2 while also giving you the control and flexibility to customize each server accordingly.
Don't forget to terminate your instance when you're done to avoid any unwanted usage fees. Termination can be completed from the Manage > Servers page from the "Actions" column on the right side of the page, or alternatively by directly navigating to the Server > Info tab of your server and clicking the Terminate button.
© 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.