【问题标题】:Capistrano deploy with gitosis and application server at the same server?Capistrano 在同一台服务器上部署 gitosis 和应用程序服务器?
【发布时间】:2012-11-19 14:23:09
【问题描述】:

我在同一个 VPS 服务器上构建了 gitosis 服务器和 stage 服务器。在我的本地机器或阶段服务器中从 gitosis 克隆存储库运行良好。但是本地机器中的cap deploy总是要求我输入如下密码,我不知道是哪个密码,我尝试了每个密码都不起作用。

我知道可以使用deploy_via: copy 复制本地存储库,但我更喜欢为其他项目构建一个 gitosis 服务器。

有什么想法吗?谢谢。

环境

gitosis 和阶段服务器 ip:106.187.xxx.xxx(出于安全原因屏蔽一些数字)

日志

  * executing `deploy'
    triggering before callbacks for `deploy'
  * executing `check:revision'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote gitosis@106.187.xxx.xxx:foo_project.git master"
    command finished in 1105ms
  * executing "if [ -d /home/deployer/apps/railsapp/shared/cached-copy ]; then cd /home/deployer/apps/railsapp/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 07827de89355c5366c4511ee22fdd9c68a31b0be && git clean -q -d -x -f; else git clone -q gitosis@106.187.xxx.xxx:foo_project.git /home/deployer/apps/railsapp/shared/cached-copy && cd /home/deployer/apps/railsapp/shared/cached-copy && git checkout -q -b deploy 07827de89355c5366c4511ee22fdd9c68a31b0be; fi"
    servers: ["106.187.xxx.xxx"]
    [106.187.xxx.xxx] executing command
 ** [106.187.xxx.xxx :: out] Password:
Password: 
 ** [106.187.xxx.xxx :: out]
 ** [106.187.xxx.xxx :: out] Password:
Password: 
 ** [106.187.xxx.xxx :: out]
 ** [106.187.xxx.xxx :: out] Password:
Password: 
 ** [106.187.xxx.xxx :: out]
 ** [106.187.xxx.xxx :: out] Permission denied (publickey,keyboard-interactive).
 ** [106.187.xxx.xxx :: out] fatal: The remote end hung up unexpectedly

部署.rb

server "106.187.xxx.xxx", :web, :app, :db, primary: true

set :application, "railsapp"
set :user, "deployer"
set :local_user, "joshchang"
set :deploy_to, "/home/#{user}/apps/#{application}"

set :use_sudo, false
set :rails_env, "stage"

set :scm, "git"
set :repository, "gitosis@106.187.xxx.xxx:foo_project.git"
set :deploy_via, :remote_cache
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

【问题讨论】:

    标签: ruby-on-rails capistrano gitosis


    【解决方案1】:

    抱歉,这个问题有点难以理解,但有两种方法可以在 capistrano 中使用 git。首先是授予服务器直接访问 git 存储库的权限;例如,在 GitHub 上,您可以选择安装“部署密钥”——需要访问的服务器的公钥。所以检查gitosis是否有这个选项。

    但在你做之前,考虑另一种方法,即通过用户的git授权进行部署,所以当你部署时,你自己拉,而不是指示服务器这样做。每种方法各有利弊,但我认为从长远来看,第二种方法更容易管理。

    要使用第二种方法,部署(运行capistrano)的人的机器需要1)有ssh-agent运行,2)需要使用ssh-add授权ssh-agent使用你的公钥——它非常安全,一旦设置好,它就是透明的。

    当你使用第二种方法时,对git的访问将与本地相同,因此不应提示输入密码。否则,您在deploy.rb 中的设置就可以了。

    【讨论】:

    • 嗨@tharrison,我在本地做了ssh-agent,但问题没有解决。我发现在本地打开 sshd 会在cap deploy 时显示类似ssh: connect to host $MY_LOCAL_IP port 22: Connection refusedfatal: The remote end hung up unexpectedly 的错误消息。是否有必要打开 sshd?谢谢。
    • 在 capistrano 工作之前,您需要做两件事,1) 使用 deployer 用户 ssh 到远程主机,以及 2) 在连接到的远程主机上运行 ssh 命令通过 ssh 访问 git 存储库。您不需要在本地运行 sshd(服务/守护程序),但它确实需要在远程主机上运行(并且可能是)。
    猜你喜欢
    • 2017-12-27
    • 1970-01-01
    • 2019-03-02
    • 2023-04-09
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多