성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Logstash 기본 사용법</h1> <p> 이에 대한 공식 문서는 있지만,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Getting Started with Logstash ; <a target='tab' href='http://elastic.co/guide/en/logstash/current/getting-started-with-logstash.html'>http://elastic.co/guide/en/logstash/current/getting-started-with-logstash.html</a> </pre> <br /> 그래도 다음의 동영상을 먼저 보실 것을 권장합니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Logstash 시작하기 (약 43분 동영상) ; <a target='tab' href='https://www.elastic.co/kr/webinars/getting-started-logstash?baymax=rtp&elektra=docs&storm=top-video&iesrc=ctr'>https://www.elastic.co/kr/webinars/getting-started-logstash?baymax=rtp&elektra=docs&storm=top-video&iesrc=ctr</a> </pre> <br /> 이 글은 사실 저 동영상을 정리한 것에 불과합니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 동영상에 보면, Logstash가 어떤 위치를 차지하는지 보여주는 다이어그램이 하나 나옵니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='elastic_stack_2.png' src='/SysWebRes/bbs/elastic_stack_2.png' /><br /> <br /> 즉, Logstash 스스로 elasticsearch에 데이터를 보낼 수도 있고, 아니면 Beats로부터 온 데이터를 수집/가공 후 전달할 수도 있습니다. 예전 글을 검색하다 보면 Logstash만으로 구성하는 것을 볼 수 있는데, 그 자체로는 다소 무겁다 보니 순수 로그 수집 역할만 하는 경량화된 Beats가 나오면서 Logstash는 아래의 이미지에서처럼 일종의 Dataflow 엔진으로써의 서버 역할을 수행하는 것으로 바뀌는 분위기입니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='logstash_with_beats_1.png' src='/SysWebRes/bbs/logstash_with_beats_1.png' /><br /> <br /> 하지만, 이번 글에서는 Beats까지는 설명하지 않을 것이고 Logstash의 Input/Filter/Output의 개념을 잡는 것만 다룰 것입니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 저처럼 성격이 급하면 ^^ 우선 .\bin\logstash.bat 파일을 실행해 볼 텐데요, 그냥 실행하는 경우 다음과 같이 "ERROR: Pipelines YAML file is empty" 오류가 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> <span style='color: blue; font-weight: bold'>logstash.bat</span> Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.jruby.ext.openssl.SecurityHelper (file:/C:/Users/tstusr/AppData/Local/Temp/jruby-6388/jruby10138242635010762776jopenssl.jar) to field java.security.MessageDigest.provider WARNING: Please consider reporting this to the maintainers of org.jruby.ext.openssl.SecurityHelper WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release Sending Logstash logs to C:/logstash/logs which is now configured via log4j2.properties [2020-09-04T11:07:44,103][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"7.9.0", "jruby.version"=>"jruby 9.2.12.0 (2.5.7) 2020-07-01 db01a49ba6 Java HotSpot(TM) 64-Bit Server VM 11.0.8+10-LTS on 11.0.8+10-LTS +indy +jit [mswin32-x86_64]"} <span style='color: blue; font-weight: bold'>ERROR: Pipelines YAML file is empty. Location: C:/logstash/config/pipelines.yml</span> usage: bin/logstash -f CONFIG_PATH [-t] [-r] [] [-w COUNT] [-l LOG] bin/logstash --modules MODULE_NAME [-M "MODULE_NAME.var.PLUGIN_TYPE.PLUGIN_NAME.VARIABLE_NAME=VALUE"] [-t] [-w COUNT] [-l LOG] bin/logstash -e CONFIG_STR [-t] [--log.level fatal|error|warn|info|debug|trace] [-w COUNT] [-l LOG] bin/logstash -i SHELL [--log.level fatal|error|warn|info|debug|trace] bin/logstash -V [--log.level fatal|error|warn|info|debug|trace] bin/logstash --help [2020-09-04T11:07:44,404][ERROR][org.logstash.Logstash ] java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit </pre> <br /> 메시지에 따라 "C:/logstash/config/pipelines.yml" 파일이 존재하지만 그 안에는 파이프라인 처리가 하나도 명시되어 있지 않기 때문에 발생하는 오류입니다. Logstash의 파이프라인은,<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='logstash_with_beats_2.png' src='/SysWebRes/bbs/logstash_with_beats_2.png' /><br /> <br /> 크게 Input, Filter, Output으로 나뉘며 Input 및 Output에는 데이터 역직렬화/직렬화를 위한 Codec을 연결하는 구조입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Input - Files - Syslog - SQL Queries - HTTP requests - Elasticsearch - Beats - Metrics systems - And more! Filter - log 파싱 - 데이터 확장 - 태그 추가 - And more! Output - Elasticsearch - Data 보관소 (예: Amazon S3) - Alerting & Monitoring 시스템 - And more! Codec: 데이터 인코딩 & 디코딩 - JSON - Avro - msgpack - Netflow - CloudTrail - And more! </pre> <br /> 내부적으로 이들이 동작하는 방식은 다음의 그림으로 정리가 됩니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='logstash_with_beats_3.png' src='/SysWebRes/bbs/logstash_with_beats_3.png' /><br /> <br /> 물론, 설정에 따라 work queue의 크기 조정이나, Batcher에서 얼마만큼의 벌크 단위로 Output으로 보낼지 등의 설정을 yml의 옵션 변경으로 할 수 있다고 합니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 자, 그럼 대충 구조를 보니 파이프라인을 설정해야 한다는 것은 알겠고, logstash는 이러한 파이프라인 설정을 명령행에서 할 수 있도록 "-e" 옵션을 제공하므로 Filter 없이 기본적인 Input/Output을 콘솔을 대상으로 수행하도록 다음과 같이 logstash를 수행할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\logstash> <span style='color: blue; font-weight: bold'>.\bin\logstash.bat -e "input { stdin { } } output { stdout { } }"</span> Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.jruby.ext.openssl.SecurityHelper (file:/C:/Users/tstusr/AppData/Local/Temp/jruby-1684/jruby6939663397342853683jopenssl.jar) to field java.security.MessageDigest.provider WARNING: Please consider reporting this to the maintainers of org.jruby.ext.openssl.SecurityHelper WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release Sending Logstash logs to C:/logstash/logs which is now configured via log4j2.properties [2020-09-04T14:20:45,142][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"7.9.0", "jruby.version"=>"jruby 9.2.12.0 (2.5.7) 2020-07-01 db01a49ba6 Java HotSpot(TM) 64-Bit Server VM 11.0.8+10-LTS on 11.0.8+10-LTS +indy +jit [mswin32-x86_64]"} [2020-09-04T14:20:45,387][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified [2020-09-04T14:20:46,642][INFO ][org.reflections.Reflections] Reflections took 35 ms to scan 1 urls, producing 22 keys and 45 values [2020-09-04T14:20:47,347][INFO ][logstash.javapipeline ][main] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>1000, "pipeline.sources"=>["config string"], :thread=>"#<Thread:0x394dc001 run>"} [2020-09-04T14:20:48,106][INFO ][logstash.javapipeline ][main] Pipeline Java execution initialization time {"seconds"=>0.74} [2020-09-04T14:20:48,202][INFO ][logstash.javapipeline ][main] Pipeline started {"pipeline.id"=>"main"} The stdin plugin is now waiting for input: [2020-09-04T14:20:48,264][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]} [2020-09-04T14:20:48,523][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600} </pre> <br /> 위와 같은 상태에서, 마지막에 커서가 깜박이는 위치에 "Hello World"를 입력하고 엔터를 치면, 다음과 같이 이를 그대로 해석해 Console로 출력하게 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Hello world { "@timestamp" => 2020-09-04T05:21:27.198Z, "@version" => "1", "message" => "Hello world\r", "host" => "testpc" } </pre> <br /> 사실, 이렇게 "-e" 옵션을 사용해 파이프라인을 적용하는 것은 현업에서 거의 볼 수 없습니다. 왜냐하면 실제적으로 사용하려면 꽤나 복잡해지기 때문에 대개의 경우 파일을 전달하게 되는데요, 예를 들어 sample.conf라는 파일명으로 다음과 같은 내용을 담고 있으면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > input { stdin { } } output { stdout { } } </pre> <br /> 이를 "-f" 옵션으로 경로와 함께 전달해 실행하는 식으로 운영하는 것이 더 일반적입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\logstash> <span style='color: blue; font-weight: bold'>.\bin\logstash.bat -f .\config\sample.conf</span> Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.jruby.ext.openssl.SecurityHelper (file:/C:/Users/tstusr/AppData/Local/Temp/jruby-8988/jruby9834988936030215649jopenssl.jar) to field java.security.MessageDigest.provider WARNING: Please consider reporting this to the maintainers of org.jruby.ext.openssl.SecurityHelper WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release Sending Logstash logs to C:/logstash/logs which is now configured via log4j2.properties [2020-09-04T14:24:03,152][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"7.9.0", "jruby.version"=>"jruby 9.2.12.0 (2.5.7) 2020-07-01 db01a49ba6 Java HotSpot(TM) 64-Bit Server VM 11.0.8+10-LTS on 11.0.8+10-LTS +indy +jit [mswin32-x86_64]"} [2020-09-04T14:24:03,389][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified [2020-09-04T14:24:04,745][INFO ][org.reflections.Reflections] Reflections took 38 ms to scan 1 urls, producing 22 keys and 45 values [2020-09-04T14:24:05,369][INFO ][logstash.javapipeline ][main] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>1000, "pipeline.sources"=>["C:/logstash/config/sample.conf"], :thread=>"#<Thread:0x651b361c run>"} [2020-09-04T14:24:06,167][INFO ][logstash.javapipeline ][main] Pipeline Java execution initialization time {"seconds"=>0.77} [2020-09-04T14:24:06,232][INFO ][logstash.javapipeline ][main] Pipeline started {"pipeline.id"=>"main"} The stdin plugin is now waiting for input: [2020-09-04T14:24:06,293][INFO ][logstash.agent ] <span style='color: blue; font-weight: bold'>Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}</span> [2020-09-04T14:24:06,536][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600} <span style='color: blue; font-weight: bold'>Hello World { "@timestamp" => 2020-09-04T05:24:15.093Z, "@version" => "1", "message" => "Hello World\r", "host" => "testpc" } </span> </pre> <br /> 이것만으로도 대충 개념을 아시겠죠? ^^<br /> <br /> <hr style='width: 50%' /><br /> <br /> 짐작할 수 있겠지만, 로그의 내용을 파싱하는 것은 여러 번의 시행착오를 거칠 수 있으므로 conf 파일의 파이프라인 내용은 초기 작업에서 빈번하게 바뀔 수 있는데, 그때마다 파일 변경하고 logstash.bat을 다시 실행하는 방식은 매우 비효율적입니다. 이를 위해 다음의 옵션 2가지를 ./config/logstash.yml 설정 파일에서 변경할 수 있는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ...[생략]... # Periodically check if the configuration has changed and reload the pipeline # This can also be triggered manually through the SIGHUP signal # <span style='color: blue; font-weight: bold'>config.reload.automatic: true</span> # # How often to check if the pipeline configuration has changed (in seconds) # Note that the unit value (s) is required. Values without a qualifier (e.g. 60) # are treated as nanoseconds. # Setting the interval this way is not recommended and might change in later versions. # <span style='color: blue; font-weight: bold'>config.reload.interval: 3s</span> ...[생략]... </pre> <br /> 이렇게 설정해 주면 3초마다 파이프라인이 지정된 conf 파일이 바뀌면 자동으로 다시 로드하므로 편리하게 테스트/적용할 수 있습니다. 또한, logstash.bat의 "-f" 옵션으로 conf 파일을 전달하는 것도 ./config/pipelines.yml에 "pipeline.id", "path.config"으로 미리 설정할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ...[생략]... <span style='color: blue; font-weight: bold'>- pipeline.id: sample_log_io path.config: C:\logstash\config\sample.conf</span> ...[생략]... </pre> <br /> 위와 같이 logstash.yml과 pipelines.yml을 설정한 후 logstash.bat를 실행시키면, 이제부터는 sample.conf 파일의 내용을 바꿔가며 저장하면서 결과를 바로바로 확인할 수 있습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 테스트하기 좋게 설정을 완료했으니, 이제 파이프라인을 약간 변형시켜 볼까요? ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > input { <span style='color: blue; font-weight: bold'> tcp { port => 9900 }</span> } <span style='color: blue; font-weight: bold'>filter { grok { match => { "message" => "Hello %{WORD:name}" } } } </span> output { stdout { <span style='color: blue; font-weight: bold'>codec => rubydebug</span> } } </pre> <br /> input은 그냥 봐도 직관적으로 알 수 있고, output도 대략 rubdydebug라는 미리 지정된 codec 형식으로 출력을 직렬화한다는 것을 알 수 있습니다. 반면 filter는 다소 생소한데요, (미리 지정된) grok 패턴을 이용해 input으로 받은 메시지를 정규 표현식으로 패턴 매칭 시켜 일종의 "변수 이름"에 매핑하는 문법을 사용합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > %{SYNTAX:SEMANTIC} </pre> <br /> 즉, SYNTAX로 분석된 구문을 SEMANTIC에 매핑하는 것인데요, 여기서 SYNTAX에 올 수 있는 미리 정의된 grok 패턴을 다음의 문서에서 볼 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > logstash/patterns/grok-patterns ; <a target='tab' href='https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns'>https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns</a> </pre> <br /> 예제에서는 WORD가 사용되고 있으므로, <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > WORD \b\w+\b </pre> <br /> "Hello" 단어가 오는 다음의 "한 단어"를 "name"이라는 SEMANTIC으로 매핑시켜주는 역할을 합니다. 설명이 좀 어렵지만, logstash.bat을 실행시킨 후,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\logstash> <span style='color: blue; font-weight: bold'>.\bin\logstash.bat</span> Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.jruby.ext.openssl.SecurityHelper (file:/C:/Users/tstusr/AppData/Local/Temp/jruby-1424/jruby564628344584854279jopenssl.jar) to field java.security.MessageDigest.provider WARNING: Please consider reporting this to the maintainers of org.jruby.ext.openssl.SecurityHelper WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release Sending Logstash logs to C:/logstash/logs which is now configured via log4j2.properties [2020-09-04T14:33:10,846][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"7.9.0", "jruby.version"=>"jruby 9.2.12.0 (2.5.7) 2020-07-01 db01a49ba6 Java HotSpot(TM) 64-Bit Server VM 11.0.8+10-LTS on 11.0.8+10-LTS +indy +jit [mswin32-x86_64]"} [2020-09-04T14:33:12,831][INFO ][org.reflections.Reflections] Reflections took 49 ms to scan 1 urls, producing 22 keys and 45 values [2020-09-04T14:33:16,704][INFO ][logstash.javapipeline ][sample_log_io] Starting pipeline {:pipeline_id=>"sample_log_io", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>1000, <span style='color: blue; font-weight: bold'>"pipeline.sources"=>["C:/logstash/config/sample.conf"]</span>, :thread=>"#<Thread:0x2c63791c run>"} [2020-09-04T14:33:17,556][INFO ][logstash.javapipeline ][sample_log_io] Pipeline Java execution initialization time {"seconds"=>0.83} [2020-09-04T14:33:17,799][INFO ][logstash.javapipeline ][sample_log_io] Pipeline started {"pipeline.id"=>"sample_log_io"} [2020-09-04T14:33:17,811][INFO ][logstash.inputs.tcp ][sample_log_io][434804e2a87f1e6a6e479e344cc66c63cddf7399bf4a1add6f1ec6b637001ee9] Starting tcp input listener {:address=>"0.0.0.0:9900", :ssl_enable=>"false"} [2020-09-04T14:33:17,861][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:sample_log_io], :non_running_pipelines=>[]} [2020-09-04T14:33:18,357][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600} </pre> <br /> tcp 9900 포트로 "Hello World"라는 내용을 보내면 output 필터로 콘솔이 지정되었으므로 곧바로 출력 결과가 나옵니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > { "port" => 58006, "@timestamp" => 2020-09-04T06:51:58.301Z, "host" => "0:0:0:0:0:0:0:1", "@version" => "1", "message" => "\"Hello World\" \r", <span style='color: blue; font-weight: bold'>"name" => "World"</span> } </pre> <br /> 참고로, tcp 클라이언트를 프로그램하는 것은 귀찮으므로 <a target='tab' href='https://www.sysnet.pe.kr/2/0/12311'>netcat</a> 등의 프로그램을 다운로드해 다음과 같이 cmd 창에서 테스트할 수 있습니다. (또는, <a target='tab' href='https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/telnet'>telnet</a>을 이용해 됩니다.)<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> <span style='color: blue; font-weight: bold'>echo "Hello World" | netcat localhost 9900</span> </pre> <br /> "WORD" 패턴은 너무 심심하니, 역시 미리 정의된 COMBINEDAPACHELOG를 이용해 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # <a target='tab' href='https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns'>https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns</a> COMMONAPACHELOG %{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-) COMBINEDAPACHELOG %{COMMONAPACHELOG} %{QS:referrer} %{QS:agent} </pre> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > input { tcp { port => 9900 } } filter { grok { match => { <span style='color: blue; font-weight: bold'>message => "%{COMBINEDAPACHELOG}"</span> } } <span style='color: blue; font-weight: bold'>geoip { source => "clientip" }</span> } output { stdout { codec => rubydebug } } </pre> <br /> 다음과 같은 식의 <a target='tab' href='https://github.com/elastic/examples/blob/master/Common%20Data%20Formats/apache_logs/apache_logs'>apache log</a>를 test.log 파일로 저장한 후,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 83.149.9.216 - - [17/May/2015:10:05:03 +0000] "GET /presentations/logstash-monitorama-2013/images/kibana-search.png HTTP/1.1" 200 203023 "http://semicomplete.com/presentations/logstash-monitorama-2013/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36" </pre> <br /> logstash로 전달해 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> <span style='color: blue; font-weight: bold'>type test.log | netcat localhost 9900</span> </pre> <br /> apache log도 이렇게 가뿐하게 해석/출력을 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > { "port" => 61147, "@timestamp" => 2020-09-05T15:22:17.939Z, "host" => "0:0:0:0:0:0:0:1", "response" => "200", "timestamp" => "17/May/2015:10:05:03 +0000", "request" => "/presentations/logstash-monitorama-2013/images/kibana-search.png", "verb" => "GET", "clientip" => "83.149.9.216", "bytes" => "203023", "referrer" => "\"http://semicomplete.com/presentations/logstash-monitorama-2013/\"", "ident" => "-", "@version" => "1", "auth" => "-", "geoip" => { "timezone" => "Europe/Moscow", "postal_code" => "144700", "longitude" => 37.6172, "city_name" => "Moscow", "region_code" => "MOW", "location" => { "lat" => 55.7527, "lon" => 37.6172 }, "region_name" => "Moscow", "ip" => "83.149.9.216", "latitude" => 55.7527, "continent_code" => "EU", "country_code3" => "RU", "country_name" => "Russia", "country_code2" => "RU" }, "agent" => "\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36\"", "message" => "83.149.9.216 - - [17/May/2015:10:05:03 +0000] \"GET /presentations/logstash-monitorama-2013/images/kibana-search.png HTTP/1.1\" 200 203023 \"http://semicomplete.com/presentations/logstash-monitorama-2013/\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36\"", "httpversion" => "1.1" } </pre> <br /> <hr style='width: 50%' /><br /> <br /> Logstash가 유명하게 된 것은, 바로 사전 정의한 "Input/Output/Filter/Codec" 플러그인을 다양하게 제공한다는 점입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Input plugins ; <a target='tab' href='https://www.elastic.co/guide/en/logstash/current/input-plugins.html'>https://www.elastic.co/guide/en/logstash/current/input-plugins.html</a> Output plugins ; <a target='tab' href='https://www.elastic.co/guide/en/logstash/current/output-plugins.html'>https://www.elastic.co/guide/en/logstash/current/output-plugins.html</a> Filter plugins ; <a target='tab' href='https://www.elastic.co/guide/en/logstash/current/filter-plugins.html'>https://www.elastic.co/guide/en/logstash/current/filter-plugins.html</a> Codec plugins ; <a target='tab' href='https://www.elastic.co/guide/en/logstash/current/codec-plugins.html'>https://www.elastic.co/guide/en/logstash/current/codec-plugins.html</a> </pre> <br /> Elastic Stack이라는 이름에 걸맞게 Output 플러그인 중에는 elastic search도 있어서, 이전의 파이프라인을 다음과 같이 바꿔주면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > input { tcp { port => 9900 } } filter { grok { match => { message => "%{COMBINEDAPACHELOG}" } } geoip { source => "clientip" } } output { <span style='color: blue; font-weight: bold'>elasticsearch { hosts => ["localhost:9200"] }</span> } </pre> <br /> 해석한 Apache log를 elasticsearch로 보내 이후 Kibana를 이용한 Dashboard를 구성할 수 있습니다. 몇 가지 더 볼까요? ^^ <a target='tab' href='https://www.elastic.co/guide/en/logstash/current/plugins-inputs-twitter.html'>문서에 보면 twitter</a>도 있는데, 따라서 아래와 같이 파이프라인을 정의하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > input { twitter { consumer_key => "" consumer_secret => "" oauth_token => "" oauth_token_secret => "" keywords => [ "elastic", "logstash" ] full_tweet => true use_samples => true } } output { elasticsearch { hosts => ["localhost:9200"] } } </pre> <br /> twitter로부터 키워드가 "elastic"과 "logstash"를 포함하는 트윗을 읽어와 elasticsearch에 전달하게 됩니다. 또는 다음과 같이 다중 output을 지정하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > input { ... } filter { ... } output { elasticsearch { hosts => ["localhost:9200"] } s3 { access_key_id => "" secret_access_key => "" region => "eu-west-1" bucket => "my_bucket" size_file => 2048 time_file => 5 } } </pre> <br /> elasticsearch 및 아마존 S3에 보낼 수 있습니다. input으로는 jdbc를 이용한 DB 접근도 할 수 있는 등,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > input { jdbc { jdbc_user => "mysql" schedule => "**cron_tab_format**" parameters => { "company" => "elastic" } use_column_value => true tracking_column => id statment => "SELECT * FROM my_table WHERE id > :sql_last_value" } } filter { ... } output { ... } </pre> <br /> 자신의 환경에 따라 이미 제공되는 다양한 플러그인을 활용하는 재미가 있습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 아울러, 동영상에서 자세한 내용은 소개하고 있진 않지만 logstash 자체도 (기본 포트는 9600) Rest API를 제공한다는 것!<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // curl localhost:9600/_node/stats?pretty C:\logstash\config> <span style='color: blue; font-weight: bold'>curl localhost:9600/_node?pretty</span> { "host" : "testpc", "version" : "7.9.0", "http_address" : "127.0.0.1:9600", "id" : "1d243593-01d6-48c0-a4fe-a2e4c9f42e4d", "name" : "testpc", "ephemeral_id" : "3200b6f9-b3cc-45a7-a765-7164e8a48f67", "status" : "green", "snapshot" : false, "pipeline" : { "workers" : 8, "batch_size" : 125, "batch_delay" : 50 }, "pipelines" : { "sample_log_io" : { "ephemeral_id" : "cc9815fa-c3d8-43a1-a67d-3cd1deed9dc9", "hash" : "79f402af7f2ea776e352fde9e0075868818e962ca2421702ec00863d8fd086d5", "workers" : 8, "batch_size" : 125, "batch_delay" : 50, "config_reload_automatic" : true, "config_reload_interval" : 3000000000, "dead_letter_queue_enabled" : false } }, "os" : { "name" : "Windows 10", "arch" : "amd64", "version" : "10.0", "available_processors" : 8 }, "jvm" : { "pid" : 1424, "version" : "11.0.8", "vm_version" : "11.0.8", "vm_vendor" : "Oracle Corporation", "vm_name" : "Java HotSpot(TM) 64-Bit Server VM", "start_time_in_millis" : 1599197588077, "mem" : { "heap_init_in_bytes" : 1073741824, "heap_max_in_bytes" : 1037959168, "non_heap_init_in_bytes" : 7667712, "non_heap_max_in_bytes" : 0 }, "gc_collectors" : [ "ParNew", "ConcurrentMarkSweep" ] } } </pre> <br /> <hr style='width: 50%' /><br /> <br /> 기타...<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > FLUME - 아파치 Scribe - 페이스북 오픈 소스 (실시간 스트리밍 로그 수집) Chukwa - 아파치 인큐베이터 프로젝트, 하둡의 서브 프로젝트 Fluentd - 오픈 소스 데이터 수집기 </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
3346
(왼쪽의 숫자를 입력해야 합니다.)