在 Elastic Beanstalk 上安装 Nokogiri 失败

Posted

技术标签:

【中文标题】在 Elastic Beanstalk 上安装 Nokogiri 失败【英文标题】:Nokogiri installation failes on Elastic Beanstalk 【发布时间】:2014-11-15 18:48:34 【问题描述】:

我正在尝试使用 AWS Elastic Beanstalk 部署我的 Rails 应用程序。我已经创建了实例,但当我尝试使用 aws.push 部署应用程序时,我在事件日志中收到以下错误:

2014-09-22 01:23:40 UTC+0550    ERROR   [Instance: i-744edb4a Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command hooks failed .
2014-09-22 01:23:39 UTC+0550    ERROR   Script /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed with returncode 5

拉取日志发现nokogiri gem 安装失败,报错:

-------------------------------------
/var/log/directory-hooks-executor.log
-------------------------------------
Using mail 2.5.4
Using actionmailer 4.0.2
Using active_utils 2.2.1
Using json 1.8.1
Using money 6.1.1
Using mini_portile 0.6.0

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.9 extconf.rb 
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... yes
Building libxml2-2.8.0 for nokogiri with the following patches applied:
    - 0001-Fix-parser-local-buffers-size-problems.patch
    - 0002-Fix-entities-local-buffers-size-problems.patch
    - 0003-Fix-an-error-in-previous-commit.patch
    - 0004-Fix-potential-out-of-bound-access.patch
    - 0005-Detect-excessive-entities-expansion-upon-replacement.patch
    - 0006-Do-not-fetch-external-parsed-entities.patch
    - 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
    - 0008-Improve-handling-of-xmlStopParser.patch
    - 0009-Fix-a-couple-of-return-without-value.patch
    - 0010-Keep-non-significant-blanks-node-in-html-parser.patch
    - 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

However, note that nokogiri does not necessarily support all versions
of libxml2.

For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-redhat-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /usr/local/share/gems1.9/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-redhat-linux-gnu/ports/libxml2/2.8.0/patch.log' to see what happened.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=$opt-dir/include
    --with-opt-lib
    --without-opt-lib=$opt-dir/
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/ruby1.9
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=$zlib-dir/include
    --with-zlib-lib
    --without-zlib-lib=$zlib-dir/lib
    --enable-cross-build
    --disable-cross-build
/usr/local/share/gems1.9/gems/mini_portile-0.6.0/lib/mini_portile.rb:279:in `block in execute': Failed to complete patch task (RuntimeError)
    from /usr/local/share/gems1.9/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `chdir'
    from /usr/local/share/gems1.9/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `execute'
    from extconf.rb:282:in `block in patch'
    from extconf.rb:279:in `each'
    from extconf.rb:279:in `patch'
    from /usr/local/share/gems1.9/gems/mini_portile-0.6.0/lib/mini_portile.rb:108:in `cook'
    from extconf.rb:253:in `block in process_recipe'
    from extconf.rb:154:in `tap'
    from extconf.rb:154:in `process_recipe'
    from extconf.rb:419:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /usr/local/share/gems1.9/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /usr/local/lib64/gems1.9/exts/nokogiri-1.6.2.1/gem_make.out
An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.

2014-09-21 19:53:39,643 [ERROR] (321 MainThread) [directoryHooksExecutor.py-33] [root directoryHooksExecutor error] Script /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed with returncode 5

我已将以下内容添加到文件.ebextensions/packages.conf

packages:
  yum:
    postgresql-devel: []
    git: []
    gcc: []
    libxml2: []
    libxml2-devel: []
    libxslt: []
    libxslt-devel: []

安装 nokogiri 是否需要执行其他操作?我错过了什么吗?

谢谢!

【问题讨论】:

【参考方案1】:

Nokogiri 需要 libxml2 和 libxslt。确保在运行 gem install nokogiri 或 bundle install 之前都已安装。

即ubuntu 服务器会使用 apt-get 或 aptitude 安装这些文件

【讨论】:

如果您正确阅读了我的问题并且知道我在问什么,您就会知道我已指示 eb 为我安装这些。还是谢谢/。 我确实阅读了您的问题,但我对 yml 并不熟悉,而且很明显,这些库并没有按照您想要的方式安装。【参考方案2】:

我能够通过将patch 包含在要安装的软件包列表中来解决此问题:)

像这样:

packages:
  yum:
    postgresql-devel: []
    git: []
    patch: []

【讨论】:

【参考方案3】:

nokogiri 有时无法编译的另一个原因是它在低内存机器上耗尽了内存。

【讨论】:

不要尝试在小于 t2.small 的任何东西上运行 ruby​​。

以上是关于在 Elastic Beanstalk 上安装 Nokogiri 失败的主要内容,如果未能解决你的问题,请参考以下文章

在 Amazon Elastic Beanstalk 上安装 Anaconda

如何在 Elastic Beanstalk 上安装 matplotlib

在 Elastic Beanstalk 上安装 Nokogiri 失败

在 Elastic Beanstalk 上使用 Yarn 安装包

在 AWS Elastic Beanstalk 上全局安装 npm 包

在 AWS Elastic Beanstalk 上安装 Composer.json