我有一个使用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 install
与gem install
会在某种程度上关心我是在micro
还是nano
ec2实例上?
如果您要测试自己,则该项目位于github上:https://github.com/mawise/simpleblog您必须更改deploymentscripts/deploy-aws.rb
才能引用其他实例类型。
((我知道有些日志引用了1.10.8
,而另一些日志引用了1.10.9
,我看到了另一篇文章建议1.10.9
损坏了,所以我尝试了具有相同结果的较低版本。]
我遇到了这个问题。编译gem时,很可能您的EC2实例的内存不足,并且它无法安装所有gem。一个t3a.nano实例具有0.5 GB的内存,而一个t3a.micro实例具有1.0 GB的内存。
我通过简单地创建交换文件在应用程序中解决了该问题。这是一个有弹性的beantalk应用程序,但是您可能可以使其适应您的应用程序。
# 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