티스토리 뷰

데이터 원천을 아래의 사이트에서 확인 가능함

https://gist.github.com/rm-hull/bd60aed44024e9986e3c

추가 사이트 

http://ita.ee.lbl.gov/html/contrib/NASA-HTTP.html

http://www.almhuette-raith.at/apache-log/access.log

http://ita.ee.lbl.gov/html/traces.html

https://www.google.co.uk/search?q=inurl:access.log+filetype:log


1. NASA 접속 이력 파일 받기

http://ita.ee.lbl.gov/html/contrib/NASA-HTTP.html

파일명 : NASA_access_log_Jul95.gz


2. ELKR 가상 머신에 파일 압축 풀기

[zedo@elkr work]$ pwd

/home/zedo/work

[zedo@elkr work]$ gunzip  NASA_access_log_Jul95.gz

zedo@elkr work]$ tail -3  NASA_access_log_Jul95

199.0.2.27 - - [28/Jul/1995:13:32:23 -0400] "GET /images/ksclogo-medium.gif HTTP/1.0" 200 5866

tornado.umd.edu - - [28/Jul/1995:13:32:25 -0400] "GET /shuttle/missions/sts-74/sts-74-patch-small.gif HTTP/1.0" 200 5494


3. FileBeat 설정

[zedo@elkr work]$ vi /home/zedo/work/filebeat-6.4.2-linux-x86_64/filebeat.yml

filebeat.prospectors:

- input_type: log

  paths:

    - /home/zedo/work/NASA_access_log_Jul95

output.logstash:

  hosts: ["localhost:5043"]  

  

  

4. logstash에서 Filebeat의 입력을 받기 위해 설정

/home/zedo/work/logstash-6.4.1/config/nasa.config

input {

  beats {

    port => "5043"

  }

}

filter {

  grok {

    match => {

      message => "%{IP:clientIp} (?:-|) (?:-|) \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:httpMethod} %{URIPATH:uri}%{GREEDYDATA}(?: HTTP/%{NUMBER})?|-)\" %{NUMBER:responseCode} (?:-|%{NUMBER:responseBytes})"

    }

  }

  geoip {

    source => "clientip"

  }

}

output {

  elasticsearch { hosts => ["localhost:9200"] }

  #  stdout { codec => rubydebug }

}


-----------------

11월 25일 1차

위의 구성으로 진행할 경우 geoip가 미생성되어 map 생성 불가함, 아래와 같이 변경하여 진행함

input {

  beats {

    port => "5043"

  }

}

filter {

   grok {

       match => { "message" => "%{COMBINEDAPACHELOG}"}

   }

   geoip {

       source => "clientip"

   }

}

output {

  elasticsearch { hosts => ["localhost:9200"] }

  #  stdout { codec => rubydebug }

}


-----------------

11월 25일 2차

위의 구성으로 진행할 경우 geoip가 미생성되어 map 생성 불가함, 아래와 같이 변경하여 진행함

input {

  file {

    path => "/home/zedo/work/NASA_access_log_Jul95"

    start_position => "beginning"

  }

}

filter {

   grok {

       match => { "message" => "%{COMBINEDAPACHELOG}"}

   }

   date {

       match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]

   }   

   geoip {

       source => "clientip"

   }

}

output {

  elasticsearch { hosts => ["localhost:9200"] }

  #  stdout { codec => rubydebug }

}

-----------------

11월 25일 3차

위의 구성으로 진행할 경우 geoip가 미생성되어 map 생성 불가함, 아래와 같이 변경하여 진행함

input {

  beats {

    port => "5043"

  }

}

filter {

  grok {

    match => {

      message => "%{IPORHOST:clientip} (?:-|) (?:-|) \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:httpMethod} %{URIPATH:uri}%{GREEDYDATA}(?: HTTP/%{NUMBER})?|-)\" %{NUMBER:responseCode} (?:-|%{NUMBER:responseBytes})"

    }

  }

   date {

       match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]

   }   

   geoip {

       source => "clientip"

   }

   mutate {

      remove_field => ["@version", "offset", "input_type", "source", "type", "tags", "name", "beat"]

   }

}

output {

  elasticsearch { hosts => ["localhost:9200"] }

  #  stdout { codec => rubydebug }

}

-----------------

11월 25일 4차

위의 구성으로 진행할 경우 geoip가 미생성되어 map 생성 불가함, 아래와 같이 변경하여 진행함

input {

  file {

    path => "/home/zedo/work/NASA_access_log_Jul95"

    start_position => "beginning"

    sincedb_path => "/dev/null"

  }

}

filter {

  grok {

    match => {

      message => "%{IPORHOST:clientip} (?:-|) (?:-|) \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:httpMethod} %{URIPATH:uri}%{GREEDYDATA}(?: HTTP/%{NUMBER})?|-)\" %{NUMBER:responseCode} (?:-|%{NUMBER:responseBytes})"

    }

  }

   date {

       match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]

   }   

   geoip {

       source => "clientip"

   }

}

output {

  elasticsearch { hosts => ["localhost:9200"] }

  #  stdout { codec => rubydebug }

}



5. logstash의 기동

1) config 파일 정상 유무 확인

[zedo@elkr logstash-6.4.1]$ bin/logstash -f config/nasa.conf --config.test_and_exit

Sending Logstash logs to /home/zedo/work/logstash-6.4.1/logs which is now configured via log4j2.properties

[2018-11-24T14:24:17,795][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified

Configuration OK

[2018-11-24T14:24:20,373][INFO ][logstash.runner          ] Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash


2) conf 파일 변경시 마다 매번 logstash 재시작 업도록 시작함

* --config.reload.automatic 옵션은 conf 파일 수정시마다 logstash를 재시작할 필요없이 반영할 수 있도록 함

[zedo@elkr logstash-6.4.1]$ bin/logstash -f config/nasa.conf --config.reload.automatic


6. Filebeat의 구동

* filebeat에서 로그 자료 재전송을 하고 싶으면(예를 들면 conf 수정 후 logstash 재시작) filebeat 프로세스 중지 후에 "registry" 파일 삭제 필요  

you do need to force Filebeat to read the log file from scratch. To do this, 

go to the terminal window where Filebeat is running and press Ctrl+C to shut down Filebeat. Then delete the Filebeat registry file.

[zedo@elkr filebeat-6.4.2-linux-x86_64]$ rm data/registry

1) filebeat의 구동

[zedo@elkr filebeat-6.4.2-linux-x86_64]$ ./filebeat -e -c filebeat.yml -d "publish"


7. Elasticsearch에서 확인

[zedo@elkr work]$ curl -XGET 'localhost:9200/_cat/indices/logstash-2018.11.24'

[zedo@elkr work]$ curl -XGET 'localhost:9200/logstash-2018.11.24/_search?pretty&q=response=200'

[zedo@elkr work]$ curl -XGET 'localhost:9200/logstash-2018.10.28/_search?pretty&q=geoip.city_name=Buffalo'


8. kibana를 통한 가시화 수행

1) Kibana Index pattern

- Kibana > Management > Kibana > Index Patterns > Create index pattern > logstash-2018.11.24

- Index pattern : timestamp


2) Coordinate Map

kibana > Visualization > Maps > Coordinate map > "logstash*" 데이터 셑 선택함

  . 상위 메뉴에서 "Time picker"을 선택하고 "Absolute" 클릭하여 시간 설정하고 "Go" 버튼을 클릭함

    시작 : 1995-07-01, 끝 : 1995-07-31

  . Bukets > Geo Coordinates 선택하고

  . Bukets > Aggregation > Geohash 선택함

  . Bukets > Field > geoip.locations. 선택함

  . 지도을 끌어 당겨 화면에 맞추고 zoom을 수행하고 "NASA_MAP" 이름으로 저장함


The_Pipeline_of_data_analysis.pptx


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/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
글 보관함