【问题标题】:GemNotFound during bundle install on EC2 nano instances, but works on micro instances在 EC2 nano 实例上捆绑安装期间的 GemNotFound,但适用于微型实例
【发布时间】:2020-10-02 19:00:59
【问题描述】:

我有一个使用 Ruby 2.6.5 (rbenv) 和 Rails 5.2 的 Ruby on Rails 应用程序

我创建了安装脚本来配置 EC2 实例并将应用程序部署到该实例。

它与t3a.micro 实例一致,但如果我使用配置为使用t3a.nano 的相同部署脚本(在t3.nano 上也失败)实例,则始终失败。错误是:

/home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/spec_set.rb:91:in `block in materialize': Could not find nokogiri-1.10.9 in any of the sources (Bundler::GemNotFound)
    from /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `map!'
    from /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `materialize'
    ...

我可以手动安装 gem:

$ which gem
/home/ubuntu/.rbenv/shims/gem
$ gem install nokogiri
Fetching mini_portile2-2.4.0.gem
Fetching nokogiri-1.10.9.gem
Successfully installed mini_portile2-2.4.0
Building native extensions. This could take a while...
Successfully installed nokogiri-1.10.9
Parsing documentation for mini_portile2-2.4.0
Installing ri documentation for mini_portile2-2.4.0
Parsing documentation for nokogiri-1.10.9
Installing ri documentation for nokogiri-1.10.9
Done installing documentation for mini_portile2, nokogiri after 2 seconds
2 gems installed
$

但如果我 bundle install 应用程序失败:

...
Running 'compile' for libxml2 2.9.10...
To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/nokogiri-1.10.8/mkmf.log

extconf failed, uncaught signal 9

Gem files will remain installed in /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.8 for
inspection.
Results logged to
/home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/nokogiri-1.10.8/gem_make.out

An error occurred while installing nokogiri (1.10.8), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.10.8' --source 'https://rubygems.org/'` succeeds before bundling.

知道发生了什么或如何解决它吗?为什么bundle installgem install 的不同之处在于关心我是在micro 还是nano ec2 实例上?

如果您想自己测试,该项目位于 github:https://github.com/mawise/simpleblog 您必须更改 deploymentscripts/deploy-aws.rb 以引用不同的实例类型。

(我知道一些日志引用1.10.8 和其他1.10.9,我看到另一个帖子暗示1.10.9 有问题,所以我尝试了较低版本,结果相同。)

【问题讨论】:

    标签: ruby-on-rails ruby amazon-ec2 rubygems bundler


    【解决方案1】:

    我遇到过这个问题。很可能您的 EC2 实例在编译 gem 时内存不足,并且无法安装所有 gem。 t3a.nano 实例有 0.5 GB 内存,而 t3a.micro 有 1.0 GB。

    我通过简单地创建一个交换文件在我的应用程序中解决了这个问题。这是一个有弹性的 beanstalk 应用程序,但您可以将其调整为您的应用程序。

    https://github.com/stefansundin/rssbox/blob/1e40fe60f888ad0143e5c4fb83c1471986032963/.ebextensions/01-swap.config

    # run as root:
    dd if=/dev/zero of=/var/swapfile bs=1M count=512
    chmod 600 /var/swapfile
    mkswap /var/swapfile
    swapon /var/swapfile
    echo "/var/swapfile none swap sw 0 0" >> /etc/fstab
    

    【讨论】:

    • 请注意,您不能只使用sudo echo "stuff" >> /etc/fstab,以便以 root 身份执行此操作。如果编写脚本并需要使用 sudo,请尝试以下操作:echo "/var/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2015-02-25
    • 2014-05-28
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    相关资源
    最近更新 更多