fluentd 의 설정에 대해 사용법에 대해 간단하게 적어보았습니다.
fluentd 홈페이지로 가면 더욱 많은 자료를 얻을수 있으며,
이 포스팅은 Shinohara 님의
의 글을 참고하여 작성하였습니다.
설정파일의 요소
설정파일은 source, match, include 이 세가지 요소를 구성되어있다.
source 디렉티브
로그의 입력 방법을 정한다.
기본으로 쓸수있는것은 표준입력, 파일, 포트지정한 HTTP 통신 등이 있음
match 디렉티브
여기서 매칭된 로그로 지정한 처리가 적용된다.
기본적으로 사용할수 있는것은, 표준 출력, 파일, 다른 fluent서버로 전송,
이 방법들을 조합한 방식 등이 있다.
include 디렉티브
복수의 설정파일을 설정하는것이 가능하다.
(/etc/log/httpd/conf.d/*.conf 등)
* tag
로그를 지정하는 ID(Key) 에 상당하는것이다.
match 디렉티브로 저장한 debug.test 등이 태그예가 된다.
설정 방법
match 디렉티브는 최초에 매칭된것에만 적용된다.
로그의 출력쪽이 복수일 경우의 설정방법은 하기를 참고한다.
표준 입력 -> 표준 출력
match 디렉티브에서 debug.** 을 지정해놓았기에, debug.aaa 도 매칭되게 된다.
(
정규표현식을 사용하여 적용할수도 있다.
* match 디렉티브에 사용할수 있는 정규표현식은 공식사이트를 참고할수도 있다.
)
설정
<source> type forward </source> <match debug.**> type stdout </match>
명령
# 설정파일을 지정하여 기동 $ fluentd -c ./fluent/fluent.conf -vv & # 표준출력으로 결과가 표시된다. $ echo '{"json":"is a message "}' | fluent-cat debug.test
표준입력 -> 파일
설정
<source> type forward </source> <match apache.access> type file path /var/log/fluent/access </match>
명령
# 설정파일을 지정하여 기동 $ fluentd -c ./fluent/fluent.conf -vv & # 표준출력으로 결과가 표시된다. $ echo '{"json":"is a message "}' | fluent-cat apache.access
엑세스 로그 -> 파일
설정
<source> type tail format apache path /var/log/httpd-access.log tag apache.access </source> <match apache.access> type file path /var/log/fluent/access </match>
명령
# 설정파일을 지정하여 기동 $ fluentd -c ./fluent/fluent.conf -vv & # 엑세스로그를 거쳐서, 지정한 파일에 결과를 표시한다. $ curl http://localhost/index.html -F 'json={"log":"is a test"}'
특정 포트의 HTTP 통신 -> 파일
이 경우 8888포트는 fluentd가 Listen하게 되므로, 8888포트는 미사용상태이어야 한다.
설정
# http://localhost:8888/<tag>?json=<json> <source> type http port 8888 </source> <match index.html> type file path /var/log/fluent/access </match>
명령
# 설정파일을 지정하여 기동 $ fluentd -c ./fluent/fluent.conf -vv & # 지정한 파일에 결과가 표시된다. 이 경우 index.html 태그에 걸린다. $ curl http://localhost:8888/index.html -F 'json={"log":"is a test"}' # 이 경우는 aaa.index.html태그에 걸린다. $ curl http://localhost:8888/aaa/index.html -F 'json={"log":"is a test"}'
고도화된 설정
로그의 수집을 담당하는 별도의 fluentd 서버로 로그를 전송
로그 전송측의 fluentd 설정파일
<match mytag.**> type forward # primary host <server> host 192.168.0.1 port 24224 </server> # use secondary host <server> host 192.168.0.2 port 24224 standby </server> # use longer flush_interval to reduce CPU usage. # note that this is a trade-off against latency. flush_interval 60s </match>
로그를 받아주는 측의 fluentd 의 설정파일
# Input <source> type forward port 24224 </source> # Output <match mytag.**> ... </match>
복수의 출력을 설정
<match myapp.**> type copy # 표준출력 <store> type stdout </store> # 파일 <store> type file path /var/log/fluent/myapp </store> # 다른 fluentd 서버로 출력 <store> type forward host 192.168.0.13 buffer_type file buffer_path /var/log/fluent/myapp-forward retry_limit 50 flush_interval 10s </store> </match>
그 외의 출력방법
# fluent 내부 이벤트로그를 출력 <match fluent.**> type null </match>
# 매칭되지 않은 로그를 지정하여 파일로 저장(압축하여). <match **> type file path /var/log/fluent/else compress gz </match>
참고
ace-t
•8년 ago
정리가 깔끔하네요! 좋은 정보 감사합니다.
blog-admin
•8년 ago
도움이 되어서 기쁩니다 ^^