LoginSignup
3

More than 5 years have passed since last update.

td-agentでAWS S3へログアップロード

Posted at

TL;DR

  • ① td-agentをインストール
  • ② td-agentディレクトリ調整
  • ③ td-agent設定ファイル設定

準備

下記ログファイルをtd-agent経由で、AWS S3へアップロードする。
なお、apacheインストールと、AWS S3へのAMI設定が済んでいる状態とする。

/var/log/httpd/access_log
/var/log/httpd/error_log

操作手順

① td-agentをインストール

td-agent インストール

curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh

インストールバージョン確認

td-agent -v

Plugin インストール

td-agent-gem install fluent-plugin-s3
td-agent-gem install fluent-plugin-forest

② td-agentディレクトリ調整

ログ配置場所作成

mkdir /var/log/td-agent/s3

設定ファイル追記

vi /etc/td-agent/td-agent.conf

対象ログディレクトリの権限変更

chmod o+x /var/log/httpd

③ td-agent設定ファイル設定

vi /etc/td-agent/td-agent.conf

#Apache
<source>
 type tail
 format none
 path /var/log/httpd/access_log
 pos_file /var/log/td-agent/httpd.access.pos
 tag td.httpd.access
</source>

<source>
 type tail
 format none
 path /var/log/httpd/error_log
 pos_file /var/log/td-agent/httpd.error.pos
 tag td.httpd.error
</source>

<match td.httpd.**>
 type forest
 subtype s3
 <template>
  aws_key_id (your-aws-key)
  aws_sec_key (your-aws-secretkey)
  s3_bucket test-backup
  s3_region ap-northeast-1
  s3_enpoint s3-ap-northeast-1.amazonaws.com
 </template>
  <case *.httpd.access>
   buffer_type file
   buffer_path /var/log/td-agent/buffer/httpd.access
   path log/httpd/access_log/${hostname}/access_log_
  </case>
  <case *.httpd.error>
   buffer_type file
   buffer_path /var/log/td-agent/buffer/httpd.error
   path log/httpd/error_log/${hostname}/error_log_
  </case>
</match>

下記設定項目があれば、ローカルバッファからS3へのアップロード待機時間を設定することが可能。

time_slice_format %Y%m%d
time_slice_wait 10m

td-agent停止時にファイルバッファをS3へアップするか、アップせずに残しておくは下記で選択可能。

flush_at_shutdown true

参照

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
3