Basic Example

Objective

The purpose of the Basic Example tutorial is to 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. Learn how to create custom RightScripts and connect to your EC2 instance using an SSH console. Upload a simple web page and web application to the web server and then preview it in a browser window. 

The Basic Example can be completed with any type of account (Free Trial, Developer, Premium). 

If you do not have a RightScale account, sign up for a Free Trial account at http://www.rightscale.com. If you are running a trial account and your EC2 time has expired, and you are not ready to sign-up for one of our pay editions, you can create an AWS account and set up a Free Developer account.  See Upgrade Your Account to learn how to sign-up for AWS and add your credentials into the Dashboard.

NOTE: If you are using a free trial account, you must activate your trial account by clicking on the link that was emailed to you from notifier@my.rightscale.com.

This tutorial is divided into 5 Steps:

Step 1: Create an Apache ServerTemplate
Step 2: Create and add a RightScript to the ServerTemplate
Step 3: Launch the web server on EC2
Step 4: Connect to the instance using the SSH Console
Step 5: Upload files to the web server
Bonus: Upload a web application to the web server 

 

Step 1 - Create an Apache ServerTemplate

Let's begin by creating a new ServerTemplate and adding some scripts to it.  A ServerTemplate defines the composition and configuration of your EC2 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.

Go to Design -> ServerTemplates and click the New button to create a new ServerTemplate.

NOTE:  For multi-cloud support, your buttons may be labeled slightly different, including the cloud name.  For example, "New EC2" or "New Flexiscale," etc. For this example, select the "New" or "New EC2" button.

02-new_server_template3.gif

Next you will provide some basic information about your new ServerTemplate.  

02-new_server_template4.gif

  • Nickname – used to identify your server in Dashboard. Names are not case sensitive.
    Enter:apache webserver
  • Description – brief description about your machine.
    Enter:This template installs and configures a simple apache webserver.
  • Image - the Amazon Machine Image (AMI).  AMIs are the basic unit of deployment.  An AMI is a packaged environment that contains a configured Linux operating system. We recommend using our own custom RightImages which contain a lightweight server installation with all of the tools necessary to use EC2 and RightScale.
    Select: RightImage CentOS5_2V4_0_0
    NOTE: Versions prior to "RightImage CentOS5_0v3_0_0" do not support decomissioning scripts, which are introduced during the next step of this tutorial.
  • Kernal image - the kernal that you want to use for your instance.
    Select: default
  • Ramdisk image - the ramdisk that you want to use for your image.
    Select: default
  • Instance type – describes the size of the EC2 instance. See EC2 Intance Types.
    Select: m1.small
  • EC2 user data – use to pass data to the instances at boot or runtime. Leave this field blank.

 

Click Save and a confirmation screen will appear with information about the new server that you just created.

24-new_server_template_confirmation3.gif

Now you have a blank ServerTemplate that you can use to build your Apache web server.

 

 

Step 2 - Create and add a RightScript to the ServerTemplate

Create a RightScript

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

  • Boot Scripts - Scripts that run at boot time.
  • Operational Scripts - Scripts that can be run once a server is running.
  • Decommission Scripts - Scripts that run right before a server is terminated.

Go to Design -> RightScripts.

As you create custom RightScripts of your own, they will be listed alphabetically under your Private tab.  If you clone a RightScript from one of the other tabs, it will also appear under your Private tab.  Once a RightScript is defined, it can be used by any ServerTemplate in an account.

27-rightscripts_no_tabs_freetrial2.gif

Click the New button to create a new RightScript.  Create a new RightScript that installs Apache on the web server.

 

04-new_rscript_template.gif

  • Name – name of the new RightScript. (required)
    Enter: apache install
  • Description – brief description about the RightScript's functionality.
  • Packages – list of programs that will be automatically installed when an instance boots. Separate multiple packages by a comma or character space. Ex: httpd, package2. In this example we want to install Apache.
    Enter: httpd
  • Inputs – click the Identify button to scan the script for any variables that are capitalized. Once the server is operational, you can define a value for each variable.
  • Script – code for the RightScript.  In this example, since Apache does not start automatically, enter the following line of code.
    Enter: service httpd start

Click Save.

Add the RightScript to the webserver

Now that you've created the new RightScript, you need to add it to the "apache webserver" ServerTemplate.

Go to Design -> ServerTemplates, and click on apache webserver ServerTemplate.

05-add_rscript2server_template4.gif

Click on the Scripts tab.

RightScripts can be added to ServerTemplates as either a boot, operational, or decomission script.  Since this RightScript is installing apache, you want it to automatically run when the server boots.  Add the "apache install" RightScript as a boot script.

06-add_rscript2server_template3.gif

Select the apache install script from the pulldown list of private RightScripts.
Select boot script from the dropdown box.
Click Add.

23-add_rscript_boot_script.gif

The Dashboard header displays "RightScript was successfully added" and the "apache install" RightScript is now listed under Boot Scripts.  This RightScript is configured to run at boot time whenever the “apache webserver” ServerTemplate is used to create a new server.

 

 

Step 3 - Launch the web server on EC2

The template is now ready to be launched.  Click the Launch button.

28-launch_server_template2.gif

 

Troubleshooting

47-insufficient_message.gif
If you receive an error message saying that your account has insufficient funding to perform this action, you need to verify your email address.  Go to your email account and check for an email confirmation from notifier@my.rightscale.com.  It may be in your bulk/spam folder.  When you click the email validation link your account should be activated.  Refresh and launch the server again.  If you are still experience problems, please contact  support@rightscale.com.

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 curent [HEAD] version.

37-add_server_confirmation3.gif

  • ServerTemplate – name of the ServerTemplate to be launched.
  • Nickname – name of the new ServerTemplate. The ServerTemplate name is used by default.
  • SSH Key – a secure key that isusing one of associated with a particular instance on EC2.
    Select: default-key
  • Security Group – firewall access. Use the "default" security group.
    Select: default
  • Availability Zone – specify the availability zone where the instance should be launched. 
    Select: any
  • Elastic IP – specify an elastic IP address.  Select "-none-."
    Select: -none-

Verify your settings and click Launch.


Since inputs were not specified in the ServerTemplate, zero inputs are listed.

30-add_server_confirmation2.gif
Click Launch.

The RightScale Dashboard header displays "Launched server apache" as the “apache webserver” you just configured in the Dashboard is now being launched on EC2.

Under Recent Events, you can track the status of the server's boot process. 

39-recent_events2.gif

The "apache webserver" template that you just launched is now pending. The server will take a couple of minutes to complete the boot process.  One of the main advantages of using ServerTemplates is that they ensure that new servers are launched exactly how you configured it, everytime!  Depending how often you view the status window, after a couple of minutes you should see the instance's status progress from "pending" to "booting" and finally to "operational."  The elapsed time (Age) of each event is also displayed.

08-recent_tasks_pending.gif 08-recent_tasks.gif

Once your server is operational, go back to the Dashboard’s main window (Home -> Dashboard, or you can click on the RightScale logo as a shortcut) to see all of your running instances.

31-click_apache_server2.gif

Under Nickname, click apache webserver and you will be taken to a general information page for your running instance.

11-dashboard_instance_info.gif

12-apache_homepage.gifClick on the Public DNS name link to view your running EC2 instance in a new browser window.  We will reference this link again during the tutorial, so it will be helpful to keep this window open as a quick reference.

You should now see the Apache 2 Test Page in your web browser.  You should also receive an email from notifier@rightscale.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-67-202-46-87.compute-1.amazon.aws.com) and see the Apache 2 Test Page.

 

 

Step 4 - Connect to the instance using the SSH console

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.

Go back to your instance's homepage and click on the SSH Console button to “SSH” into the machine.

13-ssh_console_btn.gif

You can also open an SSH window by clicking the SSH button next to the instance's DNS. 

44-ssh_button.gif

Two windows should be launched for you.  The first is an ssh status and control window.  The other is the ssh console itself.

A couple Warning-Security screens may appear. Click Yes when you see the SSH confirmation window.

45-ssh_launch_screen1.gif   46-ssh_mindtouch_confirm.gif

14-ssh_main.gif

 

Troubleshooting

Occassionally the very first attempt at ssh will fail.  If this happens, simply close out the launched windows and attempt again by pressing the "SSH Console" button. 

NOTE: If you don't have Java configured correctly, you will need to ssh in manually by following the client setup in this guide. See FAQ: How do I ssh into my machines?

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.

  • Type: vi /var/www/html/index.html to create an index.html file in the specified directory. Click Enter.
  • Type: i   to insert text.
  • Copy and Paste (Shift + Insert) the code below and click ESC.
  • Type: wq  and click Enter.
<html>
   <head>
     <title>Tutorial: Apache Server</title>
   </head>
   <body>
     <h1>Welcome to RightScale!</h1>
   </body>
</html> 

Reload your “apache webserver.” Type: service httpd restart   from the SSH command prompt. Click Enter.  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.

42-browser_apache2rock.gif

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?

 

 

Step 5 - Upload files to the web server

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 a variable that will allow you to display different messages.

Go to Design -> RightScripts. Click New.

  • NameType: configure hompage 
  • Script – Copy and paste the following code snippet.
#!/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 

15-new_rscript_configure.gif

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.

16-configure_script.gif

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 -> Server Templates. Select the apache webserver ServerTemplate.

Click the Scripts tab and select the configure homepage RightScript and define it as an operational script by clicking Add.

17-add_configure_script2.gif

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 main window (Home -> Dashboard, or you can click on the RightScale logo) and click on "apache webserver."

31-click_apache_server2.gif

 

Now click on the Script Inputs tab. Click Edit.

18-script_edit.gif

To define the welcome message parameter, select Text and type RightScripts Rock! and click Save.

19-script_edit_type.gif


To run this new operational script, go to the Scripts tab and click the Run button on the right.

20-script_run.gif

The “configure homepage” operational script now appears in the Recent Events list.  (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 DNS 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 “apache webserver.” You should now see the following page in a browser window.

42-browser_welcome2rock.gif

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 you have a RightScript that will display any text message that you define.

 

 

Bonus - Upload a web application to the web server

NOTE:  The bonus section can only be completed with a Developer or pay edition of RightScale.  You cannot complete the bonus section with a Free Trial account.

Objective

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.

Requirements

Download the following sample web application: webapp.tgz
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 

21-script_deploy_webapp.gif

Click Save

Since we are launching a web application, we need to attach the webapp file to the ServerTemplate. Click on the Attachments tab.  Browse and upload the webapp.tz file. 

32-attach_app.gif
 

Click on the Script tab and take a look at what this script does.

33-attach_app_script.gif

Notice the $ATTACH_DIR in the script.

RightScripts allow you to attach as many files as you want to a ServerTemplate. Simply append each file with $ATTACH_DIR/ in front of the filename.

The next step is to attach the "deploy webapp" RightScript to the ServerTemplate.
Go to the Dashboard homepage and click on "apache webserver" ServerTemplate (not the nickname).

43-select_server_template2.gif

 

Click on the Scripts tab.  Add the "deploy webapp" as an operational script.

34-attach_deploy_webapp.gif

 

Go to  Home -> Dashboard and click on "apache webserver" nickname (not the ServerTemplate). 

31-click_apache_server2.gif

 

Click on the Scripts tab. 

35-launch_deploy_webapp.gif


To run the "deploy webapp" RightScript, click on the Run button. 

After refreshing the preview window, you should see the new homepage of your EC2 instance, which is running the webapp.tz web application.  (In this example, the web application is a simple html page.)

42-browser_rock2webapp.gif

To turn this example into a reusable server configuration for launching a generic website, simply change the “deploy webapp” RightScript from an operational script to a boot script.

When you are done testing the web application, don't forget to terminate your instance to ensure that completing this tutorial will only cost $0.10.  Go to Manage -> Servers and click on the Stop button.

36-terminate_instance3.gif

 

 ----------------------

Did you find this document helpful?  Please feel free to leave us a comment below.  We're always looking for ways  to improve our documentation.  Thanks!

 

Tag page

Files 1

FileSizeDateAttached by 
 webapp.tgz
webapp.tz
215 bytes18:38, 3 Apr 2008deanoActions
Viewing 8 of 8 comments: view all
Nice tutorial. Warning that cutting and pasting the first script seems to have only partially worked. It did restart the server, but the homepage had the EOF and the service httpd restart listed on it. Strange... Maybe that was some end of line issue when I cut and paste it.

The part at the end regarding uploading the webapp was especially promising as I would like to deploy our application server this way, but ideally I'd be able to upload the file as part of a one-step build/deploy process.
Posted 00:12, 9 Apr 2008
Nice simple tutorial.

There's a small error error in the 'configure webserver' script, as curt noticed above. The commands after the final EOF are written to the file (and shown on the web front page) instead of executed.

The reason is that the scrip contains two spaces that mess up the EOF marker. One between << and EOF and another after the final EOF. Just remove these two spaces, and it works as expected.

Posted 12:52, 18 Apr 2008
Thanks for the feedback,

I will add you suggestion Curt, and Emil, thanks for pointing that out, it has been fixed.

Martin
Posted 16:23, 21 Apr 2008
The SSH shell did not work for me on MS Internet Explorer, but it launched OK when I launched SSH from Firefox.
Posted 19:35, 21 Apr 2008
It does not seem that your apache setups are very secure. I don't see any of the techniques outlined in the book "Apache Security" being followed. Is there any plan to enhance the apache install scripts to employ some of these techniques (changing the user apache runs as, chroot jail etc) ?
Posted 14:45, 24 Apr 2008
Hi Philip,

You are right, if you want security, jail apache and run it as a non-root user.

Our templates are not designed as an all-inclusive solution for every user. Rather, they are starting point to get you setup quickly and easily, and meant to be customized to fit your particular needs. So, indeed you will find plenty of situations where you would like a specific setup that is not provided. That is why we make it easy to clone and customize scripts and templates.

In this case, we chose to use the default CentOS installation. If we had made the default installation run as a different user and in a chroot environment, it would increase the complexity, and therefore the learning curve, of *all* users, and this is something that we want to minimize. Savvy users, like yourself, who know what they are doing usually want to make all sorts of tweaks and customizations anyways, and that is fine because they are very capable of implementing them. In this case, jailing apache and running it as a different user is trivial for an experienced sysadmin.

Thanks for your post,

Martin
Posted 23:46, 24 Apr 2008
Under step 4, I don't believe that you actually need to restart apache to view the new index.html. I also think that this link: "FAQ: What's the difference between private/public/premium RightScripts?" is pointing at a shared drive, as the link isn't working for me.

Great tutorial, though! I can't believe how easy this is to work with. edited 22:56, 28 Apr 2008
Posted 21:51, 28 Apr 2008
The command "cat <<EOF> file.txt" looks a bit strange to me (but does work).

I like to write this as:

cat > zap.txt <<EOF
Example here document.

All of this ends up in the file zap.txt in the current directory.

EOF
Posted 17:00, 7 May 2008
Viewing 8 of 8 comments: view all
You must login to post a comment.