본문 바로가기

리눅스

[리눅스] Fluentd를 Docker 컨테이너로 실행하는 방법

반응형

Fluentd를 Docker 컨테이너로 실행하는 방법

Fluentd 컨테이너 실행

mkdir -p /fluentd/log
chown -R 999.999 /fluentd
docker run -d --name fluentd \
-p 24224:24224 \
-v /fluentd/log:/fluentd/log \
fluent/fluentd

Fluentd를 Docker Compose를 사용하여 컨테이너 실행

mkdir -p docker/config
mkdir -p fluentd/log
chown -R 999.999 fluentd

docker-compose.yml 파일 생성

vim docker-compose.yml
version: '3.8'
services:

  fluentd:
    build: ./docker
    image: anti1346/fluentd:v1.12-debian
    restart: unless-stopped
    container_name: fluentd
    hostname: fluentd
    volumes:
      - /usr/share/zoneinfo/Asia/Seoul:/etc/localtime:ro
      - ./docker/config/fluent.conf:/fluentd/etc/fluent.conf
      #- ./docker/config/fluent-es.conf:/fluentd/etc/fluent.conf
      - ./fluentd/plugins:/fluentd/plugins
      - ./fluentd/log:/fluentd/log
    #network_mode: host
    ports:
      - "8888:8888"
      - "24224:24224"
      - "24224:24224/udp"

Dockerfile 파일 생성

vim docker/Dockerfile
#docker/Dockerfile
FROM fluent/fluentd:v1.12-debian

USER root

RUN apt-get update \
 && apt-get install -y --no-install-recommends $buildDeps \
 && gem install fluent-plugin-elasticsearch \
 && gem sources --clear-all \
 && rm -rf /var/lib/apt/lists/* \
 && rm -rf /tmp/* /var/tmp/* /usr/lib/ruby/gems/*/cache/*.gem

USER fluent

fluent.conf 파일 생성

vim docker/config/fluent.conf
# fluentd/conf/fluent.conf
<source>
  @type  forward
  @id    input1
  @label @mainstream
  port  24224
</source>

<filter **>
  @type stdout
</filter>

<label @mainstream>
  <match docker.**>
    @type file
    @id   output_docker1
    path         /fluentd/log/docker.*.log
    symlink_path /fluentd/log/docker.log
    append       true
    time_slice_format %Y%m%d
    time_slice_wait   1m
    time_format       %Y%m%dT%H%M%S%z
  </match>
  <match **>
    @type file
    @id   output1
    path         /fluentd/log/data.*.log
    symlink_path /fluentd/log/data.log
    append       true
    time_slice_format %Y%m%d
    time_slice_wait   10m
    time_format       %Y%m%dT%H%M%S%z
  </match>
</label>
docker-compose up -d
728x90
반응형