Elasticsearch: 6.4.2
Logstash: 6.4.2
1. 执行过程
Logstash事件进程管道有三个阶段:input->filter->output,其中input和output是必须的,filter是可选的;input默认为stdin,output默认为stdout。
-
inputs:常用的有file、syslog、redis、jdbc、beats等。
-
filters:常用的有:
- grok:解析和结构化任意文本。常用来解析非结构化的log;内置120种解析模式。
- mutate:对事件类型执行转换,可以rename、remove、replace、modify。
- drop:完全丢掉一种事件。
- geoip:添加IP地址的地理位置信息。
-
outputs:常用的有elasticsearch、file、graphite、statsd。
Codecs是基本的对input/output的流式过滤器,常见的有json、multiline、plain。
执行过程:logstash管道中每个input阶段都运行在独立的线程中。Inputs将事件写到一个存在于内存或硬盘的集中式queue中;每个管道worker从queue取一批事件(数量可配置)并按序执行配置的filters,最后将结果写入到outputs。
2. 简单实例
下载filebeat、logstash二进制包并解压。
下载apache日志。
filebeat读取apache日志并发送到logstash,logstash将其输出到stdout。
filebeat.yml
filebeat.prospectors:
- type: log
paths:
- /path/to/logstash-tutorial.log
output.logstash:
hosts: ["localhost:5044"]
启动filebeat
./filebeat -e -c filebeat.yml -d "publish"
logstash-sample.conf
input {
beats {
port => "5044"
}
}
output {
stdout { codec => rubydebug }
}
启动logstash
bin/logstash -f config/logstash-sample.conf --config.reload.automatic
- –config.reload.automatic:自动重加载配置文件,当你修改配置文件后不再需要stop并restart logstash了。