티스토리 뷰

개요

  • 일반적으로 NGINXaccess_log, error_log는 라인 단위의 텍스트 형태로 출력한다. 오픈 소스 오브젝트 로깅 솔루션인 Graylog을 이용하여 해당 로그를 적재하면 오브젝트 단위로 검색이 용이하여 장애 발생시 문제 파악이 수월해진다. 이번 글에서는 Syslog UDP의 형태로 NGINX의 로그를 Graylog로 실시간 전송하는 방법을 정리하였다.

NGNIX Syslog Content Pack 설치

  • 개인 유저인 scriptingislife가 제작한 NGNIX Syslog Content Pack을 아래와 같이 설치한다. 설치가 완료되면 12401UDP 포트를 리스닝하는 Input가 자동 생성된다.
Graylog Web Interface → System → Content Packs
→ [Upload] 클릭
→ [파일 선택] 클릭
→ https://raw.githubusercontent.com/scriptingislife/graylog-content-pack-nginx-syslog/main/content_pack.json (입력)
→ [Upload] 클릭

nginx.conf 파일 작성

# access_log, error_log 설정 추가
$ sudo nano /usr/local/nginx/conf/nginx.conf
http {
    log_format graylog_json escape=json '{ "nginx_timestamp": "$time_iso8601", '
       '"remote_addr": "$remote_addr", '
       '"connection": "$connection", '
       '"connection_requests": $connection_requests, '
       '"pipe": "$pipe", '
       '"body_bytes_sent": $body_bytes_sent, '
       '"request_length": $request_length, '
       '"request_time": $request_time, '
       '"response_status": $status, '
       '"request": "$request", '
       '"request_method": "$request_method", '
       '"host": "$host", '
       '"upstream_cache_status": "$upstream_cache_status", '
       '"upstream_addr": "$upstream_addr", '
       '"http_x_forwarded_for": "$http_x_forwarded_for", '
       '"http_referrer": "$http_referer", '
       '"http_user_agent": "$http_user_agent", '
       '"http_version": "$server_protocol", '
       '"remote_user": "$remote_user", '
       '"http_x_forwarded_proto": "$http_x_forwarded_proto", '
       '"upstream_response_time": "$upstream_response_time", '
       '"nginx_access": true }';
    server {
        access_log syslog:server={graylog-host}:12401 graylog_json;
        error_log syslog:server={graylog-host}:12401 debug;
    }
}

# nginx.conf 문법 검사
$ sudo /usr/sbin/nginx -t

# NGINX 재시작
$ sudo /usr/sbin/nginx -s reload

참고 글

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함