# Fluentd를 통한 일반 로그 전달

## 개요

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

이 가이드는 S3와 Fluentd를 통해 파일에서 Panther로 원시 로그를 전달하는 방법을 설명합니다. 아래 Fluentd 구성은 데이터를 사전 처리하지 않으며, 대신 파일 내용 자체를 있는 그대로 전달합니다. 이 가이드는 다음 작업을 수행하는 방법을 안내합니다:

* 장치에 Fluentd를 설치합니다.
* AWS Firehose 또는 S3 플러그인을 통해 Fluentd 구성을 편집합니다.
* Fluentd 인스턴스를 시작하고 정상적으로 실행되는지 확인합니다.

### 사전 요구 사항

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

## 원시 로그를 Panther에 전달하도록 Fluentd 설정하기

### 1단계: Fluentd 설치

다음을 따르세요 [Fluentd 설치 가이드](https://docs.fluentd.org/installation) 를 참고하여 syslog 메시지를 수집하려는 서버 환경에 설치하세요. 설치가 완료되면 아래의 터미널 구성을 진행하여 Fluentd를 올바르게 설정할 수 있습니다.

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

{% hint style="info" %}
Fluentd를 구성할 때 Firehouse 플러그인 또는 S3 플러그인 두 가지 옵션이 있습니다. Panther와 함께 사용할 경우 더 뛰어난 성능을 제공하므로 Firehose 플러그인 옵션을 권장합니다. 하지만 두 옵션 모두 로그를 S3로 전달합니다. \\

구성에는 두 가지 서로 다른 인증 유형이 표시됩니다. 역할 위임(assume roles) 또는 액세스 키 중 하나를 사용하세요. 환경에 가장 적합한 인증 유형을 사용하세요.
{% endhint %}

Fluentd의 아래 플러그인 구성에 유의하세요:

* The `<source>` 섹션은 tail 플러그인을 사용하여 로그 파일에서 읽습니다.
* The `<parse>` 섹션은 Fluentd가 다음을 사용해 어떤 파싱도 수행하지 않도록 지시합니다 `@type none`.
* 다음 내에서 `match format` 섹션에서는 `single_value` 유형이 사용됩니다.
* 의 조합은 `none` 파싱과 `single_value` format은 Fluentd가 데이터를 있는 그대로 출력하도록 지시합니다.

#### **구성 1: Firehose 플러그인 사용(권장)**

Fluentd의 Firehose 플러그인을 설치하여 다음을 활용해야 합니다 `@type kinesis 플러그인`**.**

1. **설치** 다음 [Fluentd 플러그인](https://github.com/awslabs/aws-fluent-plugin-kinesis#installation) 을 아래 명령으로 설치하세요.\\

   ```yaml
   td-agent-gem install fluent-plugin-kinesis
   ```
2. **편집** 다음 위치에 있는 Fluentd 구성 파일 `/etc/td-agent/td-agent.conf` 을 아래 구성으로 설정하세요. 다음 값을 반드시 업데이트하세요. `region`, `delivery_stream_name`, 그리고 `role_arn`:\\

   ```
   <source>  
     @type tail
     tag syslog
     path /path/to/file/*.log
     pos_file /var/log/td-agent/pos_file.pos
     <parse>
       @type none
     </parse>
   </source>

   <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 single_value
     </format>
   </match>
   ```

#### **구성 2: S3 플러그인 사용**

1. **편집** 다음 위치에 있는 Fluentd 구성 파일 `/etc/td-agent/td-agent.conf,` 을 아래 구성으로 설정하세요. 다음 값을 반드시 업데이트하세요. `s3_bucket`, `s3_region`, `aws_key_id`, 그리고 `aws_sec_key`:\\

   ```
   <source>  
     @type tail
     tag syslog
     path /path/to/file/*.log
     pos_file /var/log/td-agent/pos_file.pos
     <parse>
       @type none
     </parse>
   </source>

   <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 single_value
     </format>
   </match>
   ```

### 3단계: Fluentd 시작

1. Fluentd 구성을 완료한 후, 터미널에서 아래 명령을 실행하세요:\\

   ```
   $ sudo systemctl start td-agent.service 
   ```
2. Fluentd가 정상적으로 실행 중인지 확인하려면, 터미널에서 아래 명령을 실행하세요:\\

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

{% hint style="info" %}
만약 `systemctl` 이 Fluentd 환경에서 사용할 수 없다면, 다음을 참조하세요 [Fluentd 설치 가이드](https://docs.fluentd.org/installation).
{% endhint %}


---

# 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/general-log-forwarding-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.
