Fluentd 설치방법 (서버에 설치, docker로 설치)

Fluentd 설치방법 (서버에 설치, docker로 설치)

Fluentd 설치 방법을 두가지 버전으로 나누어서 설명하도록 하겠습니다.

첫번째는 ubuntu 20.04 서버에 직접 설치하는 방법

두번째는 도커로 서버에 설치하는 방법입니다.

두가지 방법 중 편한 방법으로 사용하시면 됩니다.

 


1. 서버에 직접설치 방법

공식 문서에 따르면 Fluentd 를 설치하기 전에 권장사항을 따를 것을 권고합니다.

참고 : https://docs.fluentd.org/installation/before-install

  • NTP 설정 (NTP 데몬 설정, 정확한 현재 타임스탬프 설정)
  • 최대 File Descriptors 로 늘리기
  • 네트워크 커널 매개변수 최적화

1-1. File Descriptors 확인

$ ulimit -n
1024
  • 값이 1024인 경우, 아래 파일에 내용 추가
    • systemd 서비스 사용중인 os는 'LimitNOFILE=65536' 도 추가
$ vi /etc/security/limits.conf

root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536
  • 시스템 재부팅
$ sudo reboot
  • 변경내용 확인
$ ulimit -n
65536

1-2. 네트워크 커널 매개 변수 최적화

  • Fluentd 인스턴스가 많은 고부하의 환경에 사용
  • 아래 파일에 내용 추가
$ sudo vi /etc/sysctl.conf

net.core.somaxconn = 1024
net.core.netdev_max_backlog = 5000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_wmem = 4096 12582912 16777216
net.ipv4.tcp_rmem = 4096 12582912 16777216
net.ipv4.tcp_max_syn_backlog = 8096
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535

$ sudo sysctl -p

1-3. Fluentd 설치

  • 각 버전에 대한 설치 프로세스를 자동화하기 위해 Fluentd 설치 쉘 스크립트가 제공됨

참고 : https://docs.fluentd.org/installation/install-by-deb

curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-focal-td-agent4.sh | sh

1-4. Fluentd 실행

  • Fluentd 실행 후 실행되었는지 확인
    • stop, restart 명령어도 사용가능
$ systemctl start td-agent
$ systemctl status td-agent

1-5. 샘플 테스트

$ curl -X POST -d 'json={"json":"message"}' http://localhost:8888/debug.test

$ tail -n 1 /var/log/td-agent/td-agent.log
2021-08-30 11:09:50.308226287 +0000 debug.test: {"json":"message"}

1-6. Fluentd 파일 위치

  • Fluentd 설정파일
/etc/td-agent/td-agent.conf
  • Fluentd 로그 파일
/var/log/td-agent/td-agent.log

 


2. Docker로 Fluentd 설치 

Docker 는 깔려 있는 것을 전제로 Fluentd 를 설치하도록 하겠습니다.

참고 : https://docs.fluentd.org/container-deployment/install-by-docker

2-1. Fluentd Docker 이미지 pull

docker pull fluent/fluentd:edge-debian

2-2. Fluentd 설정파일 생성

$ mkdir tmp
$ cd tmp
$ vi fluentd.conf
<source>
  @type http
  port 9880
  bind 0.0.0.0
</source>

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

2-3. Fluentd Docker container 실행 및 테스트

$ sudo docker run -d --name fluentd -p 9880:9880 -v $(pwd)/tmp:/fluentd/etc fluent/fluentd:edge-debian -c /fluentd/etc/fluentd.conf

$ curl -X POST -d 'json={"json":"message"}' http://127.0.0.1:9880/sample.test

$ sudo docker logs -f fluentd
fluentd -c /fluentd/etc/fluentd.conf
2021-08-30 11:52:56 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/fluentd.conf"
2021-08-30 11:52:56 +0000 [info]: gem 'fluentd' version '1.14.0'
2021-08-30 11:52:56 +0000 [warn]: define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2021-08-30 11:52:56 +0000 [info]: using configuration file: <ROOT>
  <source>
    @type http
    port 9880
    bind "0.0.0.0"
  </source>
  <match **>
    @type stdout
  </match>
</ROOT>
2021-08-30 11:52:56 +0000 [info]: starting fluentd-1.14.0 pid=7 ruby="2.6.8"
2021-08-30 11:52:56 +0000 [info]: spawn command to main:  cmdline=["/usr/local/bin/ruby", "-Eascii-8bit:ascii-8bit", "/usr/local/bundle/bin/fluentd", "-c", "/fluentd/etc/fluentd.conf", "--plugin", "/fluentd/plugins", "--under-supervisor"]
2021-08-30 11:52:57 +0000 [info]: adding match pattern="**" type="stdout"
2021-08-30 11:52:57 +0000 [info]: adding source type="http"
2021-08-30 11:52:57 +0000 [warn]: #0 define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2021-08-30 11:52:57 +0000 [info]: #0 starting fluentd worker pid=16 ppid=7 worker=0
2021-08-30 11:52:57 +0000 [info]: #0 fluentd worker is now running worker=0
2021-08-30 11:52:57.457512925 +0000 fluent.info: {"pid":16,"ppid":7,"worker":0,"message":"starting fluentd worker pid=16 ppid=7 worker=0"}
2021-08-30 11:52:57.459779701 +0000 fluent.info: {"worker":0,"message":"fluentd worker is now running worker=0"}
2021-08-30 11:53:14.422464593 +0000 sample.test: {"json":"message"}

 

댓글

Designed by JB FACTORY