部署到Elastic Beanstalk失败,出现“无法分配内存”错误

我构建了一个我想要部署到弹性beanstalk的rails应用程序。 我能够将其部署到我的AWS账户,但现在我想将其部署到我的客户账户。 出于某种原因,我在尝试部署它时遇到错误。 能够从头开始将它部署到我的帐户并能够将其部署到heroku,但每次我尝试将其部署到我的客户帐户时,我都会遇到一堆错误。 这两个帐户之间是否存在可能的设置? 我不明白为什么部署到这两个帐户会有所不同。 我尝试了所有可以找到的解决方案。

这是日志。 我不确定他们是否会有所帮助

gem 'bootstrap-sass' gem 'autoprefixer-rails' gem 'puma' group :development, :test do gem "letter_opener" gem 'byebug' end group :development do gem 'web-console', '~> 2.0' gem 'spring' end group :production do # gem 'pg' gem 'rails_12factor' end + '[' -d /var/app/ondeck/vendor/cache ']' + bundle install Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine. Warning: the running version of Bundler is older than the version that created the lockfile. We sugg est you upgrade to the latest version of Bundler by running `gem install bundler`. Fetching gem metadata from https://rubygems.org/ Fetching version metadata from https://rubygems.org/ Fetching dependency metadata from https://rubygems.org/ Using rake 11.1.2 Using i18n 0.7.0 Installing json 1.8.3 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-1pc5aw8.rb extconf.rb Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-1pc5aw8.rb extcon f.rb 2>&1 Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/json-1.8.3 for in spection. Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/js on-1.8.3/gem_make.out Using minitest 5.9.0 Using thread_safe 0.3.5 Using builder 3.2.2 Using erubis 2.7.0 Using mini_portile2 2.1.0 Using pkg-config 1.1.7 Using rack 1.6.4 Using mime-types-data 3.2016.0521 Using arel 6.0.3 Using execjs 2.7.0 Installing bcrypt 3.1.10 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-myt7e8.rb extconf.rb Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-myt7e8.rb extconf.rb 2>&1 Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/bcrypt-3.1.10 for inspection. Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/bcrypt-3.1.10/gem_make.out Using sass 3.4.22 Using coffee-script-source 1.10.0 Using thor 0.19.1 Using concurrent-ruby 1.0.2 Using multi_json 1.12.1 Using libv8 3.16.14.15 Installing puma 3.4.0 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-kv1g4s.rb extconf.rb Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-kv1g4s.rb extconf.rb 2>&1 Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/puma-3.4.0 for inspection. Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/puma-3.4.0/gem_make.out Using bundler 1.12.1 Using rails_serve_static_assets 0.0.5 Using rails_stdout_logging 0.0.4 Using ref 2.0.0 Using tilt 2.0.5 Installing sqlite3 1.3.11 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-5lnc3v.rb extconf.rb Cannot allocate memory - /opt/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20160708-498-5lnc3v.rb extconf.rb 2>&1 Gem files will remain installed in /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11 for inspection. Results logged to /opt/rubies/ruby-2.2.5/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/sqlite3-1.3.11/gem_make.out An error occurred while installing json (1.8.3), and Bundler cannot continue. Make sure that `gem install json -v '1.8.3'` succeeds before bundling. (Executor::NonZeroExitStatus) [2016-07-08T19:47:55.300Z] INFO [424] - [Application update app-d3f5-160708_124551@2/AppDeployStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed. [2016-07-08T19:47:55.301Z] INFO [424] - [Application update app-d3f5-160708_124551@2/AppDeployStage0/AppDeployPreHook] : Activity failed. [2016-07-08T19:47:55.301Z] INFO [424] - [Application update app-d3f5-160708_124551@2/AppDeployStage0] : Activity failed. [2016-07-08T19:47:55.302Z] INFO [424] - [Application update app-d3f5-160708_124551@2] : Completed activity. Result: Application update - Command CMD-AppDeploy failed [2016-07-08T20:17:06.267Z] INFO [1271] - [CMD-TailLogs] : Starting activity... [2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/AddonsBefore] : Starting activity... [2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/AddonsBefore] : Completed activity. [2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/TailLogs] : Starting activity... [2016-07-08T20:17:06.268Z] INFO [1271] - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity... 

我发现@osazemeu基于博客文章的答案需要调整,因为container_commands执行太晚(在应用程序已经设置之后),因此它从未运行过。

我将container_command更改为命令(请参阅此AWS文档以获取有关两者之间差异的详细信息),并且还创建了内联文件而不是单独的.sh文件,因为我不想跟踪哪个目录是在部署时被放入。 我调用了文件01setup_swap.config并将其放在项目根目录中的.ebextensions目录中。 这对我有用。 内容如下:

 files: "/home/ec2-user/setup_swap.sh": mode: "000755" owner: root group: root content: | #!/bin/bash # based on http://steinn.org/post/elasticbeanstalk-swap/ SWAPFILE=/var/swapfile SWAP_MEGABYTES=2048 if [ -f $SWAPFILE ]; then echo "Swapfile $SWAPFILE found, assuming already setup" exit; fi /bin/dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAP_MEGABYTES /bin/chmod 600 $SWAPFILE /sbin/mkswap $SWAPFILE /sbin/swapon $SWAPFILE commands: 01setup_swap: command: "bash setup_swap.sh" cwd: "/home/ec2-user/" 

几天前我遇到过类似的问题,这就是我解决它的方法。 如果当前步骤失败,则仅进入下一步。

步骤1:增加ElasticBean EC2实例的交换内存

 yourapp/.ebextensions/setup_swap.sh #!/bin/bash SWAPFILE=/var/swapfile SWAP_MEGABYTES=2048 if [ -f $SWAPFILE ]; then echo "Swapfile $SWAPFILE found, assuming already setup" exit; /bin/dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAP_MEGABYTES /bin/chmod 600 $SWAPFILE /sbin/mkswap $SWAPFILE /sbin/swapon $SWAPFILE 

步骤1.1在yourapp / .ebextensions / 01_setup_swap.config中

 container_commands: 01setup_swap: command: "bash .ebextensions/swap/setup_swap.sh" 

来源: elasticbeanstalk-swap

第2步:增加ElasticBeanstalk实例的大小,并尝试再次部署。

第3步:如果所有其他方法都失败了,请在rails应用中运行此命令。

 bundle exec bundle package 

这将编译gems并将其保存到rails应用程序中的本地文件夹(供应商/缓存)。 在部署期间访问此文件夹,并且不会进行编译。

将这些文件提交到您的repo,并尝试部署。 它应该没有障碍。

刚刚遇到这个错误。 这是我学到的以及如何通过这个问题:

使用AWS弹性beanstalk的免费层,默认情况下,截至本答复日期,您获得的EC2实例类型为t1.micro。 t1.micro的内存非常少。 这个gem的gem安装过程很少失败,因为post很明显。 t1.micro现在被认为是上一代实例类型( https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html )。 要通过此内存分配失败,您必须将AWS弹性beanstalk应用程序的EC2实例从t1.micro更新为t2.micro。 这对我有用。