我在deploy.rb中进行了以下设置
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 }
和我的deploy / production.rb文件:
set :stage, :production
server '123.45.67.200', user: 'user', roles: %w{app db web}
运行cap production deploy时出现以下错误:check
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是否登录到生产服务器,然后从存储库中提取代码?如果是,是否有办法将代码从存储库推送到生产服务器?
您的Git网址似乎无效。您可以通过连接到远程系统([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 user@remote-host
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配置。
Capistrano将登录到服务器,然后从服务器下载VCS中的代码。
通常有两种方法来验证:
本文档页面的后半部分描述了Git与Capistrano合作的方式:http://capistranorb.com/documentation/getting-started/cold-start/
根据您发布的错误,您可能需要设置上述选项中的一个或另一个。