: 구문에 이상이 없을 경우 check 바로 종료 되나 port listen상태에따라 대기 상태가 될수도 있는데 이때는 ctrl+c를 눌러 종료 한다.
# td-agent -c /etc/td-agent/td-agent.conf
2017-11-14 09:54:06 +0900 [info]: reading config file path="/etc/td-agent/td-agent.conf"
2017-11-14 09:54:06 +0900 [info]: starting fluentd-0.12.40
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-mixin-plaintextformatter' version '0.2.6'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-kafka' version '0.6.1'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-mongo' version '0.8.1'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '1.5.6'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-s3' version '0.8.5'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-scribe' version '0.10.14'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-td' version '0.10.29'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-td-monitoring' version '0.2.3'
2017-11-14 09:54:06 +0900 [info]: gem 'fluent-plugin-webhdfs' version '0.7.1'
2017-11-14 09:54:06 +0900 [info]: gem 'fluentd' version '0.12.40'
2017-11-14 09:54:06 +0900 [info]: adding match pattern="pattern"type="file"
2017-11-14 09:54:06 +0900 [info]: adding sourcetype="forward"
2017-11-14 09:54:06 +0900 [info]: using configuration file:
@type file
path /root/test/messages
time_slice_format %Y%m%d
time_slice_wait 10m
time_format %Y%m%dT%H%M%S%z
utc
buffer_path /root/test/messages.*
@type forward
port 24224
bind 0.0.0.0
2017-11-14 09:54:06 +0900 [info]: listening fluent socket on 0.0.0.0:24224
실패 할 경우 "exit"를 출력하면서 종료 되며 실행 결과는 아래와 같다.
# td-agent -c /etc/td-agent/td-agent.conf
2017-11-14 09:35:58 +0900 [info]: reading config file path="/etc/td-agent/td-agent.conf"
2017-11-14 09:35:58 +0900 [info]: starting fluentd-0.12.40
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-mixin-plaintextformatter' version '0.2.6'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-kafka' version '0.6.1'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-mongo' version '0.8.1'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '1.5.6'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-s3' version '0.8.5'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-scribe' version '0.10.14'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-td' version '0.10.29'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-td-monitoring' version '0.2.3'
2017-11-14 09:35:58 +0900 [info]: gem 'fluent-plugin-webhdfs' version '0.7.1'
2017-11-14 09:35:58 +0900 [info]: gem 'fluentd' version '0.12.40'
2017-11-14 09:35:58 +0900 [info]: adding sourcetype="syslog"
2017-11-14 09:35:58 +0900 [error]: config error in:
<source>
@type syslog
port 514
</source>
2017-11-14 09:35:58 +0900 [error]: config error file="/etc/td-agent/td-agent.conf" error="'tag' parameter is required"
2017-11-14 09:35:58 +0900 [info]: process finished code=256
2017-11-14 09:35:58 +0900 [warn]: process died within 1 second. exit.
case1-1.local system내 특정 Log 파일을 읽어 default 저장소인 "/var/log/td-agent/td-agent.log" 에 저장
설정해 놓은 저장 위치에 권한을 꼭 설정한다.
# chown -R td-agent save_path
디렉토리 별로 권한을 설정하기 귀찮을 경우 root 권한으로 실행 되도록 설정을 한다.
[root@logclient1 ]# cat /etc/td-agent/td-agent.conf## INPUT 설정
<source>
type tail ## 파일을 내용 감시 패턴 타입 지정
format none ## 파일의 format type을 설정 하는 곳으로 system/apache/json등 정해져 있는 것이 아니라면 "none"으로 설정 한다.
path /tmp/test/*.log## fluentd가 참조하고 있을 파일의 경로 및 파일 이름을 명시한다.
pos_file /tmp/test/testlog.pos ## 파일의 position 관리/ 마지막으로 전송한 위치를 저장 (이 설정이 없으면, 네트워크 이슈 발생 시 파일이 중복 전송되거나 잘려서 전송될 수 있으므로, 파일 내용의 정합성이 깨질 수 있다.)
tag testlog.log ## 식별자 지정으로 아래 match field부분에서 활용된다. 설정하지 않아도 된다.
</source>
##OUTPUT 설정
<match **>
type stdout ## 표준 출력으로 input 내용을 default인 "var/log/td-agent/td-agent.log" 저장한다.
</match>
config 변경후에는 td-agent daemon을 재기동한다.
case1-1. Test log 작성
: 아래와 같이 console 입력하면 ctrl+c를 누르기 전까지 해당 로그파일에 1초 간격으로 로그를 입력한다.
case1-2. local system내 특정 Log 파일을 읽어 user 지정인 "/tmp/testlog.log" 에 저장
[root@logclient1 ]# cat /etc/td-agent/td-agent.conf##INPUT 설정
<source>
type tail ## 파일을 내용 감시 패턴 타입 지정
format none ## 파일의 format type을 설정 하는 곳으로 system/apache/json등 정해져 있는 것이 아니라면 "none"으로 설정 한다.
path /tmp/test/*.log## fluentd가 참조하고 있을 파일의 경로 및 파일 이름을 명시한다.
pos_file /tmp/test/testlog.pos ## 파일의 position 관리/ 마지막으로 전송한 위치를 저장 (이 설정이 없으면, 네트워크 이슈 발생 시 파일이 중복 전송되거나 잘려서 전송될 수 있으므로, 파일 내용의 정합성이 깨질 수 있다.)
tag testlog.log ## 식별자 지정으로 아래 match field부분에서 활용된다. 설정하지 않아도 된다.
</source>
##OUTPUT 설정
<match **>
type file ## output type을 설정하는 것으로 Local 서버로 input 된 내용을 저장할때 사용한다
path /tmp/testlog.log ## 저장할때의 파일명으로 아래 "time_slice_format" type과 결합하여 파일이 명이 생성된다. ex) /tmp/testlog.log.201711141920
time_slice_format %Y%m%d%H%M ## 위 path의 파일명 뒤에 추가적으로 붙이는 날짜 포맷이다. 월/일/시/분 단위로 파일이 생성된다.
time_slice_wait 10m ## 파일이 전송되고 기다리는 시간으로 임시파일이 실제 파일명으로 변경되기 까지의 소요시간이다.ex) /tmp/testlog.log.201711141920.b55deebb706bc7884 -> /tmp/testlog.log.201711141920_0.log
time_format %Y%m%dT%H%M%S%z ## 저장되는 파일 내용 앞에 추가되는 시간 포맷이다.
</match>
case1-2. output 확인
: output 확인은 임시 파일로 확인을 하고 임시파일은 write가 완료되고 난 후 "time_slice_wait" 로 설정된 시간 만큼 기다린 후 임시파일은 삭제되고 "path" field에 명시된 경로 및 파일명 뒤에 "time_slice_format"형식이 붙여 실제 파일로 변경된다.
: 구성 1과 동일한 방법으로 logclient와 logserver에 fluentd를 설치하고 config 설정만 구분한다.
log client = log 전송
log server = log 수신
[Logclient config 설정]
[root@logclient1 ]# cat /etc/td-agent/td-agent.conf##INPUT 설정
<source>
type tail ## 파일을 내용 감시 패턴 타입 지정
format none ## 파일의 format type을 설정 하는 곳으로 system/apache/json등 정해져 있는 것이 아니라면 "none"으로 설정 한다.
path /tmp/test/*.log## fluentd가 참조하고 있을 파일의 경로 및 파일 이름을 명시한다.
pos_file /tmp/test/testlog.pos ## 파일의 position 관리/ 마지막으로 전송한 위치를 저장 (이 설정이 없으면, 네트워크 이슈 발생 시 파일이 중복 전송되거나 잘려서 전송될 수 있으므로, 파일 내용의 정합성이 깨질 수 있다.)
tag testlog.log ## 식별자 지정으로 아래 match field부분에서 활용된다. 설정하지 않아도 된다.
</source>
##OUTPUT 설정
<match **>
type forward ## output type을 설정하는 것으로 다른 서버로 input 된 내용을 전달할때 사용한다.
flush_interval 2s ## 전송 주기 설정으로 2초 간격으로 다른 서버로 전송한다.
<server>
host 172.16.4.95 ## Remote server IP주소 또는 hostname을 입력한다.(hostname등록시 /etc/hosts 또는 dos 쿼리가 되어야 한다.)
port 24224 ## remote 전송에 사용할 service port를 입력한다.
</server>
</match>
[Logserver config 설정]
[root@logsvr1 ]# cat /etc/td-agent/td-agent.conf
<source>
type forward ## 원격지에 보내는 받는 type으로 forward를 사용한다.
port 24224 ## 원격지에서 보낼 port로 설정 한다. (client/server 동일하게 설정한다.)bind 0.0.0.0 ## bind할 IP를 입력한다. 여기서는 cloud 환경이기에 net-all로 설정한다.
tag testlog.log
</source>
<match **>
type file
path /tmp/testlog.log
time_slice_format %Y%m%d%H%M
time_slice_wait 1m
time_format %Y%m%dT%H%M%S%z
</match>
output 확인은 구성1을 참고 한다.
구성 3. EFK (Fluentd + Elasticsearch + Kibana)
Install Command : java + elasticsearch + Kibana
: elasticsearch를 사용하기 위해서는 java를 우선 설치하고 그 다음에 elasticsearch를 설치한다. 여기서는 Elasticsearch 및 kibana는 logserver에 설치한다.
[java install]
# yum install -y java-1.8.0-openjdk-devel.x86_64 ## java 설치
# cat kibana.yml | grep -Ev "^#"
server.port: 5601 ## kibana service port (WEB 접속 포트)
server.host: "172.16.1.32"## 접속할 IP
elasticsearch.url: "http://172.16.1.32:9200"## elasticsearch server주소
동작확인
[Elasticsearch]
# systemctl start elasticsearch ##deamon 실행# curl -XGET '172.16.1.32:9200' ## ES query를 하여 출력 여부 확인 # netstat -nap | grep -E "9200|9300" ## Service port listen 상태 확인
tcp6 0 0 :::9200 :::* LISTEN 4770/java
tcp6 0 0 :::9300 :::* LISTEN 4770/java
[Kibana]
# systemctl start kibana ##deamon 실행# netstat -nap | grep 5601 ## Service port listen 상태 확인
tcp 0 0 172.16.1.32:5601 0.0.0.0:* LISTEN 6540/node
웹 브라우저를 열어 kiban에 접속되는지 확인한다.
case3-1. 테스트 환경 - systemlog 전송을 위한 설정 (messages, secure 등)
[Logclient config 설정]
Fluent 설정
[root@logclient1 ~]# vi /etc/td-agent/td-agent.conf
<source>
type syslog
port 5140
bind 127.0.0.1
tag system
</source>
<match **>
type copy
<store>
type forward
send_timeout 10s
recover_wait 10s
flush_interval 2s
<server>
name logsvr1
host 172.16.1.32 ## logsvr ip
port 24224 ##logsvr로 전송할 port
</server>
</store>
<store>
type stdout ## Client local 서버에 표준 저장(실제 서비스 할때에는 사용하지 않는다.)
</store>
</match>