# Fluentd를 통한 Syslog -> S3

## 개요

{% hint style="warning" %}
사용을 고려하세요 [Fluent Bit](/ko/data-onboarding/data-pipeline-tools/fluent-bit-onboarding-guide.md) Panther로 로그를 전달하는 데 Fluentd 대신 사용하세요. Fluent Bit은 Fluentd보다 설정이 더 쉽고 리소스 사용량이 적습니다.
{% endhint %}

이 가이드는 Fluentd를 사용하여 syslog 메시지를 S3로 전달하는 방법을 제공합니다. 두 가지 다른 파이프라인 흐름이 있습니다: AWS Firehose 전송 스트림을 통한 방식과 AWS S3 버킷에 직접 전달하는 방식입니다.

### 사전 요구 사항

이 가이드는 S3 버킷 또는 Firehose가 이미 생성되어 있다고 가정합니다. 이러한 리소스 중 하나를 생성해야 하는 경우 다음을 참조하세요. [Fluentd 온보딩 가이드](/ko/data-onboarding/data-pipeline-tools/fluentd.md). 이미 리소스를 프로비저닝한 경우 아래 가이드를 필요에 맞게 조정할 수 있습니다.

## Fluentd 설정

### 1단계. Fluentd 설치

다음을 따르세요. [Fluentd 설치 가이드](https://docs.fluentd.org/installation) syslog 메시지를 수집하려는 서버 환경에 맞는 가이드를 따르세요.

### 2단계. Fluentd 구성 편집

Fluentd를 구성할 때 두 가지 옵션이 있습니다: Firehouse 플러그인 또는 S3 플러그인 사용. 아래에는 두 옵션에 대한 구성 파일이 있습니다.

두 옵션 중 더 성능이 좋은 Firehose 플러그인 옵션을 권장합니다. 하지만 두 옵션 모두 로그를 S3로 전달합니다. 구성에는 두 가지 다른 인증 유형이 표시됩니다: 역할 수임과 액세스 키입니다. 환경에 가장 적합한 인증 유형을 사용하세요.

#### **Firehose 플러그인 사용(권장)**

다음 Fluentd를 설치하세요 [플러그인](https://github.com/awslabs/aws-fluent-plugin-kinesis#installation):

```
td-agent-gem install fluent-plugin-kinesis
```

다음 구성으로 Fluentd 구성 파일을 편집하세요`/etc/td-agent/td-agent.conf` . 이렇게 하면 Fluentd가 udp 포트 5140을 통해 syslog 이벤트를 수신하고 Kinesis Firehose로 출력할 수 있습니다. 아래 구성에서 다음을 업데이트하세요. `리전`, `delivery_stream_name` 및 `role_arn` :

```
<source>
  @type syslog
  port 5140
  bind 0.0.0.0
  tag syslog
  <parse>
    message_format auto
  </parse>
</source>

<filter syslog.** >
  @type record_transformer
  <record>
    tag ${tag}
    time ${time}
  </record>
</filter>

<match syslog.**>
  @type kinesis_firehose
  region <FIREHOSE-REGION>
  delivery_stream_name <FIREHOSE-NAME>

  <assume_role_credentials>
    duration_seconds 3600
    role_arn <FIREHOSE-ROLE-ARN>
    role_session_name "#{Socket.gethostname}-panther-audit"
  </assume_role_credentials>
  <format>
    @type json
  </format>
</match>
```

#### **S3 플러그인 사용**

다음 구성으로 Fluentd 구성 파일을 편집하세요 `/etc/td-agent/td-agent.conf` 다음 구성으로 설정하세요. 이렇게 하면 Fluentd가 udp 포트 5140을 통해 syslog 이벤트를 수신하고 S3 버킷으로 출력할 수 있습니다. 다음을 업데이트하세요. `s3_bucket`, `s3_region`, `aws_key_id`, 및 `aws_sec_key` :

```
<source>
  @type syslog
  port 5140
  bind 0.0.0.0
  tag syslog
  <parse>
    message_format auto
  </parse>
</source>

<filter syslog.** >
  @type record_transformer
  <record>
    tag ${tag}
    time ${time}
  </record>
</filter>

<match syslog.**>
  @type s3
  aws_key_id <ACCESS-KEY-ID>
  aws_sec_key <SECRET-KEY>
  s3_bucket <BUCKET-NAME>
  s3_region <BUCKET-REGION>
  path syslog/%Y/%m/%d/
  store_as gzip
  <buffer tag,time>
    @type file
    path /var/log/td-agent/buffer/s3
    timekey 300 # 5분 파티션
    timekey_wait 2m
    timekey_use_utc true # utc 사용
    chunk_limit_size 256m
  </buffer>
  <format>
    @type json
  </format>
</match>
```

### 3단계: Fluentd 시작

Fluentd를 구성한 후 아래 명령을 실행하여 시작하세요:

```
$ sudo systemctl start td-agent.service 
```

Fluentd가 실행 중인지 확인하세요:

```
$ sudo systemctl status td-agent.service
```

다음을 참조하세요. [Fluentd 설치 가이드](https://docs.fluentd.org/installation) systemctl `를 사용할 수 없는 경우 환경에서 Fluentd를 시작하는 방법에 대해` 를 사용할 수 없습니다.

## rsyslog 구성

### 로컬 Fluentd로 전달하도록 rsyslog 구성

구성하세요. `rsyslog` 를 로컬 Fluentd 데몬으로 메시지를 전달하도록 하려면 다음 두 줄을 `/etc/rsyslog.d/50-default.conf` 또는 `/etc/rsyslog.conf` 의 맨 아래에 추가하세요. 일부 환경에서는 다음이 해당됩니다:

```
# 로그 메시지를 Fluentd로 전송
*.* @127.0.0.1:5140
```

아래 명령으로 rsyslog를 재시작하세요:

```
$ sudo systemctl restart rsyslog.service
```

{% hint style="info" %}
이 단계는 다른 서버에도 동일하게 적용하여, 이전에 이 가이드에서 구성한 Fluentd 서버로 syslog를 전달할 수 있습니다. 로컬 주소만 `*.* @127.0.0.1:5140` 를 Fluentd 서버의 IP 주소로 바꾸세요. 서버로 udp/5140 트래픽을 보낼 수 있도록 보안 그룹 또는 호스트 기반 방화벽을 업데이트해야 할 수 있습니다.
{% endhint %}

## 로깅 확인

5\~10분 후 syslog 메시지가 S3 버킷에 기록되는지 확인하세요. 로그는 버킷 내 `syslog/` 접두사 아래에 표시되어야 합니다.

이제 S3 버킷을 온보딩하고 다음을 사용하여 Panther UI에서 데이터를 온보딩할 수 있습니다. `Fluentd.Syslog3164` 로그 유형.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.panther.com/ko/data-onboarding/data-pipeline-tools/fluentd/syslog-to-s3-via-fluentd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
