2016-04-27 109 views
1

不工作时,我有我的deploy.rb以下设置SSH代理转发与Capistrano的3部署Rails应用程序

set :application, 'sample_app' 
set :repo_url, '[email protected]:/home/user/railsapps/sample_app' 
set :deploy_to, '/var/www/sample_app' 
set :user, "user" 
set :ssh_options, { :forward_agent => true } 

和我的部署/ production.rb文件:

set :stage, :production 
server '123.45.67.200', user: 'user', roles: %w{app db web} 

我得到我运行cap production deploy时出现以下错误:检查

DEBUG [] ssh: connect to host 123.45.67.100 port 22: Connection timed out 
DEBUG [] fatal: Could not read from remote repository. 
Please make sure you have the correct access rights and the repository exists. 
(Backtrace restricted to imported tasks) 
cap aborted! 
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: git exit status: 128 
git stdout: Nothing written 
git stderr: ssh: connect to host 123.45.67.200 port 22: Connection timed out 
fatal: Could not read from remote repository. 
Please make sure you have the correct access rights and the repository exists. 

在其中一行中,我看到它试图访问存储库[email protected],这是生产服务器部署用户:

INFO [] Running /usr/bin/env git ls-remote --heads [email protected]:/home/user/railsapps/sample_app as [email protected] 

难道不应该是说,它的连接与本地SSH密钥的本地用户? Capistrano是否登录到生产服务器,然后从存储库中提取代码?如果是这样,是否有办法让代码从存储库推送到生产服务器?

+0

Capistrano通过拉动更新后的代码工作。它将登录到生产服务器,然后从那里做一个git pull。如果您正在转发密钥,您的本地密钥将可用,但请检查您是否可以将您的部署用户复制到回收站 –

回答

0

Capistrano将登录到服务器,然后从服务器下拉VCS的代码。

通常有验证这两种方式:

  1. 的ssh-agent转发,这将给你的开发者密钥的远程会话访问,或
  2. 部署按键,这将给服务器用户的密钥访问你的代码。

本文档页面的后半部分介绍了Git的工作原理与Capistrano的方式:http://capistranorb.com/documentation/getting-started/cold-start/

从您发布的错误,你可能需要设置一个或另一个上述选项。

0

看来你的Git URL是无效的。您可以通过连接到远程系统([email protected])来测试此功能,并尝试使用简单的git ls-remote --heads来打开远程Git库,这将证明连接性。

git ls-remote --heads [email protected]:/home/user/railsapps/sample_app 

我怀疑你可能需要.git添加到您的网址([email protected]:/home/user/railsapps/sample_app.git),但实际上取决于你如何有您的远程回购成立。

Git使用SSH连接,但它没有明确显示在Capistrano输出。您将看到的只是明确的git命令。

或者,如果您希望使用代理转发,那么您的ssh转发配置可能会遇到问题,无论是本地还是远程。您可以通过检查本地计算机然后连接到远程计算机并查看您的身份是否被转发来测试。你会是这样做的:

local-host$ ssh-add -l 
local-host$ ssh [email protected] 
remote-host$ ssh-add -l 

如果你看到输出如下:

Error connecting to agent: No such file or directory 

或:

Could not open a connection to your authentication agent. 

或:

The agent has no identities. 

然后,你需要理清在Capistrano将按预期工作之前解决这个问题。

你可以写下“Using ssh-agent with ssh”来帮助SSH配置。

相关问题