본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Forward

원문 보기 위키 갱신

지원 이벤트 유형: logs metrics traces

Forward는 Fluentd가 피어 간에 메시지를 라우팅하기 위해 사용하는 프로토콜이에요. forward 출력 플러그인은 Fluent Bit와 Fluentd 사이의 상호 운용성을 제공해 줘요.

Fluentd가 어디에 있는지만 지정하면 되고, 추가 구성 단계는 없어요. 대상은 로컬이거나 원격일 수 있어요.

이 플러그인은 다음 전송 방식과 모드를 제공해요.

  • Forward (TCP): 일반 TCP 연결을 사용해요.
  • Secure Forward (TLS): TLS가 활성화되면 플러그인은 Secure Forward 모드로 전환돼요.

출처: 문서

본문

구성 파라미터

다음 파라미터는 Forward와 Secure Forward 두 모드 모두에서 필수예요.

Key Description Default
host Target host where Fluent Bit or Fluentd are listening for Forward messages. 127.0.0.1
port TCP port of the target service. 24224
time_as_integer Set timestamps in integer format. This enables compatibility mode for Fluentd v0.12. false
upstream If Forward connects to an upstream definition instead of a basic host, this property defines the absolute path for the upstream configuration file. See Upstream Servers. none
unix_path Specify the path to a Unix socket to send a Forward message. If set, upstream is ignored. none
tag Overwrite the tag as Fluent Bit transmits. This lets the receiving pipeline start fresh or attribute a source. none
send_options Always send Forward protocol options, including "size". false
require_ack_response Send the chunk option and wait for an ack response from the server. This enables at-least-once delivery and lets the receiving server control traffic rate. Requires Fluentd v0.14.0 or later. false
compress Set to gzip to enable gzip compression. Incompatible with time_as_integer true and tags set dynamically using the Rewrite Tag filter. Requires Fluentd server v0.14.7 or later. none
fluentd_compat Send metrics and traces using a Fluentd-compatible format. false
retain_metadata_in_forward_mode Retain metadata when operating in forward mode. Changed to true in v5.0.4. Set to false when sending to Fluentd. Fluentd doesn't support the extended metadata format and will log [input1] skip invalid event and drop all records. true
add_option Add an extra Forward protocol option. This is an advanced setting and can be specified multiple times. Enabling it also enables send_options. none
workers The number of workers to perform flush operations for this output. 2

Secure Forward 모드 구성 파라미터

Secure Forward 모드를 사용할 때는 TLS 모드가 활성화되어야 해요. 다음 추가 구성 파라미터를 사용할 수 있어요.

Key Description Default
shared_key A key string known by the remote Fluentd used for authorization. none
empty_shared_key Connect to Fluentd with a zero-length shared secret. false
username Specify the username to present to a Fluentd server that enables user_auth. Requires shared_key or empty_shared_key to be set, because credentials are exchanged only during the secure forward handshake. Otherwise, Fluent Bit fails to start. none
password Specify the password corresponding to the username. Requires shared_key or empty_shared_key, the same as username. none
self_hostname Default value of the auto-generated certificate common name (CN). localhost
tls Enable or disable TLS support. Off
tls.verify Force certificate validation. On
tls.debug Set TLS debug verbosity level. Allowed values: 0 (No debug), 1 (Error), 2 (State change), 3 (Informational), and 4 (Verbose). 1
tls.ca_file Absolute path to CA certificate file. none
tls.crl_file Absolute path to a Certificate Revocation List (CRL) file in PEM format. When set, revoked certificates are rejected during TLS verification. Supported in v5.1.3 or later. none
tls.crt_file Absolute path to Certificate file. none
tls.key_file Absolute path to private Key file. none
tls.key_passwd Optional password for tls.key_file. none
tls.windows.certstore_name (Windows only) Specify the name of the Windows Certificate Store to load certificates from. Root
tls.windows.use_enterprise_store (Windows only) Enable loading certificates from the Local Machine Enterprise Certificate Store. Off

Forward 설정

진행하기 전에 Fluentd가 설치되어 있는지 확인해요. 설치되어 있지 않다면 Fluentd 설치 문서를 참고해요.

Fluentd를 설치한 후, 데이터를 스트리밍할 수 있게 해 주는 다음 예시 설정 파일을 만들어요.

<source>
  type forward
  bind 0.0.0.0
  port 24224
</source>

<match fluent_bit>
  type stdout
</match>

이 설정 파일은 forward 입력 타입을 통해 포트 24224에서 TCP 연결을 수신 대기하도록 지정해요.

fluent_bit 태그를 가진 모든 메시지는 표준 출력으로 메시지를 출력해요.

한 터미널에서 새로 만든 설정 파일을 지정하며 Fluentd를 실행해요.

fluentd -c test.conf

다음과 유사한 응답을 반환해야 해요.

...
2017-03-23 11:50:43 -0600 [info]: reading config file path="test.conf"
...
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-mixin-config-placeholders' version '0.3.1'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-docker' version '0.1.0'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-elasticsearch' version '1.4.0'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-flatten-hash' version '0.2.0'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-flowcounter-simple' version '0.0.4'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-influxdb' version '0.2.8'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-json-in-json' version '0.1.4'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-mongo' version '0.7.10'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-out-http' version '0.1.3'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-parser' version '0.6.0'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-record-reformer' version '0.7.0'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '1.5.1'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-stdin' version '0.1.1'
2017-03-23 11:50:43 -0600 [info]: gem 'fluent-plugin-td' version '0.10.27'
2017-03-23 11:50:43 -0600 [info]: adding match pattern="fluent_bit" type="stdout"
2017-03-23 11:50:43 -0600 [info]: adding source type="forward"
2017-03-23 11:50:43 -0600 [info]: using configuration file: <ROOT>
  <source>
    type forward
    bind 0.0.0.0
    port 24224
  </source>
  <match fluent_bit>
    type stdout
  </match>
</ROOT>
2017-03-23 11:50:43 -0600 [info]: listening fluent socket on 0.0.0.0:24224
...

Fluent Bit와 Forward 설정

Fluentd가 메시지를 받을 준비가 되면, 다음 형식을 사용해 forward 출력 플러그인이 정보를 flush할 위치를 지정해요.

fluent-bit -i INPUT -o forward://HOST:PORT

tag 파라미터가 설정되지 않으면 플러그인은 태그를 유지해요. tag는 Fluentd 내부의 라우팅 규칙에 중요해요.

CPU 입력 플러그인을 예로 들어, cpu 메트릭을 fluent_bit 태그로 Fluentd에 flush할 수 있어요.

fluent-bit -i cpu -t fluent_bit -o forward://127.0.0.1:24224

Fluentd에서 지난 몇 초간 수집된 CPU 메트릭을 볼 수 있어요.

...
2017-03-23 11:53:06 -0600 fluent_bit: {"cpu_p":0.0,"user_p":0.0,"system_p":0.0,"cpu0.p_cpu":0.0,"cpu0.p_user":0.0,"cpu0.p_system":0.0,"cpu1.p_cpu":0.0,"cpu1.p_user":0.0,"cpu1.p_system":0.0,"cpu2.p_cpu":0.0,"cpu2.p_user":0.0,"cpu2.p_system":0.0,"cpu3.p_cpu":1.0,"cpu3.p_user":1.0,"cpu3.p_system":0.0}
2017-03-23 11:53:07 -0600 fluent_bit: {"cpu_p":2.25,"user_p":2.0,"system_p":0.25,"cpu0.p_cpu":3.0,"cpu0.p_user":3.0,"cpu0.p_system":0.0,"cpu1.p_cpu":1.0,"cpu1.p_user":1.0,"cpu1.p_system":0.0,"cpu2.p_cpu":1.0,"cpu2.p_user":1.0,"cpu2.p_system":0.0,"cpu3.p_cpu":3.0,"cpu3.p_user":2.0,"cpu3.p_system":1.0}
2017-03-23 11:53:08 -0600 fluent_bit: {"cpu_p":1.75,"user_p":1.0,"system_p":0.75,"cpu0.p_cpu":2.0,"cpu0.p_user":1.0,"cpu0.p_system":1.0,"cpu1.p_cpu":3.0,"cpu1.p_user":1.0,"cpu1.p_system":2.0,"cpu2.p_cpu":3.0,"cpu2.p_user":2.0,"cpu2.p_system":1.0,"cpu3.p_cpu":2.0,"cpu3.p_user":1.0,"cpu3.p_system":1.0}
2017-03-23 11:53:09 -0600 fluent_bit: {"cpu_p":4.75,"user_p":3.5,"system_p":1.25,"cpu0.p_cpu":4.0,"cpu0.p_user":3.0,"cpu0.p_system":1.0,"cpu1.p_cpu":5.0,"cpu1.p_user":4.0,"cpu1.p_system":1.0,"cpu2.p_cpu":3.0,"cpu2.p_user":2.0,"cpu2.p_system":1.0,"cpu3.p_cpu":5.0,"cpu3.p_user":4.0,"cpu3.p_system":1.0}
...

이것은 CPU 메트릭이 수집되어 Fluentd로 제대로 flush됐다는 것을 보여 줘요.

Fluent Bit와 Secure Forward 설정

다음 예시는 프로덕션 환경에서 모범 사례를 위한 인증서 생성을 고려하지 않아요.

Secure Forward는 TLS를 사용해 원격 Fluentd 서비스와의 안전한 통신 채널을 제공해요.

Fluent Bit

flb라는 파일에 이 내용을 붙여 넣어요.

flb.yaml:

service:
  flush: 5
  daemon: off
  log_level: info

pipeline:
  inputs:
    - name: cpu
      tag: cpu_usage

  outputs:
    - name: forward
      match: '*'
      host: 127.0.0.1
      port: 24284
      shared_key: secret
      self_hostname: flb.local
      tls: on
      tls.verify: off

flb.conf:

[SERVICE]
  Flush      5
  Daemon     off
  Log_Level  info

[INPUT]
  Name       cpu
  Tag        cpu_usage

[OUTPUT]
  Name          forward
  Match         *
  Host          127.0.0.1
  Port          24284
  Shared_Key    secret
  Self_Hostname flb.local
  Tls           on
  Tls.verify    off

Fluentd

fld.conf라는 파일에 이 내용을 붙여 넣어요.

<source>
  @type         secure_forward
  self_hostname myserver.local
  shared_key    secret
  secure no
</source>

<match **>
 @type stdout
</match>

통신 테스트

  1. Fluentd를 시작해요.

    fluentd -c fld.conf
    
  2. Fluent Bit를 시작해요.

    # For YAML configuration.
    fluent-bit --config flb.yaml
    
    # For classic configuration
    fluent-bit --config flb.conf
    

5초 후 Fluent Bit는 레코드를 Fluentd로 써요. Fluentd 출력에서 다음과 같은 메시지를 볼 수 있어요.

...
2017-03-23 13:34:40 -0600 [info]: using configuration file: <ROOT>
  <source>
    @type secure_forward
    self_hostname myserver.local
    shared_key xxxxxx
    secure no
  </source>
  <match **>
    @type stdout
  </match>
</ROOT>
2017-03-23 13:34:41 -0600 cpu_usage: {"cpu_p":1.0,"user_p":0.75,"system_p":0.25,"cpu0.p_cpu":1.0,"cpu0.p_user":1.0,"cpu0.p_system":0.0,"cpu1.p_cpu":2.0,"cpu1.p_user":1.0,"cpu1.p_system":1.0,"cpu2.p_cpu":1.0,"cpu2.p_user":1.0,"cpu2.p_system":0.0,"cpu3.p_cpu":2.0,"cpu3.p_user":1.0,"cpu3.p_system":1.0}
2017-03-23 13:34:42 -0600 cpu_usage: {"cpu_p":1.75,"user_p":1.75,"system_p":0.0,"cpu0.p_cpu":3.0,"cpu0.p_user":3.0,"cpu0.p_system":0.0,"cpu1.p_cpu":2.0,"cpu1.p_user":2.0,"cpu1.p_system":0.0,"cpu2.p_cpu":0.0,"cpu2.p_user":0.0,"cpu2.p_system":0.0,"cpu3.p_cpu":1.0,"cpu3.p_user":1.0,"cpu3.p_system":0.0}
2017-03-23 13:34:43 -0600 cpu_usage: {"cpu_p":1.75,"user_p":1.25,"system_p":0.5,"cpu0.p_cpu":3.0,"cpu0.p_user":3.0,"cpu0.p_system":0.0,"cpu1.p_cpu":2.0,"cpu1.p_user":2.0,"cpu1.p_system":0.0,"cpu2.p_cpu":0.0,"cpu2.p_user":0.0,"cpu2.p_system":0.0,"cpu3.p_cpu":1.0,"cpu3.p_user":0.0,"cpu3.p_system":1.0}
2017-03-23 13:34:44 -0600 cpu_usage: {"cpu_p":5.0,"user_p":3.25,"system_p":1.75,"cpu0.p_cpu":4.0,"cpu0.p_user":2.0,"cpu0.p_system":2.0,"cpu1.p_cpu":8.0,"cpu1.p_user":5.0,"cpu1.p_system":3.0,"cpu2.p_cpu":4.0,"cpu2.p_user":3.0,"cpu2.p_system":1.0,"cpu3.p_cpu":4.0,"cpu3.p_user":2.0,"cpu3.p_system":2.0}
...

더 알아보기 (Learn more)