【问题标题】:Not able to deploy with capistrano to aws from bitbucket无法使用 capistrano 从 bitbucket 部署到 aws
【发布时间】:2016-04-21 11:30:48
【问题描述】:

我尝试使用本地计算机上的 Capistrano 将 Ruby on Rails 应用程序从 bitbucket 上的存储库自动部署到 AWS EC2 实例。我尝试了 ssh、密码、无密码、转发 ssh 密钥、使用唯一的 ssh 密钥而不转发。每次我面对这个 ssh 跟踪 set :ssh_options, { verbose: :debug } :debug

D, [2016-01-15T21:08:45.830590 #8129] DEBUG -- socket[2aefc98b29bc]: queueing packet nr 52 type 97 len 28 I, [2016-01-15T21:08:45.830677 #8129] INFO -- net.ssh.connection.session[2aefc9c83b04]: ec2-23-289-88-231.eu-west-1.compute.amazonaws.com delete channel 2 which closed locally and remotely INFO [b3dd32b6] Finished in 0.255 seconds with exit status 0 (successful). cap aborted! Errno::ENETUNREACH: Network is unreachable - connect(2) /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/2.0.0/socket.rb:65:inconnect' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/2.0.0/socket.rb:65:in connect_internal' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/2.0.0/socket.rb:140:inconnect' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/2.0.0/socket.rb:343:in block in tcp' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/2.0.0/socket.rb:232:ineach' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/2.0.0/socket.rb:232:in foreach' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/2.0.0/socket.rb:333:intcp' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/net-ssh-3.0.2/lib/net/ssh/transport/session.rb:70:在initialize' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/net-ssh-3.0.2/lib/net/ssh.rb:225:innew' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/net-ssh-3.0.2/lib/net/ssh.rb:225:in start' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/connection_pool.rb:95:in称呼' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/connection_pool.rb:95:in create_new_entry' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/connection_pool.rb:38:in退房' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/netssh.rb:134:in with_ssh' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/netssh.rb:87:in执行命令' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:121:in block in create_command_and_execute' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:121:in轻敲' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:121:in create_command_and_execute' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:53:in执行' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in block (3 levels) in <top (required)>' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:15:in实例执行' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:15:in run' /home/al/.rbenv/versions/2.0.0-p647/lib/ruby/gems/2.0.0/gems/sshkit-1.8.1/lib/sshkit/runners/parallel.rb:13:in块(2级)在执行' 任务:TOP => git:check => git:wrapper 部署失败并出现错误:# ** 调用部署:失败(first_time) ** 执行部署:失败 al@al-machine:/media/al/E02EF2032EF1D290/projects/project$ 上限中止! ` ```

请建议尝试什么

这是 deploy.rb

`
lock '3.2.1'
set :application, 'myapp'
set :repo_url, 'git@bitbucket.org:user/application.git'
set :branch, 'staging'
set :ssh_options, {
  verbose: :debug
}
 set :deploy_to, 'myfolder'
 set :scm, :git
 set :pty, true
 set :keep_releases, 5
set :use_sudo, true
set :rails_env, 'develop'
set :deploy_via, :copy
set :stages, ["staging", "production"]
set :default_stage, 'staging'
namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end
  #after :publishing, :restart
  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end
after :finishing, 'deploy:cleanup'
end
`

这是 staging.rb

`
role :app, %w{deploy@example.com}
role :web, %w{deploy@example.com}
role :db,  %w{deploy@example.com}
set :deploy_to, "/myfolder"
 server 'ec2-my-ip.eu-west-1.compute.amazonaws.com',
   user: 'ec2-user',
   port: '22',
   roles: %w{web app db},
   :primary => true,
   ssh_options: {
    user: 'ec2-user', # overrides user setting above
     keys: %w(/home/local_machine_user/.ssh/aws_ssh_key_pair.pem),
     forward_agent: false,
     auth_methods: %w(publickey password),
     password: 'please use keys'
   }
`

【问题讨论】:

    标签: ruby-on-rails ruby amazon-web-services ssh amazon-ec2


    【解决方案1】:

    我遇到了类似的问题。对我来说,我错过了更改 example.com 地址。所以你的 staging.rb 应该是这样的:

    role :app, %w{deploy@ec2-my-ip.eu-west-1.compute.amazonaws.com} role :web, %w{deploy@ec2-my-ip.eu-west-1.compute.amazonaws.com} role :db, %w{deploy@ec2-my-ip.eu-west-1.compute.amazonaws.com} set :deploy_to, "/myfolder" server 'ec2-my-ip.eu-west-1.compute.amazonaws.com', user: 'ec2-user', port: '22', roles: %w{web app db}, :primary => true, ssh_options: { user: 'ec2-user', # overrides user setting above keys: %w(/home/local_machine_user/.ssh/aws_ssh_key_pair.pem), forward_agent: false, auth_methods: %w(publickey password), password: 'please use keys' }

    【讨论】:

      【解决方案2】:

      这是网络问题:

      Errno::ENETUNREACH: Network is unreachable - connect(2)
      

      检查您的安全组并确保您允许实例连接到端口 22 上的外部源。(您也可以使用“ssh -Tv git@bitbucket.org”从该实例测试它。)

      【讨论】:

      • 我可以在 ssh 连接下手动并使用两个密钥(aws 或本地计算机)将存储库从 bitbucket 克隆到 EC2。它克隆得很好。我试图交换密钥,一切正常,但不能通过 Capistrano。安全组目前完全开放。
      猜你喜欢
      • 1970-01-01
      • 2016-03-08
      • 2021-09-03
      • 2014-11-12
      • 2016-11-20
      • 1970-01-01
      • 2014-01-08
      • 2014-01-24
      • 1970-01-01
      相关资源
      最近更新 更多