2016-04-27 86 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配置。

相關問題