0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Syslogを収集し、Fluentdを利用して別システムへ転送する

Last updated at Posted at 2024-12-20

概要

Syslogを収集する環境を作成し、そのログをさらに別システムへ転送するための手順を記載します。

環境

本手順で取り扱う内容は、次の環境にて確認しています。

  • Syslog client
    マシン:Amazon EC2
    OS:Ubuntu 24.04

  • Syslog server & Fluentd server
    マシン:Amazon EC2
    OS:Ubuntu 24.04
    Fluentd:1.16.6

構成図は次のようになります。
image.png

Syslog ClientはSyslog serverにログを転送します。
そしてSyslog serverにFluentdを導入し、別システムへ転送する仕組みです。
なお、Syslog clientは通常、複数台存在するはずですが、本記事では話をシンプルにするために1台構成としています。

手順

ログ収集環境セットアップ手順

ログ収集環境をセットアップするための手順を記載します。

通信設定

Syslog serverのセキュリティグループのインバウンドルールにて、Syslog clientからのUDP 514 Port接続を許可して下さい。

rsyslogdセットアップ​(Syslog server)

rsyslog.confを編集します。

$ sudo vi /etc/rsyslog.conf

編集内容ですが、clientからUDPでsyslogを受信するために次の2行をアンコメントして下さい。

module(load="imudp")
input(type="imudp" port="514")

また、syslogをfluentdに送信するために/etc/rsyslog.d/30-fluentd.confファイルを作成して下さい。

$ sudo vi /etc/rsyslog.d/30-fluentd.conf

ファイルの内容は次のようにして下さい。
全てのFacility・SeverityのログをFluentdに転送する設定です。
Facility・Severityについてはこちらのページが参考になるかと思います。

*.* @localhost:5140

編集が完了したら、変更内容を反映させて下さい。

$ sudo systemctl restart rsyslog.service

rsyslogdセットアップ​(Syslog client)

Syslog clientでは/etc/rsyslog.d/30-syslogsv.confファイルを作成して下さい。

$ sudo vi /etc/rsyslog.d/30-syslogsv.conf

ファイルの内容は次のようにして下さい。
全てのFacility・SeverityのログをSyslog serverに転送する設定です。

*.* @<Syslog server IP>:514

編集が完了したら、変更内容を反映させて下さい。

$ sudo systemctl restart rsyslog.service

以上でログ収集環境のセットアップは完了です。

Fluentdセットアップ及び、別システムへの転送設定

Fluentdインストール​(Syslog server)

Fluentdのガイドに従ってインストールして下さい。
次のコマンドでは、Ubuntu24.04にFluentdをインストールします。

$ curl -fsSL https://toolbelt.treasuredata.com/sh/install-ubuntu-noble-fluent-package5-lts.sh | sh

Config設定

fluentd.confを編集します。

$ sudo vi /etc/fluent/fluentd.conf

ファイルの中身を書き換えて下さい。
次のfluentd.confはサンプルになります。

<source>
  @type syslog
  port 5140
  bind 0.0.0.0
  tag test
  <parse>
    @type none
  </parse>
</source>

<match test.**>
  @type http
  endpoint <YOUR-ENDPOINT>
  open_timeout 2
  <format>
    @type json
  </format>
  content_type application/json
  headers {"Authorization": "Bearer <YOUR-ACCESSTOKEN>"}
  <buffer>
    chunk_limit_records 1
  </buffer>
</match>

編集が完了したら、変更内容を反映させて下さい。

$ sudo systemctl restart fluentd

動作確認

転送先システムにて、ログが受信できていることを確認して下さい。
もしくはloggerコマンドをSyslog clientにて実行し、​手動で確認することも可能です。

$ logger TEST TEST TEST

もし、受信できていない場合、fluentdログ(/var/log/fluent/fluentd.log)を確認することが有効です。

参考

https://docs.fluentd.org/installation
https://www.infraexpert.com/study/syslog1.html

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?