【发布时间】:2020-11-28 05:54:38
【问题描述】:
这是我第一次尝试使用 Capistrano 部署 Rails 应用程序。我正在按照https://ogdenstudios.xyz/blog/how-do-i-deploy-a-rails-6-app-to-amazon-ec-2/ 的教程部署到 AWS EC2 实例。我的应用程序在 Rails 6 上,并且在 localhost 上运行顺畅。我按照教程进行了操作,但在最后一步中,当我运行 cap production deploy 时出现以下错误:
00:00 rbenv:validate
rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
00:00 git:wrapper
01 mkdir -p /tmp
#<Thread:0x00007fd74423aa28 /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
12: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
11: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
10: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
9: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/scm/tasks/git.rake:8:in `block (3 levels) in eval_rakefile'
8: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:80:in `execute'
7: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
6: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `tap'
5: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
4: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:130:in `execute_command'
3: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh'
2: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `with'
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `call'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start': Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (Net::SSH::AuthenticationFailed)
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (SSHKit::Runner::ExecuteError)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
Tasks: TOP => deploy:check => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
INFO [7f1cf201] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [7f1cf201] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:31:07 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [0bfcc93b] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [0bfcc93b] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:50:22 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [cb1eb774] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [cb1eb774] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 14:09:05 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [86bd8328] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [86bd8328] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
我正在添加我的 deploy.rb 文件
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
set :application, "lantiamaster"
set :repo_url, "git@github.com:Robs-v82/lantiamaster.git"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/ubuntu/lantiamaster"
set :use_sudo, true
set :branch, 'master'
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# Default value for :pty is false
set :pty, true
set :ssh_options, {
forward_agent: true,
user: fetch(:user),
# auth_methods: %w[publickey],
keys: %w[~/server-keys/lantiamaster-key-pair.pem]
}
# Default value for :linked_files is []
# append :linked_files, "config/database.yml"
set :linked_files, %w{config/master.key}
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases, 5
# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
我是部署新手,我不知道问题可能是什么。我创建了 SSH 密钥,并将其保存在我的 ubuntu 虚拟机和我的 Github 帐户中。
【问题讨论】:
-
您是否使用此信息
ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com:手动尝试 ssh 并成功? -
我不确定我是否理解。如果您要启动我的 EC2 实例,输入这些凭据(而不是本教程第 6 步中描述的“轻松访问”),我只是尝试过。我仍然遇到同样的错误。
-
如果您拥有aws帐户,请打开ec2选项卡,选择正确的ec2并单击连接,它会这样你。
标签: ruby-on-rails ubuntu amazon-ec2 capistrano ssh-keys