This tutorial will introduce you to some of the basic RightScale concepts and demonstrate how easy it is to set up and launch a web server on the Elastic Compute Cloud (EC2) using the RightScale Dashboard by using our various ServerTemplates and RightScripts. You will also learn how to create custom RightScripts and connect to your EC2 instance using an SSH console. Optionally, you can upload a simple web page and web application to the web server and then preview it in a browser window.
Table of Contents
For best results, use Firefox, or Chrome. IE8+ and Safari should also work though.
Let's begin by creating a new ServerTemplate and adding some RightScripts. A ServerTemplate, defines the composition and configuration of your instance. When an instance is launched from a ServerTemplate, it uses a base OS image and a series of scripts to install and configure the Server as it boots. ServerTemplates help you get up and running quickly, while also giving you the flexibility to clone and customize these ServerTemplates, so that you can reuse and leverage all the pre-existing assets.
Note: ServerTemplates are cloud-agnostic. You can use the same ServerTemplate to launch instances in multiple clouds or AWS regions. In this tutorial, you will launch an instance in the AWS US-East region.
Next, you will provide some basic information about your new ServerTemplate.
Select the Save action button when ready. A confirmation message will confirm that you created a new ServerTemplate and MCI.
Now you have a blank ServerTemplate that you can use to build an Apache web server.
Since you just created a new MultiCloud Image (MCI) from scratch that's using a v5 RightImage, which supports our latest RightLink technology, you will also need to tag the MCI so that RightScale will properly recognize it as a RightLink-enabled server when it's launched. Servers that contain the RightLink agent are optimized to communicate with the RightScale platform. RightScale will check for a specific RightLink tag on the MCI to determine if a server supports RightLink.
Note: If you are using a v4 RightImage (i.e. no RightLink support), you do not have to add a tag to the MCI.
Click on the ServerTemplate's Images tab to view the MCI that you just created. Click on the text link to view the MCI.
Under the MCI's Info tab, click the Edit Tags text link. Add the following RightLink tag: provides:rs_agent_type=right_link
The next step is to add some extra functionality to the ServerTemplate, by inserting a RightScript.
A RightScript, is any script that you define within the RightScale Dashboard. It may be a shell script, a Perl script, a Ruby script, etc. There are three types of RightScripts that are attached to ServerTemplates
Note: RightScripts can only be run on "operational" servers. Servers that "strand" during the boot process cannot run RightScripts.
As you create custom RightScripts of your own, they will be listed alphabetically under Design > RightScripts. If you clone a published RightScript, you will create an editable copy. Once a RightScript is defined, it can be used by any ServerTemplate in an account.
Create a new RightScript that installs Apache on the web server.
Select the Save action button when ready. A message will confirm that your RightScript was successfully created.
Now that you've created the new RightScript, you need to add it to the "apache webserver" ServerTemplate you created earlier.
Hint: Click the Help action button to toggle the context sensitive Help Text built into the RightScale Dashboard. The Help Text contains useful overview information to assist you wherever you are within the Dashboard. If you are not yet familiar with ServerTemplates and the MultiCloud Marketplace, please take a minute to read the Help Text.
The "apache install" RightScript is now listed under the Boot Sequence section. This RightScript is configured to run at boot time whenever the “apache webserver” ServerTemplate is used to create a new Server.
Note: Operational Scripts can be manually run when a Server is operational, whereas Decommission Scripts are executed during the shutdown phase in order to provide a more graceful server termination.
You are now ready to launch a Server on EC2 using the new ServerTemplate. Servers are always launched within the context of a deployment. Every RightScale account has a "Default" deployment, which is typically used for testing purposes only. Most users create deployments for each of their projects. Since this tutorial is designed for a quick demo, add it to the "Default" deployment.
Click Add Server from the Default deployment.
If you selected a MultiCloud Image that has machine images defined for multiple clouds, you will need to select into which cloud you want to launch a server. Select: AWS US-East
You may notice that the ServerTemplate has a [HEAD] label. Since you can commit and create revisions of ServerTemplates and RightScripts, you can only make changes to the current [HEAD] version. Think of the HEAD version, as a working copy. (Note: It is not considered a best practice to use HEAD versions in production.)
You will be presented with an Add Server flow. For more information on the Add Server assistant, see Add Server Assistant.
The following includes additional information and suggestions for filling out the Add Server dialog:
Verify your settings and select the Launch action button when ready.
Because Inputs were not specified in the ServerTemplate, no Inputs are listed, and the Server is ready to be launched.
The instance is now being launched on EC2. This can take a few minutes. (Typically in the 5-10 minute range.) Under the Events pane, you can track the status of the Server's boot process.
The "my webserver" instance that you just launched is now pending. The server will take a couple of minutes to complete the boot process. In this example, the server should transition to the "operational" state without a problem. However, it's useful to know that if a server ever becomes "stranded" you should still be able to SSH into the instance for troubleshooting purposes. The next section will explain how to open an SSH console instance in more detail.
One of the main advantages of using ServerTemplates is that they ensure that new Servers are launched exactly how you configured them ... every time! Depending how often you view the Events window and the "State" column, after a couple of minutes you should see the instance's status progress from "pending" to "booting" and finally to "operational."
Once your Server is operational, click the my webserver link (Nickname column) to view general information for your running instance.
You should now see the Apache 2 Test Page in your web browser. You should also receive an email from email@example.com informing you that the 'apache webserver' instance is now operational.
Congratulations! You just launched a live web server on EC2! Anyone in the world can type in your Public DNS name (ex: http://ec2-174-129-100-132.compute-1.amazon.aws.com) and see the Apache 2 Test Page.
We provide you with three options with respect to using SSH to access your instances. From the RightScale dashboard use Settings > User Settings > SSH > Edit to configure your SSH client settings.
In this example, we will use the Java Web Start application option. By default, the web server that you just launched is currently pointing to an Apache homepage. Let’s create our own custom landing page using the SSH console.
You are now logged into the instance. From this command prompt, create a file called, /var/www/html/index.html and paste the following code.
<html> <head> <title>Tutorial: Apache Server</title> </head> <body> <h1>Welcome to RightScale!</h1> </body> </html>
Reload your “my webserver.” Now refresh the preview in the browser window that is displaying the instance's public DNS link. Or you can go back to the Dashboard and click on the public DNS name to load the new homepage. (You should not have to restart Apache, but if for some reason you need to in order to see your changes, enter the following command: service httpd restart from the SSH command prompt. Click Enter.
Congratulations! You just logged into your EC2 instance using the SSH console and manually created a custom homepage for your Apache webserver. But, wouldn't it be great if we could somehow automate this manual process?
Next, you'll create a new RightScript that will accomplish the same task achieved in the previous step of this tutorial. Except this time, you will also create an Input (variable) that will allow you to display different messages.
Go to Design -> RightScripts. Click New.
#!/bin/bash cat <<EOF> /var/www/html/index.html <html> <head> <title>Tutorial: Apache Server</title> </head> <body> <h1>$WELCOME_MESSAGE</h1> </body> </html> EOF service httpd restart
Click Save. The RightScale Dashboard header status message displays "RightScript was successfully added."
Click the Script tab and look at the list of Inputs. Notice that the RightScale Dashboard automatically recognizes the WELCOME_MESSAGE parameter! Instead of hard-coding a message, we will use the WELCOME_MESSAGE variable, so that we can use the same script to display different messages.
Now add the new “configure homepage” RightScript to the “apache webserver” ServerTemplate. But this time, add it as an operational script. Operational Scripts behave similar to boot scripts, but they are not run when the instance boots. Operational scripts are run on-command once a server is operational.
Go to Design -> ServerTemplates -> View Local. Select the apache webserver ServerTemplate.
Click the Scripts tab and add the configure homepage RightScript as an operational script.
Notice that we're adding a script to the editable HEAD version of the apache webserver ServerTemplate. Since we launched a server using the HEAD version of a ServerTemplate, we can add scripts to the ServerTemplate and the scripts will be available for execution on the running server. This is a useful feature for development and testing purposes. In production environments it is considered a best practice to only launch Servers using committed (static) ServerTemplate revisions.
After we've added this new operational script, we can execute this script from the running instance page. But, before you run the instance again, specify a new value for the WELCOME_MESSAGE parameter.
Go back to the Dashboard's Deployments tab (or click on the RightScale logo) and click on the "my webserver" link. You want to go to the running Server's page which is listed in the Default deployment section.
Now click on the Inputs tab. Click Edit.
To define the welcome message parameter, select Text and type RightScripts Rock! and click Save.
To run this new operational script, go to the Scripts tab and click the Run action button on the right.
The “configure homepage” operational script now appears in the Events pane. (You may observe a brief transition from 'queued' to 'completed'.) Once the task is 100% completed, take another look at the server's homepage in a browser window. (Refresh your browser window.) The message should have changed to "RightScripts Rock!"
If you accidentally closed the preview browser window, go to the Dashboard (click on the RightScale logo) and click on the public DNS link for the “my webserver.” You should now see the following page in a browser window.
In the example above, you defined the page’s <H1> tag to display the text “RightScripts Rock!." This was accomplished by simple variable substitution using RightScript Inputs.
Congratulations! You now have a RightScript that will display any text message that you define.
Instead of creating a RightScript that loads a simple html page, we will upload a web application and create a RightScript that deploys an entire web application.
Download the following sample web application: webapp.tgz
Note: After downloading the file, make sure that the filename was not modified by your OS or browser settings. Sometimes, extra characters will be added to the filename or the file extension may be changed or missing. The file must be have correct filename.
Create a new RightScript called, deploy webapp.
Paste the following code into the Script field.
tar xzf $ATTACH_DIR/webapp.tgz -C /var/www/html/ service httpd restart
Since we are launching a web application, we need to attach the webapp file to the ServerTemplate. Click on the RightScript's Attachments tab. Browse and upload the webapp.tgz file that you just downloaded.
Now click on the Script tab and take a closer look at code.
Notice the $ATTACH_DIR in the script.
RightScripts allow you to attach as many files as you want to a ServerTemplate. Simply prepend each filename with "$ATTACH_DIR/ ".
The next step is to attach the "deploy webapp" RightScript to the ServerTemplate.
Go to the "apache webserver" ServerTemplate.
Click on the template's Scripts tab. Add the "deploy webapp" as an operational script.
Go to Manage -> Deployments -> View all. Select the Default deployment and then click on the "my webserver" link.
Click on the Scripts tab.
To run the "deploy webapp" RightScript, click on the Run action button.
After refreshing the preview window, you should see the new homepage of your EC2 instance, which is running the webapp.tgz web application. (In this example, the web application is a simple html page.)
Clearly this web application is very basic. Having uploaded the zipped tarball, it extracts a new index.html and restarts Apache, resulting in the new homepage for your Apache webserver. Of course, it could have done a lot more, and all of the key principles from this tutorial still apply.
|Glossary | 用語 | 용어||Site Map | Site Help||Community||Corporate Site||Get Support||Dashboard Login|
|Doc Feedback||Product Feedback||Resources||MultiCloud Marketplace||Forums|
© 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.