步骤
deb:
12curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.4.2-amd64.debsudo dpkg -i filebeat-5.4.2-amd64.deb安装后可以看到如下
Parsing Logs with Logstash
filebeat config
- 在安装完成之后你需要配置filebeat,通过修改filebeat.yml,以nginx的日志为例
|
|
- filebeat.yml
|
|
- 在数据源的机器上执行如下命令:12cd /usr/share/filebeat/bin/./filebeat -e -c /etc/filebeat/filebeat.yml -d "publish"
logstash config
- 创建一个logstash的配置文件
|
|
first-pipeline.conf
12345678910111213input {beats {port => "5044"}}The filter part of this file is commented out to indicate that it isoptional.filter {}output {stdout { codec => rubydebug }}确认logstash配置文件是否写错
|
|
- 获取ok ( The –config.test_and_exit option parses your configuration file and reports any errors.)
|
|
- 运行logstash
|
|
- 在filebeat开启的时候可以获得类似于如下的信息:123456789101112131415161718{"@timestamp" => 2017-06-22T14:58:32.169Z,"offset" => 13300,"@version" => "1","input_type" => "log","beat" => {"hostname" => "iZm5e7jlki70utmw22zj76Z","name" => "iZm5e7jlki70utmw22zj76Z","version" => "5.4.2"},"host" => "iZm5e7jlki70utmw22zj76Z","source" => "/var/log/nginx/access.log","message" => "115.61.84.162 - - [22/Jun/2017:22:06:06 +0800] \"GET http://open.163.com/ HTTP/1.1\" 200 612 \"http://open.163.com/\" \"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\"","type" => "log","tags" => [[0] "beats_input_codec_plain_applied"]}
- 修改first-pipeline.conf,使用grok
|
|
- 删除日志记录的节点,我们可以重头读取日志
|
|
- 可以看到我们获取到了的日志改变了,获取了更加详细的日志
- 启用goip
|
|
- 同样删除registry,重启程序,可以看到信息又更新了
indexing data into elasticsearch
将first-pipeline.conf 再度修改,将output指向elasticsearch
123456789101112131415161718192021input {beats {port => "5044"}}filter {grok {match => { "message" => "%{COMBINEDAPACHELOG}"}}geoip {source => "clientip"}}#output {# stdout { codec => rubydebug }#}output {elasticsearch {hosts => [ "localhost:9200" ]}}同样删除registry,重启程序,然后再启动elasticsearch
|
|
- 命令中logstash-DATE,替换 DATE 变成正确的时间, 格式如下 YYYY.MM.DD,通过请求,我们可以获得类似如下的数据
- 完整版
|
|
- 去web上查看结果