LoginSignup
2
2

More than 1 year has passed since last update.

fluentdメモ - (1) インストール/簡易操作

Last updated at Posted at 2020-04-15

はじめに

fluentdに関するメモ書きです。

<環境>
RHEL V7.5
td-agent v3 (fluentd v1)

関連記事

fluentdメモ - (1) インストール/簡易操作
fluentdメモ - (2) 設定ファイル概要
fluentdメモ - (3) 設定ファイル調査 Input/Fileter/Output編
fluentdメモ - (4) 設定ファイル調査 Buffer編

インストール

参考: td-agent v2 vs v3

Treasure Data, Inc. maintains stable packages for Fluentd and canonical plugins as Treasure Agent (the package is called td-agent). td-agent has v2 and v3. td-agent v2 for the production and v3 is the new stable version for working with ruby 2.4 and fluetnd v1 series.

Treasure Data Incが、fluentdを含むパッケージとしてtd-agentという名前で提供してくれています。td-agent v3がfluentd v1相当なので、今回はこれを導入することになります。
コマンドやディレクトリなども"fluentd"ではなく"td-agent"になってますが、中身はfluentdです。
Rubyのgemでインストールするとfluentdという名前になるらしい。分かりにくっ!
(ネーミングって大事だよね。)

RPMによりインストールします。
Install by RPM Package (Redhat Linux)

[root@test08 ~]# curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   849  100   849    0     0   8491      0 --:--:-- --:--:-- --:--:--  8575
==============================
 td-agent Installation Script
==============================
This script requires superuser access to install rpm packages.
You will be prompted for your password by sudo.
読み込んだプラグイン:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
treasuredata                                                                                                                                     | 2.9 kB  00:00:00
treasuredata/7Server/x86_64/primary_db                                                                                                           |  31 kB  00:00:00

ansible.noarch                                                                        2.9.3-1.el7                                                                   epel
epel-release.noarch                                                                   7-12                                                                          epel
jq.x86_64                                                                             1.6-1.el7                                                                     epel
python-httplib2.noarch                                                                0.9.2-0.2.el7                                                                 epel
python-paramiko.noarch                                                                2.1.1-0.10.el7                                                                epel
python2-crypto.x86_64                                                                 2.6.1-16.el7                                                                  epel
読み込んだプラグイン:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ td-agent.x86_64 0:3.6.0-0.el7 を インストール
--> 依存性の処理をしています: redhat-lsb-core のパッケージ: td-agent-3.6.0-0.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ redhat-lsb-core.x86_64 0:4.1-27.el7 を インストール
--> 依存性の処理をしています: redhat-lsb-submod-security(x86-64) = 4.1-27.el7 のパッケージ: redhat-lsb-core-4.1-27.el7.x86_64
--> 依存性の処理をしています: spax のパッケージ: redhat-lsb-core-4.1-27.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ redhat-lsb-submod-security.x86_64 0:4.1-27.el7 を インストール
---> パッケージ spax.x86_64 0:1.5.2-13.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

========================================================================================================================================================================
 Package                                             アーキテクチャー                バージョン                             リポジトリー                           容量
========================================================================================================================================================================
インストール中:
 td-agent                                            x86_64                          3.6.0-0.el7                            treasuredata                           51 M
依存性関連でのインストールをします:
 redhat-lsb-core                                     x86_64                          4.1-27.el7                             rhel-dvd                               37 k
 redhat-lsb-submod-security                          x86_64                          4.1-27.el7                             rhel-dvd                               15 k
 spax                                                x86_64                          1.5.2-13.el7                           rhel-dvd                              260 k

トランザクションの要約
========================================================================================================================================================================
インストール  1 パッケージ (+3 個の依存関係のパッケージ)

総ダウンロード容量: 51 M
インストール容量: 172 M
Downloading packages:
td-agent-3.6.0-0.el7.x86_64.rpm                                                                                                                  |  51 MB  00:00:07
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                                                    6.8 MB/s |  51 MB  00:00:07
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : spax-1.5.2-13.el7.x86_64                                                                                                                1/4
  インストール中          : redhat-lsb-submod-security-4.1-27.el7.x86_64                                                                                            2/4
  インストール中          : redhat-lsb-core-4.1-27.el7.x86_64                                                                                                       3/4
  インストール中          : td-agent-3.6.0-0.el7.x86_64                                                                                                             4/4
adding \'td-agent\' group if needed...
adding \'td-agent\' user if needed...
Installing default conffile...
prelink detected. Installing /etc/prelink.conf.d/td-agent-ruby.conf ...
Installing logrotate.d config
Configure td-agent to start, when booting up the OS...
  検証中                  : redhat-lsb-core-4.1-27.el7.x86_64                                                                                                       1/4
  検証中                  : redhat-lsb-submod-security-4.1-27.el7.x86_64                                                                                            2/4
  検証中                  : td-agent-3.6.0-0.el7.x86_64                                                                                                             3/4
  検証中                  : spax-1.5.2-13.el7.x86_64                                                                                                                4/4

インストール:
  td-agent.x86_64 0:3.6.0-0.el7

依存性関連をインストールしました:
  redhat-lsb-core.x86_64 0:4.1-27.el7                    redhat-lsb-submod-security.x86_64 0:4.1-27.el7                    spax.x86_64 0:1.5.2-13.el7

完了しました!

Installation completed. Happy Logging!

簡易操作例

設定ファイル: /etc/td-agent/td-agent-test.conf を以下のように作成

/etc/td-agent/td-agent-test.conf
<system>
  log_level debug
</system>

<source>
  @type forward
  @id input_forward
</source>

<match **>
  type stdout
</match>

設定ファイルの詳細は別記事に記載しますので、ここでは簡単に補足します。

<source>forward input plugin というのを使う設定をしています(in_forward)。
これによりfluentdが特定のポートでリモートからのログを受け付けてくれます。(他のノードのfluentdからフォワードされてきたり、fluentdのクライアントからログ送信が行われることを想定しているようです。)

<match>では、stdout output pluginを使って標準出力にログを出すように設定しています(out_stdout)。入力、出力、加工は、ログに付けられた"タグ"の単位ごとに指定します。ここでは、"**"を指定しているので、任意のタグがつけられたログの処理を記述しています。

この設定を使用してfluentdを起動します。

[root@test08 /etc/td-agent]# td-agent -c td-agent-test.conf
2020-04-12 16:10:45 +0900 [info]: parsing config file is succeeded path="td-agent-test.conf"
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-mixin-config-placeholders' version '0.4.0'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-mixin-rewrite-tag-name' version '0.1.0'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-elasticsearch' version '4.0.7'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-elasticsearch' version '4.0.3'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-kafka' version '0.12.3'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-prometheus' version '1.7.3'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-prometheus_pushgateway' version '0.0.1'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-record-modifier' version '2.1.0'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-record_splitter' version '0.2.1'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '2.2.0'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-s3' version '1.3.0'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-systemd' version '1.0.2'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-td' version '1.1.0'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-td-monitoring' version '0.2.4'
2020-04-12 16:10:45 +0900 [info]: gem 'fluent-plugin-webhdfs' version '1.2.4'
2020-04-12 16:10:45 +0900 [info]: gem 'fluentd' version '1.9.2'
2020-04-12 16:10:45 +0900 [warn]: 'type' is deprecated parameter name. use '@type' instead.
2020-04-12 16:10:45 +0900 [warn]: define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2020-04-12 16:10:45 +0900 [info]: using configuration file: <ROOT>
  <system>
    log_level debug
  </system>
  <source>
    @type forward
    @id input_forward
  </source>
  <match **>
    type stdout
  </match>
</ROOT>
2020-04-12 16:10:45 +0900 [info]: starting fluentd-1.9.2 pid=4410 ruby="2.4.9"
2020-04-12 16:10:45 +0900 [info]: spawn command to main:  cmdline=["/opt/td-agent/embedded/bin/ruby", "-Eascii-8bit:ascii-8bit", "/usr/sbin/td-agent", "-c", "td-agent-test.conf", "--under-supervisor"]
2020-04-12 16:10:46 +0900 [warn]: #0 'type' is deprecated parameter name. use '@type' instead.
2020-04-12 16:10:46 +0900 [info]: adding match pattern="**" type="stdout"
2020-04-12 16:10:46 +0900 [info]: adding source type="forward"
2020-04-12 16:10:46 +0900 [warn]: #0 define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2020-04-12 16:10:46 +0900 [info]: #0 starting fluentd worker pid=4421 ppid=4410 worker=0
2020-04-12 16:10:46 +0900 [info]: #0 [input_forward] listening port port=24224 bind="0.0.0.0"
2020-04-12 16:10:46 +0900 [info]: #0 fluentd worker is now running worker=0
2020-04-12 16:10:46.567072099 +0900 fluent.info: {"pid":4421,"ppid":4410,"worker":0,"message":"starting fluentd worker pid=4421 ppid=4410 worker=0"}
2020-04-12 16:10:46.567287163 +0900 fluent.info: {"port":24224,"bind":"0.0.0.0","message":"[input_forward] listening port port=24224 bind=\"0.0.0.0\""}
2020-04-12 16:10:46.569092897 +0900 fluent.info: {"worker":0,"message":"fluentd worker is now running worker=0"}

fluentd起動時のログに、forard inputプラグインが24224ポート(デフォルト)でListenしている旨のメッセージも出ています。

[root@test08 ~]# netstat -an | grep 24224
tcp        0      0 0.0.0.0:24224           0.0.0.0:*               LISTEN
udp        0      0 0.0.0.0:24224           0.0.0.0:*

テスト用のログをforwart input pluginに対して投げてみます。
簡易的にin_fowardにメッセージを投げることができるfluentdクライアントのコマンド(fluent-cat)が提供されているのでそれを使います。
参考: fluent-cat

[root@test08 ~]# echo '{"message":"Hello World."}' | /opt/td-agent/embedded/bin/fluent-cat debug.test

上の例では、{"message":"Hello World."}というJSONデータを、debug.testというタグをつけてfluentdに投入していることになります。
fluentdを実行したコンソールを見ると、以下のようなメッセージが出力されるのが確認できます。

2020-04-12 16:26:37.721094625 +0900 debug.test: {"message":"Hello World."}
2
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
2
2