And Brain said,
Fluentd & Fluentbit, 인프라를 밝히기 위한 야간비행 본문
Infrastructure를 밝히기 위해 뒤에서 묵묵히 자신들의 일을 하는 Fluentd와 나아가 Fluentbit를 구축해보겠습니다.
기존 ELK Stack에 대해서 알고계신다면, 이 둘의 역할은 각각 Logstash와 Filebeat의 역할이라고 이해하시면 될 것 같습니다.
환경은 Ubuntu 22.04이고, 서버가 분리되어 있는 상태기 때문에 Fluentbit를 통해 애플리케이션 서버의 로그를 인프라 시스템 서버의 Fluentd로 보낼 것입니다.
먼저, 둘 중 더 간단한 Fluentbit부터 설치해봅시다.
curl https://raw.githubusercontent.com/fluent/fluent-bit/master/install.sh | sh
이렇게 간단히 설치를 하면 서버 내 /etc/fluent-bit/fluent-bit.conf 에서 Fluentbit 설정을 할 수 있습니다.
[SERVICE]
# Flush
# =====
# set an interval of seconds before to flush records to a destination
flush 20
# Daemon
# ======
# instruct Fluent Bit to run in foreground or background mode.
daemon Off
# Log_Level
# =========
# Set the verbosity level of the service, values can be:
#
# - error
# - warning
# - info
# - debug
# - trace
#
# by default 'info' is set, that means it includes 'error' and 'warning'.
log_level info
log_file /var/log/fluent-bit/logfile.log
# Parsers File
# ============
# specify an optional 'Parsers' configuration file
parsers_file parsers.conf
# Plugins File
# ============
# specify an optional 'Plugins' configuration file to load external plugins.
plugins_file plugins.conf
# HTTP Server
# ===========
# Enable/Disable the built-in HTTP Server for metrics
http_server Off
http_listen 0.0.0.0
http_port 2020
# Storage
# =======
# Fluent Bit can use memory and filesystem buffering based mechanisms
#
# - https://docs.fluentbit.io/manual/administration/buffering-and-storage
#
# storage metrics
# ---------------
# publish storage pipeline metrics in '/api/v1/storage'. The metrics are
# exported only if the 'http_server' option is enabled.
#
storage.metrics on
# storage.path
# ------------
# absolute file system path to store filesystem data buffers (chunks).
#
# storage.path /tmp/storage
# storage.sync
# ------------
# configure the synchronization mode used to store the data into the
# filesystem. It can take the values normal or full.
#
# storage.sync normal
# storage.checksum
# ----------------
# enable the data integrity check when writing and reading data from the
# filesystem. The storage layer uses the CRC32 algorithm.
#
# storage.checksum off
# storage.backlog.mem_limit
# -------------------------
# if storage.path is set, Fluent Bit will look for data chunks that were
# not delivered and are still in the storage layer, these are called
# backlog data. This option configure a hint of maximum value of memory
# to use when processing these records.
#
# storage.backlog.mem_limit 5M
[INPUT]
name tail
path /var/log/application/user-service/*.log
tag user-service-log
[INPUT]
name tail
path /var/log/application/board-service/*.log
tag board-service-log
[INPUT]
name tail
path /var/log/application/portal-service/*.log
tag portal-service-log
[OUTPUT]
name forward
match *
host InfraIP
port FluentdPort
[OUTPUT] 영역에서 host 와 port를 각각 인프라 서버 IP와 Fluentd Port로 맞춰줍시다.
이번엔, Fluentd를 구축할 것인데 현재 2023년 7월 31일 기준, Fluentd가 Ubuntu 22.04 를 공식적으로 지원하지 않고 있기에 Docker를 이용해서 구축할 것입니다.
이렇게 원하는 디렉토리 내에 DockerFile과 compose yml 과 fluentd 디렉토리를 각각 만들어줍니다.
fluentd 디렉토리 내에는 또한 conf 폴더와 log 폴더도 만들어준 후, 돌아와서
docker-compose.yml
DockerFile
저는 코어를 엘라스틱서치로 가져갈 것이기에 elasticsearch 플러그인까지 설치했습니다. 여러 플러그인들이 많으니 찾아보시길 바랍니다.
이렇게 conf 파일까지 작성했다면 컴포즈 파일이 있는 디렉토리에서 docker-compose up 명령어를 치면 끝.
이런 식으로 뜬다면 끝.