"Deploying on Amazon AWS"

How to deloy applications on AWS (Ruby on Rails or LAMP or JAVA etc ).

Was just trying something and thought of saving some of my server cost , and decided to use Amazon AWS instances for it. I know I know .. I am bit late but nevertheless .

Will try to form a basic approach of deploying on AWS , wont cover actual ROR or LAMP deployment , but will try to take you till how we can actually get ssh access , rest post that is routine .

  1. Amazon is currently offering a ‘Free’ (http://aws.amazon.com/ec2/pricing/) service tier in their EC2 cloud, so go ahead and register that .
  2. Once you have registered now, try to create an instance .
  3. Sign into aws.amazon.com and click on Amazon EC2
  4. Click on the “Launch Instance” button and deploy an instance
    • If you want to stay in the ‘Free’ Tier to just try things out, pick a Micro instance which has a big yellow star next to the Select button
    • In my case, I picked the UBUNTU Image
    • As part of setting up the new instance you will be asked to re-use or create a new keypair. This will be important when accessing the Image later on
  5. Login to the EC2 instance you created before.
    • On the Instances page, highlight your instance and select Instance Actions -> Connect
    • A dialog box will indicate how to use an SSH client to access the instance. The command looks something like this:
      ssh -i keypairname.pem ec2-user@ec2-XX-XX-1XX-1XX.us-west-1.compute.amazonaws.com
    • For windows users, see this article about how to use PuTTY to access the Instance (http://docs.amazonwebservices.com/AmazonEC2/gsg/2007-01-19/putty.html)
  6. Once you  have logged into your system using SSH , now you can easilyinstall LAMP, or ROR or whatever you want to. It will be the same way you install these on any other UBUNTU boxes.

EASY pesy !!

Thats it ! Will try to make time and write more of actual ROR and LAMP installations and also DOMAIN mapping in the coming posts .

Thanks !!

Advertisements
"Deploying on Amazon AWS"

"Basic vi editor commands"

General Startup
	To use vi: vi filename
	To exit vi and save changes: ZZ   or  :wq
	To exit vi without saving changes: :q!
	To enter vi command mode: [esc]

Counts
        A number preceding any vi command tells vi to repeat
	that command that many times.

Cursor Movement

	h       move left (backspace)

	j       move down

	k       move up

	l       move right (spacebar)

	[return]   move to the beginning of the next line

	$       last column on the current line

	0       move cursor to the first column on the
		current line

	^       move cursor to first nonblank column on the
		current line

	w       move to the beginning of the next word or
		punctuation mark

	W       move past the next space

	b       move to the beginning of the previous word
		or punctuation mark

	B       move to the beginning of the previous word,
		ignores punctuation

        e       end of next word or punctuation mark

        E       end of next word, ignoring punctuation

        H       move cursor to the top of the screen

        M       move cursor to the middle of the screen

        L       move cursor to the bottom of the screen

Screen Movement

       G        move to the last line in the file

       xG       move to line x

       z+       move current line to top of screen

       z        move current line to the middle of screen

       z-       move current line to the bottom of screen

       ^F       move forward one screen

       ^B       move backward one line

       ^D       move forward one half screen

       ^U       move backward one half screen

       ^R       redraw screen
		( does not work with VT100 type terminals )

       ^L       redraw screen
		( does not work with Televideo terminals )


Inserting

       r        replace character under cursor with next
		character typed

       R        keep replacing character until [esc] is hit

       i        insert before cursor

       a        append after cursor

       A        append at end of line

       O        open line above cursor and enter append mode


Deleting

	x       delete character under cursor

	dd      delete line under cursor

        dw      delete word under cursor

        db      delete word before cursor



Copying Code

        yy      (yank)'copies' line which may then be put by
		the p(put) command. Precede with a count for
		multiple lines.



Put Command
        brings back previous deletion or yank of lines,
	words, or characters

        P       bring back before cursor

        p       bring back after cursor



 Find Commands

	?       finds a word going backwards

	/       finds a word going forwards

        f       finds a character on the line under the
		cursor going forward

        F       finds a character on the line under the
		cursor going backwards

        t       find a character on the current line going
		forward and stop one character before it

	T       find a character on the current line going
		backward and stop one character before it

	;	repeat last f, F, t, T



Miscellaneous Commands

	.	repeat last command

	u	undoes last command issued

	U	undoes all commands on one line

	xp	deletes first character and inserts after
		second (swap)

	J	join current line with the next line

	^G	display current line number

	%	if at one parenthesis, will jump to its mate

	mx	mark current line with character x

	'x	find line marked with character x

	NOTE: Marks are internal and not written to the file.



Line Editor Mode
	Any commands form the line editor ex can be issued
	upon entering line mode.

	To enter: type ':'

	To exit: press[return] or [esc]



ex Commands
	For a complete list consult the
	UNIX Programmer's Manual



READING FILES
	copies (reads) filename after cursor in file
	currently editing

	:r filename



WRITE FILE

	:w 	saves the current file without quitting



MOVING

	:#	move to line #

	:$	move to last line of file



SHELL ESCAPE
	executes 'cmd' as a shell command.

	:!'cmd'
"Basic vi editor commands"

"How to find – Size of a directory & Free disk space"

This article explains 2 simple commands that most people want to know when they start using Linux. They are finding the size of a directory and finding the amount of free disk space that exists on your machine. The command you would use to find the directory size is ‘ du ‘. And to find the free disk space you could use ‘ df ‘.


All the information present in this article is available in the man pages for du and df. In case you get bored reading the man pages and you want to get your work done quickly, then this article is for you.



‘du’ – Finding the size of a directory


$ du

Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.


$ du /home/david

The above command would give you the directory size of the directory /home/david


$ du -h

This command gives you a better output than the default one. The option ‘-h’ stands for human readable format. So the sizes of the files / directories are this time suffixed with a ‘k’ if its kilobytes and ‘M’ if its Megabytes and ‘G’ if its Gigabytes. 


$ du -ah

This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that ‘du’ always counts all files and directories while giving the final size in the last line. But the ‘-a’ displays the filenames along with the directory names in the output. ‘-h’ is once again human readable format.


$ du -c

This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be


30M .

30M total


The first line would be the default last line of the ‘du’ output indicating the total size of the directory and another line displaying the same size, followed by the string ‘total‘. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.


$ du -ch | grep total

This would have only one line in its output that displays the total size of the current directory including all the subdirectories.


Note : In case you are not familiar with pipes (which makes the above command possible) refer toArticle No. 24 . Also grep is one of the most important commands in Unix. Refer to Article No. 25 to know more about grep.


$ du -s

This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.


$ du -S

This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.


$ du –exculde=mp3

The above command would display the size of the current directory along with all its subdirectories,but it would exclude all the files having the given pattern present in their filenames. Thus in the above case if there happens to be any mp3 files within the current directory or any of its subdirectories, their size would not be included while calculating the total directory size.



‘df’ – finding the disk free space / disk usage


$ df

Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the ‘Size’, ‘Used’ and ‘Avail’ columns use kilobytes as the unit. The ‘Use%’ column shows the usage as a percentage which is also very useful.


$ df -h

Displays the same output as the previous command but the ‘-h’ indicates human readable format. Hence instead of kilobytes as the unit the output would have ‘M’ for Megabytes and ‘G’ for Gigabytes.


Most of the users don’t use the other parameters that can be passed to ‘df’. So I shall not be discussing them.


I shall in turn show you an example that I use on my machine. I have actually stored this as a script named ‘usage‘ since I use it often.


Example :

I have my Linux installed on /dev/hda1 and I have mounted my Windows partitions as well (by default every time Linux boots). So ‘df’ by default shows me the disk usage of my Linux as well as Windows partitions. And I am only interested in the disk usage of the Linux partitions. This is what I use :


$ df -h | grep /dev/hda1 | cut -c 41-43


This command displays the following on my machine


45%


Basically this command makes ‘df’ display the disk usages of all the partitions and then extracts the lines with /dev/hda1 since I am only interested in that. Then it cuts the characters from the 41st to the 43rd column since they are the columns that display the usage in % , which is what I want.

"How to find – Size of a directory & Free disk space"

"Installing Ruby on Rails on Ubuntu 10.04"

There are a few different approaches to installing Ruby on Rails on Ubuntu 10.4. This is the technique that I use, in my opinion it involves the least hassle.


Ubuntu has a managed ruby package that serves perfectly as the basis for a Ruby on Rails installation. Open a console and install it with the following command.


sudo apt-get install ruby-full build-essential


I’ve previously had issues with the rubygems Debian package and would normally advocate installing the package directly from RubyForge.


cd ~
mkdir gems
cd gems
wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
tar -xf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb


The ruby setup script doesn’t automatically place a link to the gems application in your /usr/bin folder so add it now.


sudo ln -s /usr/bin/gem1.8 /usr/bin/gem


Update your ruby environment. If you’ve downloaded the latest version of rubygems, you’ll be told that everything is already up-to-date.


sudo gem update system
gem -v


With your ruby environment ready, install rails.


sudo gem install rails


You’re finally at the point where you can create rails projects, just use the following command.


rails test_project


I prefer to use something a bit more friendly than vi as a development environment for Rails. Download and install the latest copy of Netbeans from netbeans.org.


wget http://download.netbeans.org/netbeans/6.9/final/bundles/netbeans-6.9-ml-linux.sh
chmod +x netbeans-6.9-ml-linux.sh
./netbeans-6.9-ml-linux.sh
"Installing Ruby on Rails on Ubuntu 10.04"

"Useful Commands For The Linux Command Line"

arch

Outputs the processor architecture.

$ arch

i686

cat

Outputs the contents of a file.

$ cat lorem.txt

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

cd

Change the working directory.

$ cd /bin

chgrp

Change group ownership of files.

$ chgrp games moo.txt

chmod

Change access permissions of files.

$ chmod +x helloworld

chown

Change file owner and group.

# chown root lorem.txt

cksum

Print CRC checksum and byte counts of each file.

$ cksum lorem.txt moo.txt

3570240675 453 lorem.txt

4294967295 0 moo.txt

cp

Copies a file.

$ cp lorem.txt copy_of_lorem.txt

date

Outputs the current date and time.

$ date

Sat Mar  3 12:07:09 GMT 2007

df

Reports the amount of disk space used and available on filesystems.

$ df

Filesystem           1K-blocks      Used Available Use% Mounted on<br>

/dev/simfs            39845888    218048  39627840   1% /

dir

List directory contents.

$ dir

copy_of_lorem.txt  lorem.txt  moo.txt  www

du

Estimate file space usage.

$ du -h /bin

7.8M    /bin

echo

Display a line of text.

$ echo foobar

foobar

exit

Cause the shell to exit.

$ exit

fgrep

Print lines matching a pattern in a file.

$ fgrep “irure dolor” lorem.txt

commodo consequat. Duis aute irure dolor in reprehenderit in voluptate

find

Search for files in a directory hierarchy.

$ find hello*

hello_world

hello_world.c

free

Display amount of free and used memory in the system.

$ free

                       total       used       free     shared    buffers     cached

Mem:       8299892    8287708      12184          0    2641772    1731236

Low:       3581300    3572764       8536

High:      4718592    4714944       3648

-/+ buffers/cache:    3914700    4385192

Swap:      8193140    2335664    5857476

grep

Print lines matching a pattern.

$ grep -i apple fruitlist.txt

apple

groups

Outputs the user groups of which your account belongs to.

$ groups

games users

head

Output the first part of files.

$ head -2 lorem.txt

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim

hostname

Outputs the machines hostname on the network.

$ hostname

anapnea.net

id

Outputs user id, group id, and groups of your account.

$ id

uid=1478(smallfoot) gid=100(users) groups=35(games),100(users)

kill

End a process.

$ kill -9 18298

-bash: kill: (18298) – Operation not permitted

killall

Kill processes by name.

$ killall irssi

irssi(18298): Operation not permitted

irssi(13372): Operation not permitted

irssi(22048): Operation not permitted

irssi: no process killed

last

Show listing of last logged in users.

$ last -n 3

alice    pts/6        192.0.34.166     Fri May 18 16:17   still logged in

bob      pts/2        64.233.183.103   Fri May 18 16:17   still logged in

clare    pts/6        72.5.124.61      Fri May 18 15:54 – 15:55  (00:01)

ldd

Print shared library dependencies.

$ ldd /bin/bash

        libncurses.so.5 => /lib/libncurses.so.5 (0×40023000)

        libdl.so.2 => /lib/libdl.so.2 (0×40065000)

        libc.so.6 => /lib/libc.so.6 (0×40069000)

        /lib/ld-linux.so.2 (0×40000000)

ln

Make links between files.


$ ln -s data.txt symlink.txt


logname


Print user’s login name.


$ logname


smallfoot


ls


List directory contents.


$ ls


copy_of_lorem.txt  lorem.txt  moo.txt  www


man


Opens the manual page for a software or function.


$ man bash


md5sum


Outputs the MD5 hash sum of a file.


$ md5sum lorem.txt


56da9e37259af34345895883e6fd1a27  lorem.txt


mkdir


Makes a directory.


$ mkdir foobar


mv


Moves a file.


$ mv lorem.txt ipsum.txt


nl


Number lines of files.


$ nl lorem.txt


     1  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

     2  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim

     3  veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea

     4  commodo consequat. Duis aute irure dolor in reprehenderit in voluptate

     5  velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint

     6  occaecat cupidatat non proident, sunt in culpa qui officia deserunt

     7  mollit anim id est laborum.


nm


List symbols from object files.


$ nm hello_world


080494a0 D _DYNAMIC

0804956c D _GLOBAL_OFFSET_TABLE_

08048474 R _IO_stdin_used

         w _Jv_RegisterClasses

08049490 d __CTOR_END__

0804948c d __CTOR_LIST__

08049498 d __DTOR_END__


od


Dump files in octal and other formats.


$ od -t x /bin/sh


2376640 00098020 000054d4 00000000 00000000

2376660 00000020 00000000 000000c7 00000008

2376700 00000003 080e6500 0009d4f4 00004ae8


pidof


Find the process ID of a running program.


$ pidof fetchmail


22392


ping


Pings a host.


$ ping -c 2 127.0.0.1


PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.048 ms

64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.052 ms


— 127.0.0.1 ping statistics —

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 0.048/0.050/0.052/0.002 ms


ps


Outputs running processes.


$ ps


  PID TTY          TIME CMD

21542 pts/12   00:00:00 bash

27706 pts/12   00:00:00 ps


pstree


Display a tree of processes.


$ pstree


init-+-2*[BitchX]

     |-3*[bash—sleep]

     |-fetchmail

     |-screen-+-bash—irssi

     |        `-bash—ctorrent

     |-screen-+-bash—lisp.run

     |        |-bash—vi

     |        |-2*[bash]

     |        `-bash—lynx

     |-2*[screen—bash—irssi]

     |-screen—irssi

     |-screen—bash

     |-screen-+-bash

     |        `-irssi

     |-skjerm—irssi

     |-sshd-+-5*[sshd—sshd—bash—irssi]

     |      |-8*[sshd—sshd—bash]

     |      |-sshd—sshd—bash—screen

     |      |-sshd—sshd

     |      `-sshd—sshd—bash—pstree

     `-syslog-ng


pwd


Outputs the name of current working directory.


$ pwd


/home/smallfoot


rm


Removes a file or directory.


$ rm lorem.txt


rmdir


Removes a directory.


$ rmdir foobar


sed


Stream editor for filtering and transforming text.


$ echo “My cat’s name is Bob” | sed -e ’s/Bob/Mittens/g’


My cat’s name is Mittens


sha1sum


Outputs the SHA1 hash sum of a file.


$ sha1sum lorem.txt


c942ddebd142ec8bacac9213d48096e74bab4957  lorem.txt


shutdown


Bring the system down in a secure way. All logged-in users are notified that the system is going down.


$ shutdown now


size


List section sizes and total size.


$ size /bin/bash


   text    data     bss     dec     hex filename

 621233   22712   19176  663121   a1e51 /bin/bash


stat


Outputs file status.


$ stat lorem.txt


  File: `lorem.txt’

  Size: 453             Blocks: 8          IO Block: 4096   regular file

Device: 77h/119d        Inode: 27312217    Links: 1

Access: (0644/-rw-r–r–)  Uid: ( 1478/smallfoot)   Gid: (  100/   users)

Access: 2007-03-03 12:24:39.000000000 +0000

Modify: 2007-03-03 12:24:39.000000000 +0000

Change: 2007-03-03 12:24:39.000000000 +0000


strings


Print the strings of printable characters in files.


$ strings hello_world


/lib/ld-linux.so.2

_Jv_RegisterClasses

__gmon_start__

libc.so.6

puts

_IO_stdin_used

__libc_start_main

GLIBC_2.0

PTRh%

[^_]

Hello World!


tail


Output the last part of files.


$ tail -2 lorem.txt


occaecat cupidatat non proident, sunt in culpa qui officia deserunt

mollit anim id est laborum.


talk


Talk to another user.


$ talk bob Lookout for the dopefish!


touch


Change a file’s access and modification timestamps. If file does not exist, create it.


$ touch lorem.txt


tty


Outputs the name of the current terminal.


$ tty


/dev/pts/16


uname


Outputs operating system, hostname, kernel version, date and timp, and processor.


$ uname -a


Linux anapnea.net 2.6.9 #1 SMP Wed Jul 19 16:24:18 MSD 2006 i686 Intel(R) Xeon(TM) CPU 2.80GHz GenuineIntel GNU/Linux


uptime


Outputs the system uptime.


$ uptime


 14:50:26 up 7 days, 17:52, 18 users,  load average: 0.08, 0.02, 0.01


users


Print the user names of users currently logged in to the current host.


$ users


alice bob charlie eve


vdir


List directory contents.


$ vdir


total 8

-rw-r–r– 1 smallfoot users 453 Mar  3 12:32 copy_of_lorem.txt

-rw-r–r– 1 smallfoot users 453 Mar  3 12:24 lorem.txt

-rw-r–r– 1 smallfoot users   0 Mar  3 12:32 moo.txt

lrwxr-xr-x 1 root      root   18 Feb 27 19:33 www -> /var/www/smallfoot


w


Show who is logged on and what they are doing.


$ w


 12:14:30 up 5 days, 15:16, 19 users,  load average: 0.00, 0.00, 0.00

USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT

charlie  pts/0     Fri21    3:26m  2.52s  2.52s irssi

alice    pts/2     Wed17   30:21m  0.00s  0.00s -bash

emma     pts/4     11:37   36:57   0.00s  0.00s -bash

frank    pts/5     11:48   11:03   0.00s  0.00s -bash

smallfoo pts/12    12:01    0.00s  0.04s  0.01s w


wall


Send a message to everybody’s terminal.


$ wall next week we change the server for a new one


wc


Counts lines in a file.


$ wc -l lorem.txt


7 lorem.txt


whatis


Search the whatis database for complete words.


$ whatis bash


bash                 (1)  – GNU Bourne-Again SHell

bash [builtins]      (1)  – bash built-in commands, see bash(1)


who


Outputs who is currently logged into the system.


$ who


charlie  pts/0        Mar  2 21:37 (xtreme-11-65.acme.com)

alice    pts/2        Feb 28 17:48 (147.21.16.3)

emma     pts/4        Mar  3 11:37 (32.84-48-181.uac.com)

frank    pts/5        Mar  3 11:48 (port-212-202-233-2.foobar.org)

smallfoot pts/12       Mar  3 12:01 (c-12776f4.cust.example.net)


whereis


Locate the binary, source, and manual page files for a command.


$ whereis bash


bash: /bin/bash /etc/bash /usr/share/man/man1/bash.1.gz


whoami


Outputs your username / the name of your account.


$ whoami


smallfoot

"Useful Commands For The Linux Command Line"