처음은 윈도우로 해보자 하고시작했으나
구문이 뭔가 안맞는지 실행이 되질 않으니 linux환경에서 하는것을 정신건강상 추천드립니다.
다설치하고 sample 코드로 돌려봤는데
아래 grok filter를 적용하면 실행이 되질 않음....
input {
beats{
port => "5044"
}
}
filter{
grok{
match => {"message" => "%{NUMBER:request_time:float} %{NUMBER:upstream_response_time:float} %{IPORHOST:clientip} (?:-|({%WORD}.%{WORD})) %{USER:ident} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})\" %{NUMBER:response} (?:%{NUMBER:bytes}|-) %{QS:referrer} %{QS:agent} %{QS:forwarder}"}
}
}
output{
file{
path => "C:\Users\ibiz\Desktop\DATA\Study\ElasticSearch\logstash-8.5.1\log\output.log"
}
}
이대로 ubuntu에서는 잘되는데
이상하게 윈도우에서 안된다.
https://kangmyounghun.blogspot.com/2019/10/logstash.html
윈도우 Logstash 파이프라인
Easy to analyze if you can arrange data
kangmyounghun.blogspot.com
grok pattern
https://alexmarquardt.com/using-grok-with-elasticsearch-to-add-structure-to-your-data/
Using Grok with Elasticsearch to add structure to your data
July 13, 2020IntroductionAs well as being a search engine, Elasticsearch is also a powerful analytics engine. However in order to take full advantage of the near-real-time analytics capabilities of…
alexmarquardt.com
위와 같은 심각하게 욕나오는 상황이 발생하여 ubuntu로 다시해봄
UBUNTU
nginx 설치후 filebeat 설치(apt install filebeat 링크: https://rainbound.tistory.com/entry/Filebeat-%EC%84%A4%EC%B9%98)
후 deb 파일을 받아설치
https://www.elastic.co/kr/downloads/logstash
Download Logstash Free | Get Started Now
Download Logstash or the complete Elastic Stack (formerly ELK stack) for free and start collecting, searching, and analyzing your data with Elastic in minutes.
www.elastic.co
이젠 그냥 packgage로 설치하겟다.ㅠㅠㅠ
링크 복사하여 curl -l 로 하던지 wget으로 해도 된다.
다운 받고 다음명령어로 설치
sudo dpkg -i logstash-8.5.1-amd64.deb
다음경로에 nginx-logs.conf 생성하여 다음을 입력합니다.
../logstash/conf.d/nginx-logs.conf
input {
beats{
port => "5044"
}
}
filter{
grok{
match => {
"message" => "%{NUMBER:request_time:float} %{NUMBER:upstream_response_time:float} %{IPORHOST:clientip} (?:-|({%WORD}.%{WORD})) %{USER:ident} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})\" %{NUMBER:response} (?:%{NUMBER:bytes}|-) %{QS:referrer} %{QS:agent} %{QS:forwarder}"
}
}
}
output{
file{
path => "/var/log/logstash/output.log"
}
}
input은 입력 받는것
위에서는 filebeat에서 port 5044 에서 받겟다는 것이다.
filter - grok 은 grok 패턴으로 파싱룰 정함
ouput은 출력하는것.
file형태로 path 경로에 저장한다는 의미
저장한 다음
systemctl start logstash 한뒤
/var/log/logstash/output.log 에 들어가면
{"ecs":{"version":"8.0.0"},"agent":{"ephemeral_id":"9cfe8b47-3a21-47de-8d40-3005e3c2612b",
"version":"8.5.0","type":"filebeat","id":"8d8e570c-cf84-4ead-8b3a-ee3acdb83f44",
"name":"elasticsearch"},"input":{"type":"log"},"@version":"1",
"tags":["beats_input_codec_plain_applied","_grokparsefailure"],
"message":"10.0.127.73 - - [21/Nov/2022:15:42:09 +0900]
\"GET / HTTP/1.1\" 304 0 \"-\" \
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36\"",
"log":{"file":{"path":"/home/ubuntu/app/nginx-1.22.1/logs/access.log"},
"offset":13072},"host":{"ip":["10.0.20.10","fe80::20c:29ff:fe98:59fa"],
"name":"elasticsearch","architecture":"x86_64",
"containerized":false,"id":"d8c328cae27e4230bf803221125b6e82",
"mac":["00-0C-29-98-59-FA"],"hostname":"elasticsearch",
"os":{"platform":"ubuntu","type":"linux","version":"22.04.1 LTS (Jammy Jellyfish)",
"family":"debian","name":"Ubuntu","kernel":"5.15.0-52-generic","codename":"jammy"}},
"event":{"original":"10.0.127.73 - - [21/Nov/2022:15:42:09 +0900]
\"GET / HTTP/1.1\" 304 0 \"-\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36\""},"@timestamp":"2022-11-21T06:42:12.098Z"}
이런식으로 로그가 출력된다.
'ElasticSearch' 카테고리의 다른 글
aws opensearch 검색 (0) | 2023.06.23 |
---|---|
[ElasticStack] Logstash 설치 (0) | 2022.11.10 |
[ElasticStack] Filebeat 설치 (2) | 2022.11.08 |
ElasticSearch put 에러 (0) | 2022.11.02 |
ElasticSearch Analyzers 란? (0) | 2022.11.02 |
댓글