-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
386 lines (370 loc) · 21.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Emphasized Insanity - Rails and Amazon EC2 - Beginners guide</title>
<link href="/stylesheets/bundle_github.css" media="screen" rel="stylesheet" type="text/css">
<link href="/stylesheets/bundle_common.css" media="screen" rel="stylesheet" type="text/css">
<script type="text/javascript" charset="utf-8">
var GitHub = {}
var github_user = 'eladmeidar'
</script>
<script src="/javascripts/jquery.js" type="text/javascript"></script>
<script src="/javascripts/bundle_common.js" type="text/javascript"></script>
<script src="/javascripts/bundle_github.js" type="text/javascript"></script>
<link href="http://blog.eizesus.com/feed/atom.xml" rel="alternate" title="Emphasized Insanity" type="application/atom+xml">
<meta name="description" content="Ruby on Rails developer blog">
</head>
<body>
<div class="subnavd" id="main">
<div id="header" class="pageheaded">
<div class="site">
<div class="logo">
<a href="/"><h1>Emphasized Insanity</h1></a>
</div>
<div class="userbox">
<div class="inner">
<div class="avatarname">
<a href="http://github.com/eladmeidar"><img alt="" src="/images/eladmeidar.jpg" height="20" width="20"></a>
<a href="http://twitter.com/eladmeidar" class="name">@eladmeidar</a>
</div>
<ul class="usernav">
<li><a href="/about.html">About me</a></li>
<li><a href="http://www.linkedin.com/in/eladmeidar">LinkedIn</a></li>
<li><a href="http://workingwithrails.com/person/5844-elad-meidar">WWR</a></li>
<li><a href="http://github.com/eladmeidar">GitHub</a></li>
<li><a href="http://www.nautilus6.com">My Company</a></li>
</ul>
</div>
</div><!-- /.userbox -->
<div class="topsearch">
<form action="http://www.google.com/search?sitename=blog.eizesus.com" id="top_search_form" method="get">
<input autocomplete="off" class="search my_repos_autocompleter notnative placeholder ac_input" name="q" results="5" placeholder="Search…" type="search"> <input value="Search" class="button" type="submit">
<input type="hidden" name="sitesearch" value="blog.eizesus.com" checked=""/>
</form>
<ul class="nav">
<li><a href="/archive.html">Explore Emphasized Insanity</a></li>
</ul>
</div>
</div>
</div>
<div class="site">
<div class="pagehead repohead vis-public">
<h1> <a href="/">Emphasized Insanity</a> / <strong><a href="/">Blog</a></strong> </h1>
<ul class="actions">
<li> <a href="http://blog.eizesus.com/feed/atom.xml" class="minibutton btn-watch " id="watch_button" style=""><span><span class="icon"></span>Subscribe</span></a></li>
<li class="for-notforked" style=""><a href="#disqus-comments" class="minibutton btn-fork " id="fork_button"><span><span class="icon"></span>Comment</span></a></li>
</ul>
<ul class="tabs">
<li><a href="/" class="selected" highlight="repo_source">Source</a></li>
<li><a href="/archive.html" highlight="repo_commits">Archive</a></li>
<li><a href="http://www.railsbridge.org" highlight="issues">RailsBridge</a></li>
<li class="contextswitch nochoices">
<span class="toggle leftwards">
<em>Branch:</em>
<code>master</code>
</span>
</li>
</ul>
<div class="subnav-bar">
<ul>
<li>
<a href="#" class="dropdown">Switch Branches (1)</a>
<ul>
<li><strong>master ✓</strong></li>
</ul>
</li>
</ul>
</div>
<div id="repo_details" class="metabox clearfix pledgified">
<div id="repo_details_loader" class="metabox-loader" style="display: none;">Sending Request…</div>
<a href="#pledgie_box" rel="facebox" title="Brought to you by pledgie.com" class="pledgie pledgie-button for-owner tooltipped" id="activate_pledgie_button" style="display: none;"><span>Enable Donations</span></a>
<div id="pledgie_box" style="display: none;">
<h2>Pledgie Donations</h2>
</div>
<div id="repository_description" rel="repository_description_edit">
<p>
This is the personal homepage of Elad Meidar, a web developer and an entrepreneur specializing in Ruby on Rails. I am a proud member of <a href="http://www.railsbridge.org">RailsBridge</a>, Helping new <a href="http://www.railsmentors.org/users/185">Rails developers</a> get into our world and also contributed a few <a href="http://contributors.rubyonrails.org/contributors/elad-meidar/commits">Patches</a> to the Ruby on Rails core.
</p>
<p>
I hang around Fort Lauderdale, FL and Tel-Aviv in Israel, and i am currently running <a href="http://www.nautilus6.com">Nautilus6</a> so Feel free to contact me regarding projects :).
</p>
</div>
</div>
</div><!-- /.pagehead -->
<div id="commit">
<div class="group">
<div class="envelope commit">
<div class="human">
<div class="message"><pre>Recent Posts</pre></div>
<div class="actor">
<div class="gravatar">
<img alt="" src="images/eladmeidar.jpg" height="30" width="30">
</div>
<div class="name"><a href="/">Elad Meidar</a>
<span>(author)</span>
</div>
<div class="date">
<abbr class="relatize relatized" title="1984-06-19 06:06:07">about 25 years ago</abbr>
</div>
</div>
</div>
<div class="machine">
<span>c</span>ommit <a href="#" hotkey="c">60fa264c54341711baef087347105a5b9dd68863</a><br>
<span>t</span>ree <a href="#" hotkey="t">508268ee6774e5c6060585718705f1ec7afa80d8</a><br>
<span>p</span>arent <a href="#" hotkey="p">179f7c0440e6073779efc40366c6ced3a9888f71</a>
</div>
</div>
</div>
</div>
<div id="path">
<b><a href="/2009/01/rails-and-amazon-ec2-beginners-guide">Rails and Amazon EC2 - Beginners guide</a></b> /
</div>
<div id="browser">
<table cellpadding="0" cellspacing="0">
<tbody><tr>
<th></th>
<th width="400p">name</th>
<th>age</th>
<th>
history
</th>
</tr>
<tr class="alt">
<td class="icon"> <img alt="file" src="/images/txt.png"> </td>
<td class="content">
<a href="/2009/01/rails-and-amazon-ec2-beginners-guide" id="d8f8d46921aa81abc4c0d27703a8908333ae38c3">Rails and Amazon EC2 - Beginners guide</a>
</td>
<td class="age">
<span class="relatize relatized">18/01/2009</span>
</td>
<td class="message">
<a href="/2009/01/rails-and-amazon-ec2-beginners-guide" class="message" title="another post">Another post</a> [Elad Meidar]
</td>
</tr>
</tbody></table>
</div>
<div id="readme" class="announce"><span class="name"></span>
<div class="wikistyle">
<p>First of all, Amazon <span class="caps">AWS</span> rocks. it’s a great, stable and not so expensive way to get your application up and running, but also ready for any disaster to come (Someone said Digg effect?).<br />
Getting your application on to Amazon EC2 is not as complicated as you think, managing and controlling your instances may require a professional system administrator, but i would recommend that anyway (except if you go and host your application on EngineYard than you are worry-free, but you’ll pay.. ohh you’ll pay for that sense of security).<br />
<br />
<h2>Get your application Ready</h2><br />
<p><br />
There is no real need to setup your EC2 instances in day 1, you can wait until the application is mature enough to be deployed onto a production infrastructure. Amazon EC2 costs per usage, so, it will cost you to have your application up and running on EC2, keep that in mind (although the prices are a joke).<br /></p>
</p>
<h2>Setting things up</h2>
<p>
<p>Once your application is ready to be deployed to EC2, you’ll need an image.<br />
Image, in EC2 terms, is a reference to an OS + all required installations and configuration needed to run your application.<br />
The best all-round image to use with rails is <a href="http://github.com/pauldowman/ec2onrails/tree/master">Pawl Dowman’s Rails on EC2 bundle</a> (or <a href="http://ec2onrails.rubyforge.org/">here</a>). EC2onRails is great. Unfortunately, if you�ve never used EC2 before, you probably won�t be able to �Deploy a Ruby on Rails app on EC2 in Five Minutes� as the documentation claims, so this document will try to fill in the gaps for someone who has never worked with EC2.</p>
</p>
<p>
<p><em>note: it’s never too early to sit down and read <a href="http://docs.amazonwebservices.com/AWSEC2/2007-08-29/GettingStartedGuide/running-an-instance.html">Amazon’s documentations</a>, they are not that bad</em></p>
</p>
<h3>Local Machine</h3>
<p>
<p>First thing is first, your development machine, the one from which you will be deploying to EC2 should undoubtably hold:<br />
<ul><br />
<li>Ruby on Rails (do yourself a favor, at least version 2.1)</li><br />
<li>MySQL (Well, we are going to work with RailsOnEC2, which includes it, if you need another db.. you’ll need another image).</li><br />
<li>Java Development Kit 1.5 or later installed.<br/>
Mac users should be ready-to-go (Hah! Hah!), Windows/Linux users if you don�t have it, download it from <a href="http://java.sun.com/javase/downloads/index.jsp">Sun’s website</a>. <br />
Make sure to download a version labeled �<b><span class="caps">JDK</span></b>�. <br />
Java is required for the tools that Amazon provides to manage EC2 instances. (rumor says that there are ruby management tools also, but i prefer the ones that Amazon gives).</li></p>
</ul>
<p><a name="setup_account"> </a><br />
<h3>Signing up for the services</h3><br />
<p><br />
Once you are set with these issues, you’ll need to sign up for the Amazon EC2 service, do that right <a href="http://aws.amazon.com/ec2/">here</a>.<br />
Now, sign up for the S3 service.</p>
</p>
<h4>Why i need to sign up to S3?</h4>
<p>
<p>Because although your image (later: ‘instance’) includes storage, images/instances can be brought down, up, dropped and even deleted, that will ultimately, kill your data.</p>
</p>
<p>
<p>S3 is Amazon�s �Simple Storage Service�. S3 is a super-inexpensive service to store files into �buckets in the cloud�. S3 will be used for database backups of your Rails Application.<br />
Sign up for S3 <a href="http://aws.amazon.com/s3/">here</a>.<br />
<p></p>
<h4>Important Information you’ll need to keep somewhere</h4>
<p>
<p>After signing up, you will need to collect four pieces of information from your <span class="caps">AWS</span> account by visiting the <a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key">Access Identifiers page</a>.<br />
<ul><br />
<li><b>Your account number.</b> The account number can be found at the upper right of the Access Identifiers page and should be three four-digit numbers separated by dashes.</li><br />
<li><b>Your Access Key ID.</b> This is a 20 or so character key found in a beige box a little below your account number.</li><br />
<li><b>Your Secret Access Key.</b> This is a 40 or so character key found in another beige box just below your Access Key ID. If this is your first time on this page, you may have to generate your key. Click the �Show� button to display your 40 character key.</li><br />
<li><b>Your X.509 Certificate</b> Create and download the X.509 certificate below the Secret Access Key section. Place the public and private keys into a folder called �.ec2? in your home directory.</li></p>
</ul>
<p><strong>double check it! it’s very very very very important. </strong></p>
</p>
<h3>Setting up the development machine</h3>
<h4>Download And Installation EC2 Command Line Tools</h4>
<p>
<p>The EC2 command-line tools are a Java-based set of tools that allow you to create and manage machine instances on EC2.<br />
Download it <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88">here</a> and extract the zip file, remember where you put it, i always keep it in my home folder as a hidden folder named .ec2 (/Users/eizesus/.ec2/ on <span class="caps">OSX</span>).</p>
</p>
<h4>Setting the Environment Variables</h4>
<p>
<p>Run these commands:<br />
<pre class="brush: bash"><br />
export EC2_PRIVATE_KEY=/Users/eizesus/.ec2/pk-5xxxxxxxx7.pem<br />
export EC2_CERT=/Users/eizesus/.ec2/cert-5xxxxxxxxxxxxx7.pem<br />
export EC2_HOME=/Applications/java/ec2-api-tools-1.3-24159<br />
export <span class="caps">PATH</span>=$EC2_HOME/bin:$<span class="caps">PATH</span><br />
</pre><br />
<strong>Remember to replace my library with yours.</strong></p>
</p>
<p>
<p>I suggest adding these lines to your startup profile, whatever it maybe on your OS. (<span class="caps">OSX</span>, it’s in /etc/profile).<br />
After you do that, reload your session (closing the console/command line and opening it again should do).</p>
</p>
<p><a name="ec2_keypair"> </a><br />
<h4>Create an <span class="caps">SSH</span> Key Pair</h4><br />
<p><br />
Run this at the command line:<br />
<pre class="brush: bash"><br />
ec2-add-keypair my-secret-code<br />
</pre><br />
The string <code>my-secret-code</code> can and should be anything that you like, try to pick something that makes sense for your setup (remember that i will keep on writing my-secret-code, use your phrase instead).</p>
</p>
<p>
<p>Save the output from that into a file named <code>id_rsa-my-secert-code</code> on your <span class="caps">SSH</span> library (OS dependent) and paste everything between (and including) the <code>��BEGIN RSA PRIVATE KEY��</code> and <code>��END RSA PRIVATE KEY��</code> lines into it. Confirm that the file contents looks exactly like this, then save the file into the file.<br />
<pre class="brush: bash"><br />
~/.ssh/id_rsa-my-secret-code<br />
</pre><br />
And set the appropriate permissions on the new key file:<br />
<pre class="brush: bash"><br />
chmod 600 ~/.ssh/id_rsa-my-secret-code<br />
</pre></p>
</p>
<h2>Cloud Setup</h2>
<h3>Start Up an Amazon EC2 Instance</h3>
<p>
<p>An Amazon Machine Image (<span class="caps">AMI</span>) is a named configuration of an EC2 image.<br />
The current <span class="caps">AMI</span> id�s for <a href="http://ec2onrails.rubyforge.org/">EC2onRails</a> are:<br />
<ul><br />
<li>ami-c9bc58a0 (32-bit)</li><br />
<li>ami-cbbc58a2 (64-bit)</li></p>
</ul>
</p>
<p>
<p>Start up an instance of the 32-bit EC2onRails image:<br />
<pre class="brush: bash"><br />
ec2-run-instances ami-c9bc58a0 -k my-secret-code<br />
</pre><br />
The second line of the results returned will look like:<br />
<pre class="brush: bash"><br />
<span class="caps">INSTANCE</span> i-<span class="caps">XXXXXXXX</span> ami-c9bc58a0 pending my-secret-code 0<br />
</pre><br />
The <code>pending my-secret-code</code> part means that the image is pending for loading.</p>
</p>
<p>
<p>To check the status of the instance build type:<br />
<pre class="brush: bash"><br />
ec2-describe-instances i-<span class="caps">XXXXXXXX</span><br />
</pre>Replace the <code>i-XXXXXXXX</code> above with the string that comes after <code>INSTANCE</code> in the second line of the results from the <code>ec2-run-instances</code> command.<br/>
Run it again until it says <b>running </b><b>my-secret-code</b>, than you have an Amazon EC2 instance running! (yippie!). <br />
Take note of the string that looks like:<br />
<pre class="brush: bash"><br />
ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com<br />
</pre><br />
that is your machine�s address in the cloud.</p>
</p>
<h3>Authorize <span class="caps">SSH</span> and <span class="caps">HTTP</span></h3>
<p>
<pre class="brush: bash">ec2-authorize default -p 22</pre>
<p>should result in:<br />
<pre class="brush: bash"><span class="caps">PERMISSION</span> default <span class="caps">ALLOWS</span> tcp 22 22 <span class="caps">FROM</span> <span class="caps">CIDR</span> 0.0.0.0/0</pre><br />
and<br />
<pre class="brush: bash">ec2-authorize default -p 80</pre>should return something like:<br />
<pre class="brush: bash"><span class="caps">PERMISSION</span> default <span class="caps">ALLOWS</span> tcp 80 80 <span class="caps">FROM</span> <span class="caps">CIDR</span> 0.0.0.0/0</pre><br />
…you are up and ready to go!<br /></p>
</p>
<p>
<p>You should be able to ssh into the your new machine, replace <code>ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com</code> in the next command with the cloud address you just got.<br />
<pre class="brush: bash">ssh -i ~/.ssh/id_rsa-ec2-rails-keypair root@ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com</pre><br />
You may have to type �yes� to accept the authenticity of the host.</p>
</p>
<h3>Prepare Your Application for EC2</h3>
<p>
<p><a href="http://github.com/pauldowman/ec2onrails/tree/master">EC2 for Rails</a> requires <code>Capistrano:</code>:<br />
<pre class="brush: bash">sudo gem install capistrano -v 2.4.3</pre><br />
And then install the EC2 for Rails gem:<br />
<pre class="brush: bash">sudo gem install ec2onrails</pre><br />
Okay, you need to add three configuration files to your Rails application:<br />
<ol><br />
<li><a href="http://github.com/pauldowman/ec2onrails/tree/master/examples/Capfile?raw=true">Capfile</a> – save this file at the root of your application.</li><br />
<li><a href="http://github.com/pauldowman/ec2onrails/tree/master/examples/deploy.rb?raw=true">deploy.rb</a> – save this file in the /config folder.</li><br />
<li><a href="http://github.com/pauldowman/ec2onrails/tree/master/examples/s3.yml?raw=true">s3.yml</a> – also save this file in the /config folder.</li></p>
</ol>
</p>
<h3>Personalize your RailsOnEC2 Gem Configurations</h3>
<p>
<p>The capfile can an be left as-downloaded.<br/>
<code>config/s3.yml</code> – This configuration is pretty simple, under the production section, put your <span class="caps">AWS</span> information that you noted above.<br />
<pre class="brush: bash"> <br />
aws_access_key: (you got me when you signed up)<br />
aws_secret_access_key: (me too)<br />
bucket_base_name: production.yourname.com<br />
</pre><br />
<code>config/deploy.rb</code> – There are a lot of definitions to be made, read all the comments and setup the deploy process as your application requires.<br />
<code>config/database.yml</code> – For the production section, basically add any good password that you like and add <code>hostname: db_primary</code>. It should look something like:<br />
<pre class="brush: bash"><br />
production:<br />
adapter: mysql<br />
encoding: utf8<br />
database: appname_production<br />
username: user (not <span class="caps">ROOT</span>!)<br />
password: password (no, no empty passwords)<br />
hostname: db_primary<br />
</pre></p>
</p>
<h2>Finalize – Run the EC2 on Rails Capistrano Tasks</h2>
<pre class="brush: bash">
cap ec2onrails:get_public_key_from_server cap ec2onrails:server:set_roles
</pre>
<p>Configure the db and stuff:<br />
<pre class="brush: bash"><br />
cap ec2onrails:setup<br />
</pre><br />
And launch your app:<br />
<pre class="brush: bash"><br />
cap deploy:cold<br />
</pre>And wooooohoooo, check your application url.<br />
<br />
That’s it basically, you are up in the clouds (in a good way).</p>
</div>
<div id="disqus_thread"></div><script type="text/javascript" src="http://disqus.com/forums/emphasizedinsanity/embed.js"></script><noscript><a href="http://emphasizedinsanity.disqus.com/?url=ref">View the discussion thread.</a></noscript><a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
</div>
<div class="push"></div>
</div>
<div id="footer">
<div class="site">
<div class="info">
<div class="links">
</div>
<div class="company">
<script type="text/javascript" src="http://s51.sitemeter.com/js/counter.js?site=s51eizesusrulez"></script>
<a href="http://feeds.feedburner.com/EladOnRails"><img src="http://feeds.feedburner.com/~fc/EladOnRails?bg=FFFFFF&fg=660033&anim=0" height="26" width="88" style="border:0" alt="" /></a>
</div>
</div>
<div class="sponsor">
<div>
</div>
</div>
</div>
<div id="facebox" style="display: none;"> <div class="popup">
<table> <tbody> <tr> <td
class="tl"></td><td class="b"></td><td class="tr"></td> </tr>
<tr> <td class="b"></td> <td
class="body"> <div class="content"> </div>
<div class="footer"> <a href="#"
class="close"> <img src="index_files/closelabel.gif"
title="close" class="close_image"> </a>
</div> </td> <td class="b"></td>
</tr> <tr> <td class="bl"></td><td
class="b"></td><td class="br"></td> </tr> </tbody>
</table> </div> </div></body></html>