#概要
ログを取ろうと、Amazon Linux2でFluentdは入ったものの、fluent-plugin-cloudwatch-logsでインストールに詰まった。原因としてはrubyの開発環境がなかっただけだった話。
#症状
こんなエラーが生じてうまく入らない。
$ sudo /opt/td-agent/embedded/bin/gem install fluent-plugin-cloudwatch-logs --no-ri --no-rdoc
Building native extensions. This could take a while...
ERROR: Error installing fluent-plugin-cloudwatch-logs:
ERROR: Failed to build gem native extension.
current directory: /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/msgpack-1.3.3/ext/msgpack
/opt/td-agent/embedded/bin/ruby -r ./siteconf20200210-967-1s5gonu.rb extconf.rb
checking for ruby/st.h... *** 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
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/td-agent/embedded/bin/$(RUBY_BASE_NAME)
/opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:468:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:599:in `try_cpp'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:1107:in `block in have_header'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:957:in `block in checking_for'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:351:in `block (2 levels) in postpone'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:321:in `open'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:351:in `block in postpone'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:321:in `open'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:347:in `postpone'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:956:in `checking_for'
from /opt/td-agent/embedded/lib/ruby/2.4.0/mkmf.rb:1106:in `have_header'
from extconf.rb:3:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/opt/td-agent/embedded/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0/msgpack-1.3.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/msgpack-1.3.3 for inspection.
Results logged to /opt/td-agent/embedded/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0/msgpack-1.3.3/gem_make.out
#原因
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.
や、You have to install development tools first.
というメッセージがあることから、rubyの開発環境が足りていないことがわかる。
#対応策
Rubyの開発環境を一式放り込んだ。
sudo yum -y install gcc-c++ glibc-headers openssl-devel readline libyaml-devel readline-devel zlib zlib-devel libffi-devel libxml2 libxslt libxml2-devel libxslt-devel sqlite-devel
#結果
無事インストールできた。
$ sudo /opt/td-agent/embedded/bin/gem install fluent-plugin-cloudwatch-logs --no-ri --no-rdoc
Building native extensions. This could take a while...
Successfully installed msgpack-1.3.3
Fetching: fluentd-1.9.1.gem (100%)
Successfully installed fluentd-1.9.1
Fetching: aws-partitions-1.271.0.gem (100%)
Successfully installed aws-partitions-1.271.0
Fetching: aws-sdk-core-3.89.1.gem (100%)
Successfully installed aws-sdk-core-3.89.1
Fetching: aws-sdk-cloudwatchlogs-1.28.0.gem (100%)
Successfully installed aws-sdk-cloudwatchlogs-1.28.0
Fetching: fluent-plugin-cloudwatch-logs-0.8.0.gem (100%)
Successfully installed fluent-plugin-cloudwatch-logs-0.8.0
6 gems installed
#雑感
AWSとか普通の環境を触り始めて1か月くらいたってようやくこの手のエラー対応に慣れてきたなぁ、と思いました(遅い)