logstash使用

安裝

安裝很簡單,只須要去官網http://www.elastic.co/cn/products/logstash 下載對應版本的安裝包,解壓:
tar -zxvf logstash-5.4.3.gz
而後對logstash目錄下執行:
bin/logstash -e 'input { stdin { } } output { stdout {} }'
會出現以下界面
html

配置文件

logstash也能夠經過制定配置文件的形式啓動
bin/logstash -f logstash.conf
其中logstash.conf的配置文件的格式大體以下:git

input {
  file {
        path => ["/root/flow/agentLog/*","/root/flow/log/*"]
        start_position => "beginning"
   }
}

filter {
    grok {
         match => [
             "message","%{TIME:time} %{WORD:module} %{NOTSPACE:thread} %{LOGLEVEL:loglevel}  %{NOTSPACE:method} %{NOTSPACE:split} (?<json_data>{[.\s\S]+})",
             "message","%{TIME:time} %{NOTSPACE:thread} %{LOGLEVEL:loglevel}  %{NOTSPACE:method} %{NOTSPACE:split} (?<json_data>{[.\s\S]+})"
         ]                               
    }
    json {
        source => "json_data"
        remove_field => ["method"]
        remove_field => ["thread"]
        remove_field => ["split"]
        remove_field => ["time"]
    }
}

output {
   #stdout {}
     elasticsearch {
        hosts => ["http://ip:port"]
        index => "flow-%{+YYYY.MM.dd}"
        #index => "logstash-test"
        #user => "elastic"
        #password => "changeme"
    }
}
相關文章
相關標籤/搜索