위 링크 참조하여 설치는 간단히 진행할 수 있다.
이번 포스팅에서는 설치 후 필요한 설정을 하려고 한다.
configuration 부분에 대한 이해를 위해 최대한 설명하고 기록해야겠다.
<구성도>
log_format main '$host $logdate $logdate2 $scheme://$host$request_uri $bytes_sent $request_time $upstream_cache_status $status $remote_addr $http_user_agent $http_referer $upstream_addr $upstream_status $geoip_country_code $geoip_org $http_accept_encoding $body_bytes_sent $request_length $time_iso8601 $upstream_connect_time $upstream_header_time $upstream_response_time';
<conf 파일>
크게 6가지로 구분되어 있음.
<system>
root_dir /var/log/td-agent # For handling unrecoverable chunks
</system>
<source>
@type tail
path /logdata/access/*.com.log,/logdata/access/*.net.log,/logdata/access/*.kr.log
exclude_path ["/logdata/access/*.gz", "/logdata/access/*.zip" ]
pos_file /var/log/td-agent/nginx-access.log.pos
tag nginx.raw
refresh_interval 1s
<parse>
@type tsv
keys domain,date,time,url,sent,res,ret,status,cip,agent,referer,upip,up_status,geo,geoorg,encoding,length,reqlen,timestamp,up1,up2,up3
time_key timestamp
types sent:integer, res:float, reqlen:integer, up1:float, up2:float, up3:float
</parse>
</source>
<filter nginx.raw>
@type record_modifier
remove_keys date, time, encoding, length
<record>
host "#{Socket.gethostname}"
</record>
<replace>
key agent
expression /^$/
replace -
</replace>
<replace>
key referer
expression /^$/
replace -
</replace>
</filter>
<match nginx.*>
@type copy
<store>
@type relabel
@label @ERROR
</store>
<store>
@type relabel
@label @SAMPLING
</store>
</match>
<label @ERROR>
<match nginx.raw>
@type rewrite_tag_filter
capitalize_regex_backreference yes
<rule>
key status
pattern /^(4|5)\d{2}$/
tag nginx.error
</rule>
</match>
# <match **>
# @type stdout
# </match>
<match nginx.*>
@type forward
<server>
host xxx.xxx.xxx.xxx
port 24224
weight 60
</server>
<server>
host xxx.xxx.xxx.xxx
port 24224
weight 60
# standby
</server>
heartbeat_type transport
<buffer>
flush_interval 1
retry_wait 1 # The wait interval for the first retry.
retry_exponential_backoff_base 2 # Inclease the wait time by a factor of N.
retry_type exponential_backoff # Set 'periodic' for constant intervals.
retry_randomize true # Apply randomization. (see above)
retry_timeout 72h # Maximum duration before giving up.
retry_forever false # Set 'true' for infinite retry loops.
retry_secondary_threshold 0.8 # See the "Secondary Output" section in
</buffer>
<secondary>
@type file
path /var/log/td-agent/buffer/nginx.error
compress gzip
</secondary>
</match>
</label>
<label @SAMPLING>
<filter **>
@type sampling
interval 10
</filter>
# <match **>
# @type stdout
# </match>
<match nginx.*>
@type forward
<server>
host xxx.xxx.xxx.xxx
port 24224
weight 60
</server>
<server>
host xxx.xxx.xxx.xxx
port 24224
weight 60
# standby
</server>
heartbeat_type transport
<buffer>
flush_interval 1
retry_wait 1 # The wait interval for the first retry.
retry_exponential_backoff_base 2 # Inclease the wait time by a factor of N.
retry_type exponential_backoff # Set 'periodic' for constant intervals.
retry_randomize true # Apply randomization. (see above)
retry_timeout 72h # Maximum duration before giving up.
retry_forever false # Set 'true' for infinite retry loops.
retry_secondary_threshold 0.8 # See the "Secondary Output" section in
</buffer>
<secondary>
@type file
path /var/log/td-agent/buffer/nginx.sampled
compress gzip
</secondary>
</match>
</label>
<source> 부분
<source>
@type tail
path /logdata/access/*.com.log,/logdata/access/*.net.log,/logdata/access/*.kr.log
exclude_path ["/logdata/access/*.gz", "/logdata/access/*.zip" ]
pos_file /var/log/td-agent/nginx-access.log.pos
tag nginx.raw
refresh_interval 1s
<parse>
@type tsv
keys domain,date,time,url,sent,res,ret,status,cip,agent,referer,upip,up_status,geo,geoorg,encoding,length,reqlen,timestamp,up1,up2,up3
time_key timestamp
types sent:integer, res:float, reqlen:integer, up1:float, up2:float, up3:float
</parse>
</source>
- @type tail
tail 사용하여 log를 읽어 들여 동작 시작
- path <logfile path>
로그 파일 경로 설정
- exclude_path []
제외할 파일들 지정, 예를 들어 압축파일인 경우
path /path/to/*
exclude_path ["/path/to/*.gz", "/path/to/*.zip"]
- pos_file
fluentd가 여러 소스들을 pos_file 하나로 다루는 기능
나중에 pos_file을 통해 기록을 하게 된다.
- tag
tag 내용을 붙여서 파싱처리 함
- refresh_interval 60s (default)
path로 지정된 리스트 파일 읽는 주기 설정
- parse 부분
< filter 부분 >
<filter nginx.raw>
@type record_modifier
remove_keys date, time, encoding, length
<record>
host "#{Socket.gethostname}"
</record>
<replace>
key agent
expression /^$/
replace -
</replace>
<replace>
key referer
expression /^$/
replace -
</replace>
</filter>
- @type record_modifier
fluentd --dry-run -c fluent.conf
<plugin 설치>
td-agent-gem install fluent-plugin-sampling-filter
td-agent-gem install fluent-plugin-rewrite-tag-filter
Elasticsearch 개념정리 (0) | 2021.12.16 |
---|---|
리눅스 로그 관리 - Logrotate (0) | 2020.11.03 |
모니터링 시스템 Prometheus 설치 #2 (docker & grafana ) (0) | 2020.02.18 |
fluentd 설치 (CentOS 7) (0) | 2020.01.10 |
fluentd 설정 및 도커화 (CentOS 7) (0) | 2020.01.10 |
댓글 영역