一、logstash的filter阶段的配置:
1、logstash的grok插件的配置:
#GREEDYDATA表达式的意思能匹配任意字符串
2、mutate插件
3、kv插件
4、date插件
二、logstash input阶段的配置:
2、file插件:
2.1、多行处理插件multiline
file { path => ["/home/bamboom/logs/*/*.log"] start_position => "beginning" codec => multiline { pattern => "^%{TIMESTAMP_ISO8601}" negate => true what => "previous" } }
总之就是:
pattern 选项指定一个正则表达式。 事件匹配指定的正则表达式来确定是前一个事件的内容还是新的事件的内容。可以使用grok正则表达式的模板来配置该选项。
what 选项有两个选择值: previous 或者 next。 previous 值指定行匹配pattern选项的内容是上一行的一部分。 next 指定行匹配pattern选项的内容是下一行的一部分。
negate选项适用于multiline codec 行不匹配pattern选项指定的正则表达式。该配置使用negate => true 选项来指定任何不是以时间戳开始的行属于前行。也就是不匹配pattern的行都属于前行的内容的一部分。
三、logstash output阶段的配置:
1、es作为输出时的配置:
output { elasticsearch { id => 'onao_es' user => "elastic" password => "changeme" hosts => ["http://10.109.31.165:9200"] sniffing => false index => "logstash-%{+YYYY.MM.dd}" document_type => "logs" } }
注意这里是由于把es部署在容器里,而把logstash部署在另外一台宿主机上经常出现的一个bug:
正常现象:
异常现象:
这几句日志是由于sniffing => false这条配置导致的;正常现象是false的情况,异常现象是true的情况。
参考文献:
grok:https://www.jianshu.com/p/e9ca52c1f85e
grok正则匹配表:https://blog.csdn.net/backKeith/article/details/78480125
oniguruma(正则表达式):https://www.jianshu.com/p/3f699ee4c17a
logstash最佳实践:http://doc.yonyoucloud.com/doc/logstash-best-practice-cn/index.html
logstash配置文件:https://www.cnblogs.com/xiaobaozi-95/p/9214307.html
logstash插件详解:https://blog.csdn.net/bingdianone/article/details/86715916#filtergrok_130