IT/빅데이터

[BigData] EFK설치....(작성중)

louky 2017. 11. 14. 17:25
반응형

[EFK] Install ...

EFK의 정의/역활은 다른 블로그 또는 웹 사이트를 참고하기 바란다. 


필자 역시 웹사이트 및 블로그를 통해 설치하고 테스트를 해봤으나 부족한 부분 또는 제대로 이해되지 않는 부분이 많아서 별도로 정리하는 것이니.. 


설치 과정에 있어 간단할 줄 알았으나 이해가 되지 않으면 설치에 따른 오해가 발생할 것 같다. 

필자는 그러한 부분을 조금이라도 줄이기 위해 설치 과정을 조금 더 상세히 정리 하고자 한다. 


물론 잘못 된 설명이 있을수도 있으니 양해 바란다!! 

잘못된 부분이 있다면 댓글 부탁합니다.  ^^!!


구성 1 부터 순차적으로 따라하길 바란다. 물론 필요한 부분만 별도로 봐도 상관없다. 


============================================================


[ Info ]


1. 설치 System 환경 


OS      : CentOS Linux release 7.3.1611

System : 가상화 시스템 


2. 설치 버전 (작성 기준일 : 2017/11/14)


 PKG 구분

 Install version 

 Fluent(td-agent)

 td-agent 0.12.40

 Elasticsearch

 5.6.4

 Elasticsearch plugin

 1.5.0

 kibana

 5.6.4-1

 JDK

 1.8.0_151


3. 시스템 구성 


구성 1. Local system에 파일로 저장  

Stand alone setup fluent








[ Pre-work ] 

사전에 아래  PKG들이 설치 되어 있는지 확인하고 안되어 있을 경우 설치한다. 

# rpm -qa | grep -Ei "automake|libtool|gcc-c++|geoip-devel"
gcc-c++-4.8.5-16.el7.x86_64
libtool-2.4.2-22.el7_3.x86_64
GeoIP-devel-1.5.0-11.el7.x86_64
automake-1.13.4-3.el7.noarch 


설치가 안되어 있을 경우 yum command 를 이용하여 설치 한다. 

yum clean all 
yum install -y automake libtool gcc-c++ geoip-devel libcurl-devel 


kernel prameter를 변경하고 반영한다. 

# echo "net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535" >> /etc/sysctl.conf  

# sysctl -p
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535


ulimit -n 값이 1024라면 아래와 같이 반영하고 system reboot한다. reboot를 하지 못하는 경우 임시 반영한다.  

# ulimit -n  ##기본 설정 확인
1024
# echo "root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536" >> /etc/security/limits.conf   ## 영구 반영

#  ulimit -n 65536                   ##임시 반영
#  ulimit -n                              ## 반영/임시반영 확인
65536


[ Install ]


구성 1. Local system에 fluentd만 설치하여 별로도 log를 저장 하고자 할 경우 


: fluentd를 ruby언어로 되어 있는데 설치하고 운영하기가 복잡하여 td-agent라는 agent를 이용하여 fluentd를 실행하고 제어한다.

현재td-agent ver3까지 나와 있는 상태이나 베타 버전이기이 여기서는 ver2를 사용한다. 


아래 명령어를 이용하여 다운로드 하지 않고 바로 설치 한다. 

(download하여 script를 확인하고자 할 경우 wget명령어를 사용하여 download 한다.)



Install Command : fluentd

curl -L https://td-toolbelt.herokuapp.com/sh/install-redhat-td-agent2.sh | sh


설치 버전 확인

[root@logclient1 ]# td-agent --version
td-agent 0.12.40

실행/종료/상태확인

: td-agent config를 수정 했을 경우 꼭 daemon을 재시작한다.(auto load이 있는지 확인중!!) 

systemctl start td-agent
systemctl stop td-agent
systemctl restart td-agent
systemctl status td-agent

부팅시 자동 실행 등록/확인

systemctl enable td-agent        ## 부팅시 자동 실행 등록 /daemon기동 후 등록 한다.
systemctl is-enable td-agent    ## 부팅 자동 등록 여부 확인

td-agent log path

[root@logclient1 td-agent]# pwd
/var/log/td-agent


Config 설정 

 - Config file 경로  : /etc/td-agent/td-agent.conf 


config 설정은 크게 input/output/filter로 구분한다. 

input 설정은 source  부분에 output 설정은 match 부분에 하면 된다. 


config 설정 후 config 내 구문 이상여부를 아래와 같이 확인 할 수 있다. 


config 구문 확인 command

  usage)  td-agent -c config_file

 : 구문에 이상이 없을 경우 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 source type="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 source type="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초 간격으로 로그를 입력한다. 

# num=1 ; while true; do echo "echo \"test_${num}...\"" ; echo "test_${num}..." >> /tmp/test/testlog.log ; sleep 1 ; num=`expr $num + 1 ` ; done


case1-1. output 확인

 : output path를 설정하지 않았기에 td-agent 로그에 출력되어 해당 로그에 같이 저장 된다. 

[root@logclient1 ~]# tail -f /var/log/td-agent/td-agent.log
2017-11-15 10:38:03 +0900 testlog.log: {"message":"1 count..."}
2017-11-15 10:38:04 +0900 testlog.log: {"message":"2 count..."}
2017-11-15 10:38:05 +0900 testlog.log: {"message":"3 count..."}
2017-11-15 10:38:06 +0900 testlog.log: {"message":"4 count..."}
2017-11-15 10:38:07 +0900 testlog.log: {"message":"5 count..."}

  

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"형식이 붙여 실제 파일로 변경된다. 


예시 ) testlog.log.201711151023.b55dfb5830983fe91 -> testlog.log.201711151023_0.log

[root@logclient1 tmp]# tail -f  testlog.log.201711151023.b55dfb5830983fe91
20171115T102316+0900	testlog.log	{"message":"16 count..."}
20171115T102317+0900	testlog.log	{"message":"17 count..."}
20171115T102318+0900	testlog.log	{"message":"18 count..."}
20171115T102319+0900	testlog.log	{"message":"19 count..."}


구성 2. Remote system으로 log를 전송하고자 할 경우

 : 구성 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 설치

[Elasticsearch install 환경 설정]

# echo "[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md" > /etc/yum.repos.d/elasticsearch.repo

 [Elasticsearch install]

# rpm --import http://packages.elastic.co/GPG-KEY-elasticsearch
# yum -y install elasticsearch

[Elasticsearch plugin install] 

: fluentd용 elastcisearch plugin을 설치 한다. 필자의 경우 버전을 명시 하지않고 설치를 하니 td-agent version도 업그레이드가 되었다. 여기서는  버전을 명시하여 설치 한다. 

# /usr/sbin/td-agent-gem install fluent-plugin-elasticsearch -v 1.5.0

참고 !!!

fluentd 0.12.x버전에서 사용할 plugin version은  1.5.0 ~ 1.10.2까지 이고 그 이상을 사용할 경우  fluentd도 0.14.x로 업그레이드 된다. 

  •    fluent-plugin-elasticsearch version 관리 사이트 

[Kibana install 환경설정]

# echo " [kibana-5.x]
name=Kibana repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md " > /etc/yum.repos.d/kibana.repo

[Kibana install]

yum -y install kibana



설치 버전 확인


[Java version] 

# java -version
openjdk version "1.8.0_151"

JAVA설치 후 JAVA_HOME path가 설정이 되어 있는지 확인한다.

# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/j

안되어 있을 경우 아래방법으로 확인 후 등록 한다. 

 - "java -XshowSettings" 명령어를 실행하여 출력된 내용중 "java.home" field를 찾아 path값을 환경변수에 추가한다. 

# echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre" >> /etc/profile
source /etc/profile


[Elasticsearch version] 

[root@logsvr1 ~]# curl -XGET '172.16.1.32:9200'       ## number field가 ES version이다.
{
  "name" : "node-1",
  "cluster_name" : "uangelcluster",
  "cluster_uuid" : "mquxT9EPT4WB0eNTQDFiOw",
  "version" : {
    "number" : "5.6.4",
    "build_hash" : "8bbedf5",
    "build_date" : "2017-10-31T18:55:38.105Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}


[Elasticsearch plugin version] 

# /usr/sbin/td-agent-gem list | grep fluent-plugin-elasticsearch
fluent-plugin-elasticsearch (1.5.0)

[Kibana version] 

# rpm -qa | grep kibana 
kibana-5.6.4-1.x86_64 



실행/종료/상태확인


[Elasticsearch] 

systemctl start elasticsearch
systemctl stop elasticsearch
systemctl restart elasticsearch
systemctl status elasticsearch

[Kibana] 

systemctl start kibana
systemctl stop kibana
systemctl restart kibana
systemctl status kibana

부팅시 자동 실행 등록/확인

[Elasticsearch] 

systemctl enable elasticsearch        ## 부팅시 자동 실행 등록 /daemon기동 후 등록 한다.
systemctl is-enable elasticsearch    ## 부팅 자동 등록 여부 확인

[Kibana] 

systemctl enable kibana        ## 부팅시 자동 실행 등록 /daemon기동 후 등록 한다.
systemctl is-enable kibana    ## 부팅 자동 등록 여부 확인


log path

[Elasticsearch] 

: /etc/elasticsearch/elasticsearch.yml 에서 설정한 cluster name으로 로그파일이 생성된다. 

# pwd
/var/log/elasticsearch

[kibana] 

# pwd
/var/log/kibana
# ls -al
합계 36
drwxr-xr-x   2 kibana kibana    48 11월 16 13:38 .
drwxr-xr-x. 11 root   root    4096 11월 16 13:31 ..
-rw-r--r--   1 root   root       0 11월 16 13:31 kibana.stderr
-rw-r--r--   1 root   root   31755 11월 16 13:34 kibana.stdout


Config 설정 

 [Elasticsearch] 

Config file 경로  : /etc/elasticsearch/elasticsearch.yml 

  : 간단히 아래 설정만으로도 test는 가능하다. 다른 field는 주석하고 아래 내용만 활용한다. 

# cat elasticsearch.yml | grep -Ev "^#"
cluster.name: escluster
node.name: node-1
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["172.16.1.32:9300"]


[kibana] 

Config file 경로  : /etc/kibana/kibana.yml
# 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>  


Fluentd를 설정 후 deamon재시작을 한다. 

[root@logclient1 ~]# service td-agent restart


system log를 전송하기 위한 rsyslog 설정 추가 및 daemon 재시작

[root@logclient1 ~]# systemctl stop rsyslog.service 
[root@logclient1 ~]# echo "*.*                @127.0.0.1:5140" >> /etc/rsyslog.conf
[root@logclient1 ~]# systemctl start rsyslog.service


[Logserver config 설정]


Fluent 설정 

[root@logsvr1 ~]# vi /etc/td-agent/td-agent.conf
<source>
  type forward
  port 24224
  bind 0.0.0.0
</source>

<match **>
  type copy
  <store>
    type elasticsearch
    host 172.16.1.32
    port 9200
    index_name syslog
    type_name syslog

    logstash_format true
    logstash_prefix syslog
    logstash_dateformat %Y-%m-%d
    utc_index true
    time_key_format %Y-%m-%d %H:%M:%S.%N%z
    #flush_interval 1s
    reload_connections true
    reload_on_failure true
    reconnect_on_error true
  </store>
  <store>
    type stdout
  </store>
</match>
 


Fluentd를 설정 후 deamon재시작을 한다. 

[root@logsvr1 ~]# service td-agent restart


Fluentd 실행 후 Elasticsearch index가 생성 되었는지 확인한다. 

[root@logsvr1 ~]# curl -XGET '172.10.3.32:9200/_cat/indices?v'
health status index             uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   .kibana           1eiVynuXT0aWNIl9JWWWdw   1   1          2            0      6.5kb          6.5kb
yellow open   syslog-2017-11-17 D9NTAgnCT4y8_yDtzeQWnQ   5   1         97            0    172.7kb        172.7kb 


해당 index에 data가 추가되는지 확인한다.

: cli로 확인할 경우 JSON Format에 맞게 출력되는것이 아니라 일반 텍스트처럼 출력이 되기에 보기 어려울수도 있다. 이럴 경우python의 기본 툴로 JSON Format에 맞게 출력이 가능하다.


- 일반 출력  command

url -XGET '172.10.3.32:9200/syslog-2017-11-17/_search?size=1&q=*:*'

[root@logsvr1 ~]# curl -XGET '172.10.3.32:9200/syslog-2017-11-17/_search?size=1&q=*:*'
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":107,"max_score":1.0,"hits":[{"_index":"syslog-2017-11-17","_type":"syslog","_id":"AV_HnJKpWPP27jF-x-f5","_score":1.0,"_source":{"message":"Connection opened to Elasticsearch cluster => {:host=>\"172.16.1.32\", :port=>9200, :scheme=>\"http\"}","@timestamp":"2017-11-17T10:33:38+09:00"}}]}}


- JSON Format 출력 command 

 curl -XGET '172.10.3.32:9200/syslog-2017-11-17/_search?size=1&q=*:*' | python -m json.tool

"python -m json.tool" tool을 이용하면 JSON Format으로 변경하여 출력한다. 

(JSON tool 참고 사이트 => https://blog.outsider.ne.kr/1202)

[root@logsvr1 ~]# curl -XGET '172.10.3.32:9200/syslog-2017-11-17/_search?size=1&q=*:*' | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   392  100   392    0     0  39321      0 --:--:-- --:--:-- --:--:-- 43555
{
    "_shards": {
        "failed": 0,
        "skipped": 0,
        "successful": 5,
        "total": 5
    },
    "hits": {
        "hits": [
            {
                "_id": "AV_HnJKpWPP27jF-x-f5",
                "_index": "syslog-2017-11-17",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2017-11-17T10:33:38+09:00",
                    "message": "Connection opened to Elasticsearch cluster => {:host=>\"172.16.1.32\", :port=>9200, :scheme=>\"http\"}"
                },
                "_type": "syslog"
            }
        ],
        "max_score": 1.0,
        "total": 107
    },
    "timed_out": false,
    "took": 2
}



Kibana 웹 페이지에서 아래 순서에 맞춰 설정한다.  


kibana-step 1 : 웹페이지 접속

 URL : http://kibana_server_ip:5601


kibana-step 2 : index pattern 등록

: 여기서는 전송된 로그가 elasticsearch에 등록되는 index pattern을 등록 한다. index pattern은 아래와 같이 확인 가능하다


index pattern check

     

- index확인 command

   usage ) curl -XGET 'elasticsearch_svr_ip:port/_cat/indices?v'

# curl -XGET '172.10.3.32:9200/_cat/indices?v'


그림과 같이  index field의 이름 중  "syslog-2017-11-17" 과 같은 형식으로 "syslog-2017-11-18" "syslog-2017-11-19" 등이 있다면 여기서 index pattern은 "syslog-*"이다. 


참고 : 웹페이지에서 조회하고자 할 경우 => http://elasticsearch_svr_ip:port/_cat/indices?v


설정 

index pattern 등록 :  syslog*

Time Filter field name : @Timestamp

Expend index pattern ~~ : field check (체크하고 안하고의 차이점은 아직 모르겠음)




kibana-step 3 : index pattern 등록 상태 확인 


kibana-step 4 :  Discover 메뉴로 확인 (안보일 경우 웹페이지를 다시 접속한다.)





구성 4. Log server 이중화


설정중.......




반응형