Infrastructure/Fluentd

[Fluentd] 7. Nginx 연동

상쾌한기분 2021. 5. 11. 14:50
반응형

Nginx 로그 연동

개요

리눅스 서버에서 nginx의 access log 와 error log 를 수집하려고 한다.
우선, Nginx 는 날짜별로 파일 로그를 생성하고 날짜가 지나면 압축시켜 버린다.

그렇다면 Input 시에는 현재 작성하고 있는 파일에 접근해서 데이터를 수집해야 하기때문에
Input 플러그인은 tail 을 사용할 것이고 tail plugin은 access.log, error.log 를 대상으로 수집을 진행 할것이다.

또, Nginx 폴더에 그룹 권한이 admin으로 되어 있다. fluentd 를 adm 그룹으로 추가해주자.

# CentOS 7
$ gpasswd adm -a td-agent

연동

<source>
  @type tail
  @label @NGINX_LOG
  @id NGINX_ACCESS_LOG

  tag nginx.access
  path /var/log/nginx/access.log
  pos_file /var/log/td-agent/nginx-access.log.pos

  <parse>
    @type nginx
  </parse>
  @log_level debug
</source>

<source>
  @type tail
  @label @NGINX_LOG
  @id NGINX_ERROR_LOG

  tag nginx.error
  path /var/log/nginx/error.log
  pos_file /var/log/td-agent/nginx-error.log.pos

  <parse>
    @type nginx
  </parse>
  @log_level debug
</source>

테스트

<label @NGINX_LOG>
    <match nginx.**>
      @type stdout
      @id output_nginx
    </match>
</label>
728x90
반응형