LoginSignup
1
1

More than 5 years have passed since last update.

td-agent3のファイルディスクリプタの最適化と実行ユーザーをrootに設定した状態でAWS(EB)にデプロイ

Last updated at Posted at 2019-04-24

目次
1. はじめに
2. .ebextension内にファイルディスクリプタの最適化をするシェルスクリプトを書く
3. .ebextension内にtd-agent3の実行ユーザーをrootにするシェルスクリプトを書く
4. おわりに

1.はじめに

環境
・AWS ElasticBeanstalk , Ruby -v 2.6.1
・Amazon Linux AMI release 2018.03
・td-agent -v1.0(td-agent3)

本記事は表題の設定を済ました上で、td-agent-v1.0(td-agent3)をAWSのElasticBeanstalkへデプロイした際の忘備録です。

AWSのElasticBeanstalkへtd-agent-v1.0をデプロイする方法は別記事で書きましたので、こちらをご参照ください。

2. .ebextension内にファイルディスクリプタの最適化をするシェルスクリプトを書く

まずは $ ulimit -nで現状のファイルスクリプタの値を確認してください。
もし1024と表示された場合は不足しているので、最適化しろとのことです。

ファイルディスクリプタ設定.conf
 container_commands:
  limits_conf_settings:
    command: |
      cp /etc/security/limits.conf /etc/security/limits.conf.origin
      cd /etc/security/
      sed -i -e '1i root\ soft\ nofile\ 65536\nroot\ hard\ nofile\ 65536\n*\ soft\ nofile\ 65536\n*\ hard\ nofile\ 65536' limits.conf
      cat /etc/security/limits.conf

やっていることとしては、
・limits.confを念のためコピー作成
・/etc/security/ 配下へ移動
・limits.confの最初の行に下記を追加
・設定が反映されているか確認

root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536

デプロイ後にもう一度$ ulimit -nを実行し、65536と表示されれば成功です。

注意していただきたいのは、私の場合conntainer_commandsを使用しておりますが、環境はそれぞれ違うと思いますので、その辺に関する詳しい設定はAWS公式をご参照ください。

3. .ebextension内にtd-agent3の実行ユーザーをrootにするシェルスクリプトを書く

commands:
  省略

  02-command:
    command: curl -L https://toolbelt.treasuredata.com/sh/install-amazon1-td-agent3.sh | sh

  03-command:
    command: |
      cp /etc/init.d/td-agent /etc/init.d/td-agent.origin
      cd /etc/init.d/
      sed -i "18 s/td-agent/root/g" td-agent
      sed -i "19 s/td-agent/root/g" td-agent
      cat /etc/init.d/td-agent

  04-command:
    command: sudo /etc/init.d/td-agent restart

rpmでインストールした直後にTD_AGENT_USER=td-agentTD_AGENT_GROUP=td-agentそれぞれをrootに変更する処理を書きました。

4. おわりに

各種設定ファイルを書く順番やコマンドが実行されるタイミングに注意してください。
うまく噛み合わないとデプロイに失敗したり、設定が反映されない恐れがあります。

以上となります。
なにかご指摘あれば優しくコメントいただけると幸いです😊


参考

Before Installing Fluentd

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1