Logstash:多个配置文件(conf)apache
对于多个配置的处理方法,有多个处理方法:json
- 多个pipeline
- 一个pipleline处理多个配置文件
一个pipeline含有一个逻辑的数据流,它从input接收数据,并把它们传入到队列里,通过worker的处理,最后输出到output。这个output能够是Elasticsearch或其它。下面针对这两种状况,来分别进行描述。ruby
多个pipeline
cat apache.conf 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 } }
# cat 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/apache_template.json" template_name => "apache_elastic_example" template_overwrite => true } }
接下来,修改pipelines.yml文件。在logstash的安装目录下的config文件目录下,修改pipelines.yml文件。elasticsearch
- 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中。ide
这样操做配置已经完成了。进入到longstash的安装目录。咱们经过以下的命令来运行:spa
./bin/logstash
debug
在terminal中,能够看到有两个piple在同时运行,也能够在Kibana中看到咱们的index结果。code
一个pipeline
一样能够修改位于Logstash安装目录下的config子目录里的pipleline.yml文件,并把它修改成:队列
- pipeline.id: my_logs queue.type: persisted path.config: "/Users/liuxg/data/multi-pipeline/*.conf"
把全部位于/Users/liuxg/data/multi-pipeline/下的全部的conf文件都放于一个pipeline里。事件
按照上面一样的方法来运行咱们的应用:
./bin/logstash
从运行的结果中看到了两个一样的输出。这是为何呢?这是由于咱们把两个.conf文件放于一个pipleline里运行,那么咱们有两个stdout的输出分别位于两个.conf文件了。
在Kibana里能够看到咱们的最终的index数据:
咱们能够看到在apache_log里有20条数据,它包括两个log文件里全部的事件,这是由于它们都是一个pipleline。一样咱们能够在apache_daily看到一样的20条数据。