Deploying Rails App On Ec2

9,105 views

Published on

Published in: Technology
2 Comments
6 Likes
Statistics
Notes
No Downloads
Views
Total views
9,105
On SlideShare
0
From Embeds
0
Number of Embeds
340
Actions
Shares
0
Downloads
0
Comments
2
Likes
6
Embeds 0
No embeds

No notes for slide

Deploying Rails App On Ec2

  1. 1. Deploying Rails app on Amazon EC2 By: Manik Juneja Akhil Bansal
  2. 2. Introduction <ul><li>Manik Juneja </li></ul><ul><ul><li>[email_address] </li></ul></ul><ul><ul><li>http://fromdelhi.com </li></ul></ul><ul><li>Akhil Bansal </li></ul><ul><ul><li>[email_address] </li></ul></ul><ul><ul><li>http://webonrails.com </li></ul></ul>
  3. 3. Intended audience <ul><li>We assume that you are aware of: </li></ul><ul><ul><li>Amazon Simple Storage System(S3) </li></ul></ul><ul><ul><li>Basic Ruby and Rails </li></ul></ul><ul><ul><li>Deployment tool “Capistrano” </li></ul></ul><ul><ul><li>Rails deployment with Apache and Mongrel Clusters </li></ul></ul>
  4. 4. What is Amazon EC2? <ul><li>EC2 stands for Elastic Compute Cloud </li></ul><ul><li>A Beta web service from Amazon </li></ul><ul><li>Provides resizable compute capacity in the cloud </li></ul><ul><li>Makes on-demand web computing easier </li></ul>
  5. 5. What Amazon Gives? <ul><li>Hardware </li></ul><ul><ul><li>CPU capacity of 1.0-1.2 GHz 2007 Opteron </li></ul></ul><ul><ul><li>Instances with 1.7, 7.5 and 15 GB memory. </li></ul></ul><ul><li>Internet & Intranet </li></ul><ul><li>Power </li></ul><ul><li>Public Amazon Machine Images(AMIs) </li></ul>
  6. 6. No Backup and Restore Services But
  7. 7. <ul><li>Deploying Rails app on EC2 </li></ul>
  8. 8. Deploying Rails app on EC2 <ul><li>Run your instance and: </li></ul><ul><ul><li>Install Ruby and Rubygems </li></ul></ul><ul><ul><li>Install Rails and other required gems </li></ul></ul><ul><ul><li>Install Webserver </li></ul></ul><ul><ul><li>Install DBMS and create DB </li></ul></ul><ul><ul><li>Write Capistrano Script </li></ul></ul>
  9. 9. OR
  10. 10. Use a rubyforge project “ec2onrails”
  11. 11. Deploying Rails app on EC2 <ul><li>We'll use ruby gem “EC2 on Rails” </li></ul><ul><li>Developed by a Canadian developer Paul Dowman </li></ul><ul><li>http://pauldowman.com/ </li></ul><ul><li>EC2 on Rails's AMI </li></ul>
  12. 12. Features of the EC2onrails AMI: <ul><li>Ubuntu 7.10 “Gutsy” </li></ul><ul><li>MySQL 5 </li></ul><ul><li>Ruby 1.8.6 </li></ul><ul><li>Ruby on Rails 1.2.5 </li></ul><ul><li>Automatic backup of MySQL database to S3. </li></ul><ul><li>Amazon AMI tools installed </li></ul><ul><li>32-bit and 64-bit images available </li></ul>
  13. 13. Lets Deploy <ul><li>gem install ec2onrails </li></ul><ul><li>Put Capfile in the RAILS_ROOT </li></ul><ul><li>Put deploy.rb and s3.yml in the config </li></ul><ul><li>export JAVA_HOME= <PATH> </li></ul><ul><li>Signup for S3 and Amazon EC2 </li></ul><ul><li>mkdir /home/akhil/.ec2 </li></ul><ul><li>Put X.509 certificate and private key in .ec2 </li></ul>
  14. 14. Cont... <ul><li>Download the Amazon EC2 Command-Line Tools </li></ul><ul><li>export EC2_HOME= <path-to-tools> </li></ul><ul><li>export PATH=$PATH:$EC2_HOME/bin </li></ul><ul><li>export EC2_PRIVATE_KEY=~/.ec2/ private_key </li></ul><ul><li>export EC2_CERT=~/.ec2/ certificate </li></ul>
  15. 15. Cont... <ul><li>Generate a Keypair: </li></ul><ul><li>ec2-add-keypair gsg-keypair </li></ul><ul><li>The private key returned needs to be saved in a local file so that you can use it later </li></ul>
  16. 16. Cont... <ul><li>Running an Instance: </li></ul><ul><ul><li>ec2-run-instances ami-86c025ef -k gsg-keypair </li></ul></ul><ul><ul><li>RESERVATION r-64f61f0d 110620076136 default </li></ul></ul><ul><ul><li>INSTANCE i-b1b740d8 ami-86c025ef pending gsg-keypair 0 m1.small 2007-12-05T06:15:38+0000 </li></ul></ul>
  17. 17. Cont... <ul><li>ec2-describe-instances i-b1b740d8 </li></ul><ul><ul><li>RESERVATION r-64f61f0d 110620076136 default </li></ul></ul><ul><ul><li>INSTANCE i-b1b740d8 ami-86c025ef </li></ul></ul><ul><ul><li>ec2-67-202-1-178.z-2.compute-1.amazonaws.com </li></ul></ul><ul><ul><li>domU-12-31-35-00-49-A2.z-2.compute-1.internal </li></ul></ul><ul><ul><li>running gsg-keypair 0 m1.small </li></ul></ul><ul><ul><li>2007-12-05T06:15:38+0000 </li></ul></ul>
  18. 18. Cont... <ul><li>Authorizing Network Access to Your Instances </li></ul><ul><li>ec2-authorize default -p 22 </li></ul><ul><li>ec2-authorize default -p 80 </li></ul>
  19. 19. Cont... <ul><li>Connecting to your Instance </li></ul><ul><li>ssh -i id_rsa-gsg-keypair [email_address] </li></ul><ul><li>passwd admin </li></ul><ul><li>passwd app </li></ul>
  20. 20. Cont... <ul><li>Modify s3.yml </li></ul><ul><li>Modify deploy.rb </li></ul><ul><li>cap ec2onrails:setup </li></ul><ul><li>cap deploy:migration s </li></ul>
  21. 21. Cont... <ul><li>Other capistrano tasks </li></ul><ul><li>ec2onrails:db:archive </li></ul><ul><li>ec2onrails:db:restore </li></ul><ul><li>ec2onrails:db:create </li></ul><ul><li>ec2onrails:db:drop </li></ul><ul><li>ec2onrails:db:recreate </li></ul><ul><li>ec2onrails:db:set_root_password </li></ul><ul><li>ec2onrails:ami_ids - Shows the AMI id’s of the images that match the current version of the gem. </li></ul><ul><li>ec2onrails:setup - This is a convenience task to get a new instance completely set up in one step, everything except deploying the app. </li></ul><ul><li>ec2onrails:restore_db_and_deploy - Another convenience task to recreate the db, restore data to it from an s3 bucket and deploy the app, useful to set up a staging server. </li></ul>
  22. 22. Public IP Your Instances <ul><li>wget http://169.254.169.254/latest/meta-data/public-ipv4 from your Instance </li></ul>
  23. 23. Terminating Your Instances <ul><li>ec2-terminate-instances i-b1b740d8 </li></ul><ul><li>RESERVATION r-64f61f0d 110620076136 default </li></ul><ul><li>INSTANCE i-b1b740d8 ami-86c025ef </li></ul><ul><li>ec2-67-202-1-178.z-2.compute-1.amazonaws.com </li></ul><ul><li>domU-12-31-35-00-49-A2.z-2.compute-1.internal </li></ul><ul><li>shutting-down gsg-keypair 0 m1.small </li></ul><ul><li>2007-12-05T06:15:38+0000 </li></ul>
  24. 24. Check status of instances <ul><li>ec2-describe-instances </li></ul><ul><li>RESERVATION r-64f61f0d 110620076136 default </li></ul><ul><li>INSTANCE i-b1b740d8 ami-86c025ef terminated </li></ul><ul><li>gsg-keypair 0 m1.small 2007-12-05T06:15:38+0000 </li></ul>
  25. 25. Run and Manage Instances online <ul><li>We know this one service which let us mange instances online: </li></ul>RightScale.com
  26. 26. Benefits <ul><li>Ability to Start, terminate, and monitor instances, using the web service APIs. </li></ul><ul><li>Free Data transferred within the Amazon EC2 environment, or between Amazon EC2 and Amazon S3 </li></ul><ul><li>Pay for the instance-hours and bandwidth that you actually consume. </li></ul>
  27. 27. Points to consider: <ul><li>Data loss when instance is terminated </li></ul><ul><li>Instance gets a new public IP when started again </li></ul><ul><li>Need to use third party Dynamic DNS service, like “easydns.com”. </li></ul>
  28. 28. Thanks

×