将nginx / rails / node应用程序部署到EC2上

时间:2011-11-19 02:29:38

标签: deployment amazon-ec2 nginx capistrano

基本问题

  • 我正在构建一个应用程序,并希望得到一些帮助将其部署到EC2
  • 我被告知我应该使用capistrano
  • 我的下一步是什么?

关于应用

  • simple rails app(3.1.1)
  • 简单节点app(0.4.2)
  • redis在rails和node(2.0.4)之间进行通信
  • nginx反向代理rails和node(1.0.6)
  • 数据库目前是sqlite(但很可能在不久的将来升级到mysql或mongo)
  • nginx.conf文件如下:

    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    http {
      include       mime.types;
      default_type  application/octet-stream;
    
      sendfile        on;
    
      keepalive_timeout  65;
    
      server {
        listen 80;
        server_name localhost;
    
        location / {
          proxy_pass http://localhost:3000/;
        }
    
        location /events/ {
          proxy_pass http://localhost:3001/;
          proxy_buffering off;
          proxy_read_timeout 1000s;
        }
      }
    }
    

关于EC2实例

  • ec2-12-34-56-789.compute-1.amazonaws.com
  • 基本的64位亚马逊Linux t1.micro(直到我让一切正常工作,然后我会找到一些其他的部署地点;可能是EC2,可能是机架空间,可能是完全不同的东西)

关于我的部署平台

  • OSX 10.6.8
  • 将以下内容存储在〜/ .ec2 /中(可能需要移动以使capistrano工作)

    cert-123456789ABCDEF0123456789ABCDEF0.pem
    pk-123456789ABCDEF0123456789ABCDEF0.pem
    ec2-keypair
    
  • 目前有以下deploy.rb(但它不能正常工作)

    set :application, "clashcentral"
    set :repository,  "git@github.com:HairyMezican/GameLobby.git"
    set :branch, "master"
    set :repository_cache, "git_cache"
    set :deploy_via, :remote_cache
    set :ssh_options, { :forward_agent => true }
    
    set :scm, :git
    ssh_options[:keys] = [File.join(ENV["HOME"], ".ec2", "ec2-keypair")] 
    
    role :web, "ec2-12-34-56-789.compute-1.amazonaws.com"
    role :app, "ec2-12-34-56-789.compute-1.amazonaws.com"
    role :db,  "ec2-12-34-56-789.compute-1.amazonaws.com", :primary => true
    

错误

  • 我得到的原始错误是connection failed for: ec2-12-34-56-789.compute-1.amazonaws.com (Net::SSH::AuthenticationFailed: Empty)
  • 当我在set :user, "ec2-user"行添加failed: "sh -c 'if [ -d /u/apps/clashcentral/shared/git_cache ]; then cd /u/apps/clashcentral/shared/git_cache && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd && git clean -q -d -x -f; else git clone -q git@github.com:HairyMezican/GameLobby.git /u/apps/clashcentral/shared/git_cache && cd /u/apps/clashcentral/shared/git_cache && git checkout -q -b deploy cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd; fi'" on ec2-12-34-56-789.compute-1.amazonaws.com
  • 时,我得到的当前错误

1 个答案:

答案 0 :(得分:1)

我相信你需要添加:

set :user, "ec2-user"

到您的deploy.rb文件,如下所示:http://wiki.dreamhost.com/Capistrano#Automate_Deployment_with_Capistrano_.28.22capify.22.29