Logstash:多個配置檔案(conf)
在前面的一篇文章“Logstash:處理多個input”中,我們介紹瞭如何使用在同一個配置檔案中處理兩個input的情況。在今天這篇文章中,我們來介紹如何來處理多個配置檔案的問題。對於多個配置的處理方法,有多個處理方法:
- 多個pipeline
- 一個pipleline處理多個配置檔案
一個pipeline含有一個邏輯的資料流,它從input接收資料,並把它們傳入到佇列裡,經過worker的處理,最後輸出到output。這個output可以是Elasticsearch或其它。下面針對這兩種情況,來分別進行描述。
多個pipeline
為了做這個練習,我建立了兩個Logstash的配置檔案。這兩個配置檔案可以在地址https://github.com/liu-xiao-guo/logstash_multi-pipeline進行下載。我們把檔案下載下來後,把檔案存於一個自己喜歡的目錄裡。根據這個路徑修改下面.conf檔案裡的path裡的路徑。
input { file { path => "/Users/liuxg/data/multi-input/apache.log" start_position => "beginning" sincedb_path => "/dev/null" # ignore_older => 100000 type => "apache" } } filter { grok { match => { "message" => '%{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "%{WORD:verb} %{DATA:request} HTTP/%{NUMBER:httpversion}" %{NUMBER:response:int} (?:-|%{NUMBER:bytes:int}) %{QS:referrer} %{QS:agent}' } } } output { stdout { codec=> rubydebug } elasticsearch { index => "apache_log" template => "/Users/liuxg/data/apache_template.json" template_name => "apache_elastic_example" template_overwrite => true } }
這個配置檔案非常簡單。和之前的練習差不多。記得修改上面的path路徑,並讓它指向我們的log檔案所在的路徑。
daily.conf
input { file { path => "/Users/liuxg/data/multi-pipeline/apache-daily-access.log" start_position => "beginning" sincedb_path => "/dev/null" type => "daily" } } filter { grok { match => { "message" => '%{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "%{WORD:verb} %{DATA:request} HTTP/%{NUMBER:httpversion}" %{NUMBER:response:int} (?:-|%{NUMBER:bytes:int}) %{QS:referrer} %{QS:agent}' } } } output { stdout { codec => rubydebug } elasticsearch { index => "apache_daily" template => "/Users/liuxg/data/multi-pipeline/apache_template.json" template_name => "apache_elastic_example" template_overwrite => true } }
記得修改上面的path路徑,並讓它指向我們的log檔案所在的路徑。
接下來,我們修改我們的pipelines.yml檔案。在logstash的安裝目錄下的config檔案目錄下,修改pipelines.yml檔案。
pipelines.yml
- pipeline.id: daily pipeline.workers: 1 pipeline.batch.size: 1 path.config: "/Users/liuxg/data/multi-pipeline/daily.conf" - pipeline.id: apache queue.type: persisted path.config: "/Users/liuxg/data/multi-pipeline/apache.conf"
在上面的配置中,我們把daily.conf和apache.conf分別置於兩個不同的pipleline中。
這樣,我們的配置已經完成了。進入到longstash的安裝目錄。我們通過如下的命令來執行:
bogon:logstash-7.3.0 liuxg$ pwd /Users/liuxg/elastic/logstash-7.3.0 bogon:logstash-7.3.0 liuxg$ sudo ./bin/logstash
在terminal中,我們可以看到:
顯然,有兩個piple在同時執行。我們可以在Kibana中看到我們的index結果:
一個pipeline
我們同樣可以修改位於Logstash安裝目錄下的config子目錄裡的pipleline.yml檔案,並把它修改為:
pipelines.yml
- pipeline.id: my_logs
queue.type: persisted
path.config: "/Users/liuxg/data/multi-pipeline/*.conf"
這裡,我們把所有位於/Users/liuxg/data/multi-pipeline/下的所有的conf檔案都放於一個pipeline裡。
我們按照上面同樣的方法來執行我們的應用:
bogon:logstash-7.3.0 liuxg$ pwd /Users/liuxg/elastic/logstash-7.3.0 bogon:logstash-7.3.0 liuxg$ sudo ./bin/logstash
執行的結果是:
在上面我們看到了兩個同樣的輸出。這是為什麼呢?這是因為我們把兩個.conf檔案放於一個pipleline裡執行,那麼我們有兩個stdout的輸出分別位於兩個.conf檔案了。
我們在Kibana裡可以看到我們的最終的index資料:
我們可以看到在apache_log裡有20條資料,它包括兩個log檔案裡所有的事件,這是因為它們都是一個pipleline。同樣我們可以在apache_daily看到同樣的20條資料。
原文連結:https://blog.csdn.net/UbuntuTouch/java/article/details/100995868