logstash使用

安装

安装很简单,只需要去官网http://www.elastic.co/cn/products/logstash 下载对应版本的安装包,解压:
tar -zxvf logstash-5.4.3.gz
然后对logstash目录下执行:
bin/logstash -e 'input { stdin { } } output { stdout {} }'
会出现如下界面

配置文件

logstash也可以通过制定配置文件的形式启动
bin/logstash -f logstash.conf
其中logstash.conf的配置文件的格式大致如下:

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"
    }
}
posted on 2019-02-26 16:31  junjiang3  阅读(341)  评论(0编辑  收藏  举报