Appendices

This section contains tips and helpful hints for using the USGIN EC2 Instance.

Common Procedures

 

"Restarting" the Virtual Machine

You can't actually restart it, instead you essentially delete it and roll-back to a prior machine image.

  1. Use the EC2 Console  to terminate the instance.
  2. Still in the console, locate the machine image you want to roll back to and Launch an instance of that image.
    1. This post may provide some guidance as to which image to launch.
    2. Specify the details of the instance, we usually create one small instance, use the StandardFirewallRules Security Group, and the BaseAdmin key-pair.
  3. Attach the appropriate Elastic Block Store to the new instance at /dev/sdh.
  4. Follow the directions below to connect to the instance via SSH.
  5. Follow the directions below to mount the Elastic Data Store.
  6. Follow the directions below to start Apache, then PostgreSQL and MySQL, then Tomcat.

 

Connect to the Instance Using SSH (and PuTTY)

If you already have the .ppk file for the appropriate user that you wish to log in with, use it. You may want to set up SSH Tunneling if you want to use pgAdmin to connect to PostgreSQL.

If you don't have a.ppk file, follow the instructions outlined in this post.

 

Mounting the Elastic Block Store

First, use the EC2 Console  to attach the volume to the instance at /dev/sdh

mkdir /mnt/data-store
mount /dev/sdf /mnt/data-store

 

Starting, Stoping, Restarting Applications

These commands should be executed with root privileges

/etc/init.d/apache2 start
/etc/init.d/apache2 stop
/etc/init.d/apache2 reload
/etc/init.d/tomcat6 start
/etc/init.d/tomcat6 stop
/etc/init.d/tomcat6 restart
/etc/init.d/postgresql-8.4 start
/etc/init.d/postgresql-8.4 stop
/etc/init.d/postgresql-8.4 restart
/etc/init.d/mysql start
/etc/init.d/mysql stop
/etc/init.d/mysql restart

Helpful Linux Commands

User Administration

  1. adduser <username>: Create a new user named <username>
  2. userdel -r <username>: Delete the user named <username>. The -r option removes the user's home folder located at /home/<username>.
  3. lastlog: lists all users and the last time that they logged in.
  4. groupadd <groupname>: Create a group called <groupname>
  5. useradd -G <groupname1>,<groupname2>... <username>: Add a user named <username> to a group or multiple groups.
Permissions
  1. chown <username>:<groupname> <file or directory>: Change the owner of at file or directory to <username> and <groupname>.
  2. chmod <permissions code> <file or directory>: Change the permissions on a file or directory to that specified.
"Hardware" Resources
  1. top: Show the top resource using processes
  2. ps aux: Show all processes
  3. free: Show information about memory allocation
  4. du <file or folder name>: Show the size of a file or folder, recursive for folders.
  5. kill <PID>: Kill a process by its ID. Use kill <PID> -9 to force the kill.
EC2 Tools
  1. ec2-bundle-vol: use to bundle an AMI for your running instance. Use --help for syntax information.
  2. ec2-upload-bundle: use to upload your bundle to Amazon's place for these things. Again, Use --help for syntax information.
Package Management / Software Installation
  1. apt-get: Oh my goodness its so easy to install anything!
  2. dpkg -L <package name>: Show a list of all the files that were installed with the named package. Useful since Linux seems so silly about where everything ends up...
Debugging
  1. tail -f <log file>: Real-time display of latest log file changes.
  2. find / -name <file or folder name fragment>*: Recursively search for folders and files by partial name from root down.