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條數據。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM