LoginSignup
0
2

More than 5 years have passed since last update.

Fluentd ってどんなことができるのか試してみたかった(メモ+α)

Posted at

動機

ログファイルが複数のサーバに配置され、ログファイルが肥大化されることをどうにかしたい

Fluentd のインストール

参考にしたサイト

インストール

$ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) Peer reports incompatible or unsupported protocol version.

下記ファイルをブラウザで確認してコマンドラインで実行しました。

install-redhat-td-agent2.sh
echo "This script requires superuser access to install rpm packages."
echo "You will be prompted for your password by sudo."

# clear any previous sudo permission
sudo -k

# run inside sudo
sudo sh <<SCRIPT

  # add GPG key
  rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent

  # add treasure data repository to yum
  cat >/etc/yum.repos.d/td.repo <<'EOF';
[treasuredata]
name=TreasureData
baseurl=http://packages.treasuredata.com/2/redhat/\$releasever/\$basearch
gpgcheck=1
gpgkey=https://packages.treasuredata.com/GPG-KEY-td-agent
EOF

  # update your sources
  yum check-update

  # install the toolbelt
  yes | yum install -y td-agent

SCRIPT

Fluentd 設定

ログ監視の設定

$ vi /etc/td-agent/td-agent.conf 
/etc/td-agent/td-agent.conf
<source>
  type tail
  path /var/log/httpd/access_log
  pos_file /var/log/td-agent/sample.pos
  format none
  tag apache.access
</source>

<match apache.access>
  type file
  path /tmp/access_log.fluentd
</match>

設定反映

$ sudo systemctl start td-agent

Fluentd 動作確認

ファイル書き込み確認

$ ls -l /tmp/
-rw-r--r-- 1 td-agent td-agent 282  5月 14 13:02 access_log.fluentd.20170514.b54f7b8a7c0f105a4

別ターミナルで下記コマンドを実施

$ curl localhost

localhost へのアクセスが書き込まれていることを確認

$ tail -f access_log.fluentd.20170514.b54f7b8a7c0f105a4 
2017-05-14T13:01:46+00:00   apache.access   {"message":"::1 - - [14/May/2017:13:01:46 +0000] \"GET / HTTP/1.1\" 200 2321 \"-\" \"curl/7.29.0\""}
2017-05-14T13:02:56+00:00   apache.access   {"message":"::1 - - [14/May/2017:13:02:56 +0000] \"GET / HTTP/1.1\" 200 2321 \"-\" \"curl/7.29.0\""}
2017-05-14T13:40:26+00:00   apache.access   {"message":"::1 - - [14/May/2017:13:40:25 +0000] \"GET / HTTP/1.1\" 200 2321 \"-\" \"curl/7.29.0\""}

やってみて

これで apache log のアクセスについては確認ができる様になったので次回はこのログを一括でサーバへ格納して、WEBサーバなどのログの圧迫をなくせるのかなと思いました。
今後は、ログを管理サーバに転送、kibana / MongoDB / elasticsearch などを使ってログデータの集積、分析、創造できることやってみようと思います。

あとがき

今後のやろうとしていることで、アドバイスや最善の方法など、参考意見があれば教えてください。
色々取り入れて今後のメモなどとしていこうとおもいます。

0
2
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
0
2