# Fluentd를 통한 MacOS 시스템 로그 -> S3

## 개요

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

이 가이드는 Fluentd를 사용하여 MacOS 시스템 로그를 S3로 전달하는 방법을 제공합니다. 두 가지 서로 다른 파이프라인 흐름이 있습니다: AWS Firehose 전달 스트림을 통해서와 AWS S3 버킷으로 직접 전달하는 방식입니다

### 사전 요구 사항

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

## Fluentd 설정

### 1단계. Fluentd(td-agent) 설치

Fluentd 설치 [지침을](https://docs.fluentd.org/installation/install-by-dmg) MacOS 시스템 로그를 수집하려는 머신에서. 이 가이드는 특히 로그 수집 서비스로 td-agent를 사용하는 방법을 다룹니다.

### 2단계. MacOS 로그용 Fluent 플러그인 설치

아래 명령을 사용하여 Fluentd MacOS 플러그인을 설치합니다.

```
sudo /opt/td-agent/bin/fluent-gem install fluent-plugin-macos-log
```

이 플러그인에 대한 추가 문서는 다음에서 찾을 수 있습니다 [Github](https://github.com/loggly/fluent-plugin-macos-log).

### 3단계. Fluentd 설정 편집

기본적으로 포함된 구성 정보는 사용하지 않는다면 제거할 수 있습니다. 아래 Fluentd 구성을 사용하고 다음을 추가하세요 `aws_key_id`, `aws_sec_key`, `s3_bucket`, 및 `s3_region` 정보.

Fluentd와 td-agent는 충돌하는 포트에서 서비스를 실행하려고 시도합니다. 새 설치인 경우 구성 파일의 포트를 변경하거나 파일에서 기본 구성을 제거해야 합니다.

```
/etc/td-agent/td-agent.conf
```

```
<source>
  @type macoslog
  style ndjson
  tag macos
  pos_file last-starttime.log
  run_interval 10s
  <parse>
    @type json
    time_type string
    time_key timestamp
    time_format %Y-%m-%d %H:%M:%S.%L%z
  </parse>
</source>

<match **>
  @type s3
  aws_key_id <Key ID>
  aws_sec_key <Key>
  s3_bucket <Bucket>
  s3_region <Region>
  path macoslog/%Y/%m/%d/
  store_as gzip
  <buffer tag,time>
    @type file
    path /var/log/fluent/s3
    timekey 300 # S3에 게시하기 위한 5분 파티션
    timekey_wait 2m
    timekey_use_utc true # UTC 사용
    chunk_limit_size 256m
  </buffer>
  <format>
    @type json
  </format>
</match>
```

### 4단계. Fluentd를 설정 파일로 지정하고 검증

```
# fluentd를 설정 파일로 지정
fluentd -c /etc/td-agent/td-agent.conf

# 설정 검증
/opt/td-agent/usr/sbin/td-agent --dry-run
```

### 5단계. 로깅 확인

몇 분 후 이벤트가 S3 버킷에 기록되는지 확인하세요. 로그는 버킷 내 `macos/` 접두사 아래에 표시되어야 합니다.

## Panther 콘솔

### 1단계. 사용자 지정 스키마 생성

다음으로 이동하세요 **Configure > Schemas**. 클릭하세요 **+New Schema** 그런 다음 스키마 필드에 아래 값을 입력하세요:

**이름:** Custom.MacOSSystemLogs\
**설명:** 애플리케이션, 보안, 시스템용 MacOS 시스템 로그

```
version: 0
fields:
- name: pid
  type: bigint
- name: ppid
  type: bigint
- name: message
  type: string
- name: worker
  type: bigint
- name: creatorActivityID
  type: float
- name: messageType
  type: string
- name: activityIdentifier
  type: bigint
- name: backtrace
  type: object
  fields:
  - name: frames
    required: true
    type: array
    element:
      type: object
      fields:
      - name: imageOffset
        required: true
        type: bigint
      - name: imageUUID
        required: true
        type: string
- name: bootUUID
  type: string
- name: category
  type: string
- name: eventMessage
  type: string
- name: eventType
  type: string
- name: formatString
  type: string
- name: machTimestamp
  type: bigint
- name: parentActivityIdentifier
  type: bigint
- name: processID
  type: bigint
- name: processImagePath
  type: string
- name: processImageUUID
  type: string
- name: senderImagePath
  type: string
- name: senderImageUUID
  type: string
- name: senderProgramCounter
  type: bigint
- name: subsystem
  type: string
- name: threadID
  type: bigint
- name: timezoneName
  type: string
- name: traceID
  type: float
```

### 2단계. S3 버킷 온보딩 <a href="#step-2.-onboard-the-s3-bucket" id="step-2.-onboard-the-s3-bucket"></a>

다음을 따르세요 [S3 소스](/ko/data-onboarding/data-transports/aws/s3.md) 온보딩 문서를 참고하고 이전 설정에서 사용한 S3 버킷을 사용하세요.

로그 유형을 선택하고 `Custom.MacOSSystemLogs` 온보딩 단계에서 접두사를 `macos/` 지정하세요. 버킷 온보딩을 완료하면 데이터가 이제 Panther로 유입되기 시작해야 합니다!


---

# 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/macos-system-logs-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.
