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 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, you will need to create an AWS account and Sign up for AWS (AWS Credentials) and Add AWS credentials to RightScale

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 server template
Step 2: Create and add a RightScript to the server template
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 server template

Let's begin by creating a new server template and adding some scripts to it.  A server template defines the composition and configuration of your EC2 instance. When an instance is launched from a server template, it uses a base OS image and a series of scripts to install and configure the server as it boots. Server templates help you get up and running quickly, while also giving you the flexibility to clone and customize these server templates so that you can reuse and leverage all the pre-existing assets.

Click on the Design tab. Go to Servers -> ServerTemplates.
Click the New button to create a new server template.

38-server_templates_home.gif

Next you will provide some basic information about your new server template.  

02-new_server_template2.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 CentOS 5_0V3_0_0
  • 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_confirmation2.gif

Now we have a blank server template that we can use to build our Apache web server.

 

Step 2 - Create and add a RightScript to the server template

Create a RightScript

The next step is to add some extra functionality to the server template 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.  RightScripts are attached to Server Templates as either boot scripts that run at boot time, operational scripts that can be run once a server is running, or as decommission scripts that run before a server is terminated. 

Go to Design -> Servers -> RightScripts.

As you create custom RightScripts of your own, they will be listed alphabetically.  Once a RightScript is defined, it can be used by any server template in an account.

27-rightscripts_no_tabs_freetrial2.gif

Click the New button to create a new RightScript.  Let's 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 – scan the RightScripts for variables that are capitalized. When a server template is launched, 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" server template.

Go to Design -> Server Templates, and click on apache webserver server template.

05-add_rscript2server_template3.gif

Click on the Scripts tab.

RightScripts can be added to server templates as either a boot, operational, or decomission script.  Let's configure the RightScript to automatically run when the server boots.

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 "apache install" RightScript is now listed under Boot Scripts and is configured to run at boot time whenever the “apache webserver” server template 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_template.gif

 

Troubleshooting

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@rightscale.com.   It may be in your bulk/spam folder.  Click on the email link and your account should be activated.  Refresh and launch the server again.  If you are still experience problems, please contact support@rightscale.com.

 

37-add_server_confirmation3.gif

  • Server Template – name of the server template to be launched.
  • Nickname – name of the new server template. The server template 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 server template, zero inputs are listed.

30-add_server_confirmation2.gif
Click Launch.

The “apache webserver” that 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_events.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.  Server templates ensure that new servers are launched exactly how you configured it.  After a couple of minutes you should see the instance's status change from "pending" to "operational," and show the elapsed time (Age) of each event.

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) to see all of your running instances.

43-select_server_template2.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

A couple Warning-Security screens may appear. Click Run. Click Yes.

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?

14-ssh_main.gif

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.
  • Press the 'I' key 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” by typing 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, we’ll create a new RightScript that will accomplish the same task. Except this time, we will also create a variable that will allow us to display different messages.

Go to Design -> RightScripts. Click New.

  • Name – Type "configure homepage."
  • 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.

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” server template. 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.

Go to Design -> Server Templates. Select the apache webserver template.

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

17-add_configure_script.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.  (Manage -> Active Servers; select “apache webserver.”)

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. Once the task is 100% completed, take another look at the server's homepage in a browswer 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.” 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

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 server template. 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 server template. Simply append each file with $ATTACH_DIR/ in front of the filename.

The next step is to attach the "deploy webapp" RightScript to the server template.
Go to the Dashboard homepage and click on "apache webserver" server template (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 server template). 

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.

And once 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 -> Active Servers and click on the Stop button.

36-terminate_instance2.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.