【问题标题】:Rails deployment to staging using capistrano generates the following error使用 capistrano 部署到 staging 的 Rails 会生成以下错误
【发布时间】:2015-10-20 18:43:52
【问题描述】:

当我尝试从本地机器 (MAC) {Rails app} 使用 capistrano gem 部署到服务器时,我得到以下信息。我是 Rails 新手

user-mbp:xp user$ cap staging deploy
Server password:
********
DEBUG [c6110f69] Running /usr/bin/env [ -d ~/.rbenv ] as deployer@server.com
DEBUG [c6110f69] Command: [ -d ~/.rbenv ]
DEBUG [c6110f69] Finished in 6.956 seconds with exit status 0 (successful).
INFO [e385c416] Running /usr/bin/env mkdir -p /tmp/pepe/ as deployer@server.com
DEBUG [e385c416] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env mkdir -p /tmp/pepe/ )
INFO [e385c416] Finished in 0.098 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/pepe/git-ssh.sh 0.0%
INFO Uploading /tmp/pepe/git-ssh.sh 100.0%
INFO [191046c4] Running /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh as deployer@server.com
DEBUG [191046c4] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh )`enter code here`
INFO [191046c4] Finished in 0.119 seconds with exit status 0 (successful).
INFO [bd99c2fc] Running /usr/bin/env git ls-remote --heads ssh://git@git.xxx.xx.com/xp.git as deployer@server.com
DEBUG [bd99c2fc] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/pepe/git-ssh.sh /usr/bin/env git ls-remote --heads ssh://git@git.xxx.xx.com/xp.git )
DEBUG [bd99c2fc]    Permission denied (publickey,password).
DEBUG [bd99c2fc]    fatal: The remote end hung up unexpectedly
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@server.com: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly

SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly

我尝试了git:check,但仍然显示相同。

Tasks: TOP => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer@server.com: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly

暂存.rb

# *************************************************************** #
require 'highline'

set :stage, :staging

set :password, HighLine.new.ask('Server password:') { |q| q.echo = '*'}
server 'xx.x.com', user: 'deployer', password: fetch(:password), roles: %w{web app db}, primary: true
set :test_url, 'https://xx.x.com'
set :version, `git describe --always`

# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
#  set :ssh_options, {
#    keys: %w(/home/rlisowski/.ssh/id_rsa),
#    forward_agent: false,
#    auth_methods: %w(password)
#  }
# and/or per server
# server 'example.com',
#   user: 'user_name',
#   roles: %w{web app},
#   ssh_options: {
#     user: 'user_name', # overrides user setting above
#     keys: %w(/home/user_name/.ssh/id_rsa),
#     forward_agent: false,
#     auth_methods: %w(publickey password)
#     # password: 'please use keys'
#   }
# setting per server overrides global ssh_options

# fetch(:default_env).merge!(rails_env: :staging)

【问题讨论】:

  • 我假设您从开发机器进行部署。并且从您的开发机器中,您还可以推送到 git。这意味着你的开发机器上有你的 git 凭证。当您将 set :ssh_options, :forward_agent => true 添加到您的 config/deploy/staging.rb 时,您可以转发这些内容。如果这没有帮助,最好发布 staging.rb 文件。
  • 嗨 @sugaryourcoffee 发布了 staging.rb 文件
  • 您是否检查了存储库中的公钥是否与部署机器上的私钥匹配?该错误表明情况并非如此。如果您在 Github 上,那么您可以从部署机器检查您是否可以使用 ssh -vT git@github.com 访问您的存储库。
  • @sugaryourcoffee 我已经登录到服务器并找到了只有 Known_hosts 的 .ssh 目录。而我的本地计算机有 github_rsa.pub 和 id_rsa.pub 和 known_hosts。这是错误的原因吗??
  • @sugaryourcoffee 这是我尝试 ssh -vT git@github.com 时得到的结果: /etc/ssh_config line 20: Applying options for * ssh: could not resolve hostname git.xx.x.com/xp.git: nodename or servname provided, or not known

标签: ruby-on-rails ruby git capistrano3 rvm-capistrano


【解决方案1】:

有两种可能的解决方案

  1. 将您的私钥复制到您的部署机器 正如您可以推送到 Github(这是我的理解),您在开发机器上有一个私钥,在 Github 上有相应的公钥。您可以将您的私钥复制到您的部署机器上以消除错误

    develeopment-machine$ scp ~/.ssh/id-rsa.pub deployment-machine:key

然后 ssh 到您的部署机器并执行

deployment-machine$ mv ~/.ssh/id-rsa.pub ~/.ssh/id-rsa.old
deployment-machine$ mv ~/key ~/.ssh/id-rsa.pub
  1. 在您的部署机器上创建一个密钥并将公钥添加到 Github 在Github Help 有一个易于理解的解释如何做到这一点

希望这会有所帮助。

使用 Capistrano 的项目链接

如果您使用的是 Rails 3:

如果您使用的是 Rails 4:

【讨论】:

  • 我认为错误的原因是我的本地机器指向我提交和推送的特定 git,而服务器(生产和登台)指向另一个 git repo。我检查了它使用 git remote -v 命令。我应该怎么做才能解决它?
  • 将暂存配置文件中的存储库设置为您将代码推送到喜欢的存储库set :repository, "git@github.com:git_user/git_application.git"
  • 仍然有同样的问题。我遇到了这个问题。有没有办法解决这个问题并从我的本地机器部署到登台服务器
  • 我已经按照您在 staging.rb 文件中所说的进行了更改,但还是一样
  • 实际上,对于您的特定问题,我没有想法。我能提供的是我的一个项目的一个工作示例。我会把链接放在我的答案上。
猜你喜欢
  • 2019-04-27
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
  • 1970-01-01
  • 2016-01-02
  • 1970-01-01
  • 1970-01-01
  • 2013-01-24
相关资源
最近更新 更多