ELK环境搭建之logstash

下载地址

https://www.elastic.co/downloads/logstash

运行

./bin/logstash -f logstash.conf

新增一个配置文件first-pipeline.conf

配置说明 从 filebeat中收集日志 然后输出到标准输出和 elasticcsearch

input{

    beats{

        port => "5044"

    }

}

filter {

    # grok {

    # match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %    {NUMBER:bytes} %{NUMBER:duration}" }

    # }

    json {

        source => "message" #要解析的字段名

        target => "msg_json" #解析后的存储字段,默认和message同级别

    }

}

output {

    stdout{

        codec => rubydebug

    }

    elasticsearch {

        hosts => [ "localhost:9200" ]

    }

}

检查并启动

./bin/logstash -f config/first-pipeline.conf --config.test_and_exit

自动加载配置

./bin/logstash -f config/first-pipeline.conf --config.reload.automatic

grok 插件 适合系统日志

日志示例

55.3.244.1 GET /index.html 15824 0.043

#filter

grok {

 match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" }

}

json 插件

json {

    source => "message" #要解析的字段名

    target => "msg_json" #解析后的存储字段,默认和message同级别

}

nginx的过滤器

grok {

match => { "message" => "%{IP:client} - - \[%{HTTPDATE:logdate}\] \"%{WORD:verb} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}\" %{NUMBER:http_status_code} %{NUMBER:bytes} \"%{NOTSPACE:ref}\" \"%{DATA:user_agent}\"" }

}

date {

match => ["logdate", "dd/MMM/yyyy:HH:mm:ss Z"]

target => "@timestamp"

}

kv {

source => "request"

field_split => "&?"

value_split => "="

}

urldecode {

all_fields => true

}

start_position

从哪个位置读取文件数据,默认从尾部,值为:end
如果要导入历史数据则设置成:beginning

input {

    file {

        path => ["/opt/flights2.csv”]

        start_position => “beginning”

     }

}

欢迎关注我的博客
http://www.toalaska.cn/articles/2019/05/07/1557236543315.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值