用Ruby on Rails开发Facebook应用(5) – Amazon EC2
// September 16th, 2008 // 3 Comments » // Ruby, 编程开发
Amazon EC2不是什么新东西了,不过从cheewu那里得知他的垂直搜索引擎是用EC2的。偶也有兴趣试用一下,反正钱也不多,呵呵
EC2其实是虚拟化的一台机器,物理上来讲书也不知道你自己的实例在群里的那个部分运行着。不过这并不重要,重要的是只要你想,就可以随时在Amazon的computer farm上开出一块自己的”自留地”,计算能力可以选择的,也支持多个实例组成cluster.
Virtualization已经是当今的潮流,估计不用普及了,现在用电脑的,最少也用过VMware吧。呵呵。使用EC2只要简单的几个条件:
- 在amazon AWS上注册一个id
- 把EC2 服务加到你的AWS id服务中来(点一个按钮即可,但是很多人不知道,一些教程里面也没写,少了这个步骤,会导致ssl授权通不过的问题,切记)
- 一个可供网上支付的信用卡,VISA,Mastercard,AE什么的都可以
ok,添好这些,就可以使用EC2的服务了。别着急,您至少先看看收费标准吧EC2 price
都没问题了我们就可以在本地setup EC2的使用环境了。具体可以看这里EC2 Getting Start,我就不罗嗦了。
觉得命令行麻烦的话,推荐一个Firefox插件Elasticfox,大大简化的EC2的操作。反正我是不喜欢用ec2那些奇怪的命令。呵呵。命令行控们可以看这篇How To: Getting Started with Amazon EC2
有个虚拟的机器,用什么OS呢?Amazon上面已经有很多现成的AMI了,把他理解成定制好的系统,可以直接启动。你只要在启动EC2 instance的时候指定某个AMI的ID就可以了。对于Ruby on Rails来说,我推荐EC2onRail的AMI,有32bit和64bit两个版本:
- ami-c9bc58a0 (32-bit)
- ami-cbbc58a2 (64-bit)
几乎你会用到的东西在AMI里面都是ready的:
Features of the EC2 image:
- Ready to deploy a Rails app with little or no configuration of the server required
- Automatic backup of MySQL database to S3 (full backup nightly + incremental backup using binary logs every 5 minutes)
- Capistrano tasks to customize the server image, archive and restore the database to/from S3, and more (available as a rubygem)
- Mongrel_cluster behind Apache 2.2, configured according to
Coda Hale’s excellent guide
- Ruby on Rails 2.1.0, 2.0.2 and 1.2.6
- Ruby 1.8.6
- MySQL 5
- memcached
- monit configured to monitor apache, mongrel, mysql, memcached, drive space and system load
- Ubuntu 8.04 LTS “Hardy” base image built using Eric Hammond’s EC2 Ubuntu script
- SSL support
- Amazon AMI tools installed
- MySQL, Apache, and syslog configured to use /mnt for data and logging so you don’t fill up EC2’s small root filesystem
- Automatically archives Rails and Apache logs to S3 nightly.
- 32-bit and 64-bit images available (supports all instance types, small to extra large).
- Created using a build file, full source is available (the EC2 on Rails script is run from Eric Hammond’s EC2 Ubuntu script)
- Can be used as a clustered Rails app running on multiple instances
- Automatically runs hourly, daily, weekly and monthly scripts if they exist in Rails application’s script directory
- Local Postfix SMTP mail server (only available from within the instance, not listening on external network interfaces)
如果你自己还需要别的东西的话,尽可以自己安装(Ubuntu的apt-get或者手动),然后把Image传到S3上就成为自己定制的AMI了。具体过程不难,请参考这个小短文HOWTO Build EC2 image
EC2 instance ready了还没完,你自己的本地开发环境也要作一些事情
- sudo gem install ec2rails
- copy capify,deploy 脚本到你的app目录下(用过capistrano的人都知道)
- run capistrano task吧。集体还是看ec2rails的说明
ok,建一个自己的instance尽情享受root的快感去吧

