Logstash:多个配置文件(conf)

Logstash:多个配置文件(conf)

对于多个配置的处理方法,有多个处理方法:

  • 多个pipeline
  • 一个pipleline处理多个配置文件

一个pipeline含有一个逻辑的数据流,它从input接收数据,并把它们传入到队列里,经过worker的处理,最后输出到output。这个output可以是Elasticsearch或其它。下面针对这两种情况,来分别进行描述。

多个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文件。

- 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的安装目录。我们通过如下的命令来运行:

./bin/logstash

在terminal中,可以看到有两个piple在同时运行,也可以在Kibana中看到我们的index结果。

一个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条数据。

原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/12076557.html