-1

我遵循部署到aws ec2 https://www.sitepoint.com/deploy-your-rails-app-to-aws/的指南。在aws上部署我的rails应用程序与capisrano时出错

我使用的是Ubuntu 16服务器。

一切都已完美安装在服务器上,但是当我运行cap production deploy --trace这是输出。

** Invoke production (first_time) 
** Execute production 
** Invoke load:defaults (first_time) 
** Execute load:defaults 
** Invoke rvm:hook (first_time) 
** Execute rvm:hook 
** Invoke rvm:check (first_time) 
** Execute rvm:check 
cap aborted! 
Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout 
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:90:in `rescue in initialize' 
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:57:in `initialize' 
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `new' 
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `start' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `call' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `with' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:155:in `with_ssh' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:108:in `execute_command' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `tap' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:60:in `capture' 
/var/lib/gems/2.1.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:9:in `block (3 levels) in <top (required)>' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `instance_exec' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `run' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' 
Errno::ETIMEDOUT: Connection timed out - connect(2) for 172.31.11.127:22 
/usr/lib/ruby/2.1.0/socket.rb:65:in `connect' 
/usr/lib/ruby/2.1.0/socket.rb:65:in `connect_internal' 
/usr/lib/ruby/2.1.0/socket.rb:140:in `connect' 
/usr/lib/ruby/2.1.0/socket.rb:338:in `block in tcp' 
/usr/lib/ruby/2.1.0/socket.rb:232:in `each' 
/usr/lib/ruby/2.1.0/socket.rb:232:in `foreach' 
/usr/lib/ruby/2.1.0/socket.rb:328:in `tcp' 
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:70:in `initialize' 
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `new' 
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `start' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `call' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `with' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:155:in `with_ssh' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:108:in `execute_command' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `tap' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:60:in `capture' 
/var/lib/gems/2.1.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:9:in `block (3 levels) in <top (required)>' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `instance_exec' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `run' 
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' 
Tasks: TOP => rvm:check 

我Capistrano的production.rb文件:

server '172.31.11.127', user: 'deploy', roles: %w{web app db} 

我Capistrano的deploy.rb文件:

set :branch, :master 
set :deploy_to, '/home/deploy/rd' 
set :pty, true 

set :linked_files, %w{config/database.yml config/application.yml} 

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads} 


set :keep_releases, 5 
set :rvm_type, :user 
set :rvm_ruby_version, 'ruby 2.1.5' 

set :puma_rackup, -> { File.join(current_path, 'config.ru') } 
set :puma_state, "#{shared_path}/tmp/pids/puma.state" 
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid" 
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" #accept array for multi-bind 
set :puma_conf, "#{shared_path}/puma.rb" 
set :puma_access_log, "#{shared_path}/log/puma_error.log" 
set :puma_error_log, "#{shared_path}/log/puma_access.log" 
set :puma_role, :app 
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production')) 
set :puma_threads, [0, 8] 
set :puma_workers, 0 
set :puma_worker_timeout, nil 
set :puma_init_active_record, true 
set :puma_preload_app, false 
+0

尝试检查命令行ssh [email protected],并且当您将公钥添加到服务器authorized_keys文件中时,需要重新启动ssh服务 – Pratap

+0

我重新启动服务并仍然出现错误。 IP 52.2.139.74属于谁或是什么? –

+0

sry错误的IP 52.2.139.74 – Pratap

回答

0

连接超时意味着一些防火墙规则阻止端口22上的SSH连接到它正在部署代码的机器。下面的消息 -

/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:inblock(2级)在执行” errno的:: ETIMEDOUT:连接超时 - 连接(2)172.31.11.127:22 /usr/lib/ruby/2.1.0/socket.rb:65:in连接”

清楚地表明,连接超时的客户机上的超时时间到期后。 正如我看到您在aws实例中使用capistrano,请检查capistrano机器尝试连接的客户端机器的安全组。对于capistrano机器的ip/subnet,端口22应该是开放的。

+0

你如何建议我这样做?我允许ip连接到防火墙中的端口22并得到相同的错误 –

+0

您的部署用户是否存在于您部署代码的服务器机器上? –

+0

是的。我已经多次检查过。 –

相关问题