プロジェクト

全般

プロフィール

fluentdのインストール(ログを集約する)

fluentdはログの集約成形などを行うデーモン
今回はfluentdにいくつかのプラグインを同封したパッケージ版となる
『td-agent』をインストールする。

インストール

下記オフィシャルでRPMが配布されている。
https://www.fluentd.org/download

RPMをそのまま使ってもよさそうだが、インストールガイドを見る限りでは
次のコマンドを使う模様。依存関係を含めてインストールされる。

$ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh
…
…
Installation completed. Happy Logging!

設定

  • とりあえず初回起動を自動起動設定を行う。
    systemctl start td-agent
    systemctl enable td-agent
    
  • デフォルトでは次のポートでデバッグ用のログ受付を行っている
    # HTTP input
    # POST http://localhost:8888/<tag>?json=<json>
    # POST http://localhost:8888/td.myapp.login?json={"user"%3A"me"}
    # @see http://docs.fluentd.org/articles/in_http
    <source>
      @type http
      @id input_http
      port 8888
    </source>
    
  • 上記の結果は次の出力定義先に出力される
    ## match tag=debug.** and dump to console
    <match debug.**>
      @type stdout
      @id output_stdout
    </match>
    

動作確認

  • 次のコマンドで「debug.test」タグでテストを行うことが可能
    curl -X POST -d 'json={"json":"test"}' http://localhost:8888/debug.test
    
  • 上記の場合、「stdout」プラグインにより標準出力に出力される。
    結果、次のデフォルトのログファイルに出力される
    less /var/log/td-agent/td-agent.log
    …
    …
    2019-09-02 12:48:19.449849271 +0900 debug.test: {"json":"test"}