使用Capistrano在AWS EC2上部署Rails应用程序

时间:2013-03-22 20:28:34

标签: ruby-on-rails deployment amazon-ec2 capistrano

我正在尝试在AWS-EC2实例上部署带有Capistrano的Rails应用程序,在另一个用户的家中使用默认用户(Ubuntu),但它会给我一个“Permission Denied”错误。这是我的代码:

server "9.9.9.9", :web, :app, :db, primary: true

set :application, "some_app"
set :user, "ubuntu"
set :keep_releases, 3
set :location, "9.9.9.9"
ssh_options[:keys] = ["~/Keys/serverkey.pem"]
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :use_sudo, false

task :hello do
  run "echo 'Hello World' > /home/other_user/i_was_here.txt"
end

这是输出:

$ cap hello
  * 2013-03-22 14:11:29 executing `hello'
  * executing "echo 'Hello World' > /home/other_user/i_was_here.txt"
    servers: ["9.9.9.9"]
    [9.9.9.9] executing command
 ** [out :: 9.9.9.9] sh: cannot create /home/other_user/i_was_here.txt: Permission denied
    command finished in 798ms
failed: "sh -c 'echo '\\''Hello World'\\'' > /home/other_user/i_was_here.txt'" on 9.9.9.9

可能有什么不对?目的是为另一个用户部署Rails应用程序,所以我有一些疑问:

  1. 有没有办法直接与其他用户在AWS-EC2实例上部署Rails应用程序?
  2. 如果#1的答案是“否”,那么使用默认用户Ubuntu为其他用户部署Rails应用程序的正确方法是什么? (当其他用户尝试访问应用程序时,将来不会出现权限问题)
  3. 在服务器中管理很多用户,因为我们想要为每个用户获取存储和带宽,所以我们这样做,直到今天我们开始使用Capistrano哈哈。

    提前致谢。

4 个答案:

答案 0 :(得分:1)

通常是作为应该运行/维护应用程序的用户进行部署。否则你必须确保两个用户都没有搞乱权限。

此方案的原因是您不想共享凭据吗?如果是这样,请考虑使用为每个用户添加到.ssh/authorized_keys的特殊部署ssh密钥。

答案 1 :(得分:1)

从您的配置文件中删除ssh_options[:forward_agent] = true行,即使我有同样的问题,我删除了这一行,现在它正常工作

答案 2 :(得分:1)

谢谢大家的回答。我所做的是按照这些步骤与Capistrano与特定用户联系。

http://utkarshsengar.com/2011/01/manage-multiple-accounts-on-1-amazon-ec2-instance/

答案 3 :(得分:0)

ubuntu用户无权访问other_user的主目录,除非使用了sudo,或者您更改了/ home / other_user的权限。

如果您想以other_user身份运行应用程序,最好的方法是将capistrano配置为other_user。您需要将公共ssh密钥添加到/home/other_user/.ssh/authorized_keys。如果您希望应用程序以ubuntu身份运行,请部署到/ home / ubuntu。