我的 deploy.rb 中有以下设置
set :application, 'sample_app'
set :repo_url, 'user@123.45.67.100:/home/user/railsapps/sample_app'
set :deploy_to, '/var/www/sample_app'
set :user, "user"
set :ssh_options, { :forward_agent => true }
和我的部署/生产.rb 文件:
set :stage, :production
server '123.45.67.200', user: 'user', roles: %w{app db web}
运行上限生产部署时出现以下错误:检查
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 user@123.45.67.200: 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.
在其中一行中,我看到它尝试以 user@123.45.67.200 的身份访问存储库,这是生产服务器的部署用户:
INFO [] Running /usr/bin/env git ls-remote --heads user@123.45.67.100:/home/user/railsapps/sample_app as user@123.45.67.200
不应该说它以本地用户的身份与本地 ssh 密钥连接吗?Capistrano 是否登录到生产服务器,然后从存储库中提取代码?如果是,有没有办法让它将代码从存储库推送到生产服务器?
您的 Git URL 似乎无效。您可以通过连接到远程系统(user@123.45.67.200
)来测试这一点,并尝试使用一个简单的git ls-remote --heads
来访问远程Git存储库,这将证明连接性。
git ls-remote --heads user@123.45.67.100:/home/user/railsapps/sample_app
我怀疑您可能需要.git
附加到您的 URL ( user@123.45.67.100:/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按预期工作之前解决这个问题。
您可以查看这篇文章"将ssh-agent与ssh一起使用"以帮助SSH配置。
Capistrano 将登录到服务器,然后从服务器下拉 VCS 中的代码。
通常有两种方法可以对此进行身份验证:
- SSH 代理转发,它将允许远程会话访问您的开发人员密钥,或
- 部署密钥,这将使服务器用户的密钥访问您的代码。
本文档页面的后半部分描述了 Git 与 Capistrano 一起工作的方式: http://capistranorb.com/documentation/getting-started/cold-start/
从您发布的错误中,您可能需要设置上述一个或另一个选项。