1

我正在使用 rails 4.0.2 和 ruby​​ 2.0.0p247 和 capistrano 3.1.0 将 rails 应用程序部署到 VPS 服务器。

deploy.rb 文件是这样的

set :application, "rails4test"
set :repository,  "git@github.com:projectname.git"
set :keep_releases, 2
set :scm, :git

set :stages, %w(production staging)
set :default_stage, "staging"

set :deploy_to, "/var/www/website.com/public_html"
set :user, "username"
set :use_sudo, false
set :copy_exclude, ['.git']

task :deploy_production do
  set :branch, "master"
  set :rails_env, 'production'
  set :host, "serverip"

  role :web, "#{host}"                          
  role :app, "#{host}"                           
  role :db,  "#{host}", :primary => true 
  set :stage, "production"
  system("bundle exec cap production deploy")
end


set :ssh_options, {
 verbose: :debug,
 user: fetch(:user)
}

production.rb 文件是这样的

set :branch, "master"
set :rails_env, 'production'                   
set :host, "server ip"
role :web, "server ip"
role :app, "server ip"
role :db, "server ip", :primary => true

server "server ip", roles: %w{web app db}, ssh_options: {
  user: "username",
  forward_agent: true,
 }

当我运行命令 cap production deploy 时。我面临以下错误。

INFO [eccddf96] Running /usr/bin/env mkdir -p /tmp/rails4test/ on someip
DEBUG [eccddf96] Command: /usr/bin/env mkdir -p /tmp/rails4test/
cap aborted!
Authentication failed for user username@23.227.162.62
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh.rb:217:in `start'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends      /connection_pool.rb:25:in `create_or_reuse_connection'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends   /netssh.rb:173:in `ssh'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends /netssh.rb:126:in `block in _execute'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `tap'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `_execute'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.1.0/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
(See full trace by running task with --trace)
  The deploy has failed with an error: #<Net::SSH::AuthenticationFailed: Authentication failed for user username@someip>

宝石文件

gem "sshkit", "~> 1.3.0"
gem "net-scp", ">=1.1.2"
gem "net-ssh", "~> 2.8.0"
gem "term-ansicolor", ">=0"

放置这些gem后,出现以下错误:我刚刚安装了gem。

 INFO [4f498013] Running /usr/bin/env mkdir -p /tmp/rails4test/ on some ip
 cap aborted!
 Connection refused - connect(2)
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-   2.8.0/lib/net/ssh/transport/session.rb:70:in `initialize'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:70:in `open'
/home/rails/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh- 2.8.0/lib/net/ssh/transport/session.rb:70:in `block in initialize'
(See full trace by running task with --trace)
The deploy has failed with an error: #<Errno::ECONNREFUSED: Connection refused - connect(2)>
4

0 回答 0