1. 安裝好logstash后。
2. 最簡單的logstash。
logstash -e 'input { stdin { } } output { stdout {} }'
直到看到"Pipeline main started"。說明啟動成功。這個例子,stdin控制台輸入作為數據來源,stdout作為數據結果。
輸入 hello
可以看到
2016-11-24T12:28:25.047Z cangyue hello
3.配置filebeat,發送日志到logstashedit
注意:filebeat是一個為了可靠性和低延遲率而設計的輕量輸入插件。在典型的案例中,一般和logstash的實例運行在不同服務器。
4.下載filebeat
https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.0.1-darwin-x86_64.tar.gz
修改filebeat.yml
filebeat.prospectors:
- input_type: log
paths:
- /path/to/file/logstash-tutorial.log
output.logstash:
hosts: ["localhost:5043"]
運行
./filebeat -e -c filebeat.yml -d "publish"
5.在logstash的根目錄下配置test.conf,先輸入下面基本結構。
input {
beats {
port => "5043" --添加beats的輸入插件
}
} output {
stdout { codec => rubydebug } --運行實例時可以打印到控制台。
}
6.測試運行
logstash -f test.conf --config.test_and_exit --會打印出錯誤並且會自動退出
7.測試顯示ok的話。運行:
logstash -f first-pipeline.conf --config.reload.automatic --這個配置可以使修改配置文件的時候自動讀取配置而無需重啟logstash。
8.采用grok。配置中添加
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}"}
}
}
9.指向elasticsearch。
elasticsearch {
hosts => [ "localhost:9200" ]
}
10.刪除filebeat下面的data/registry文件。
11.重啟filebeat。
12.測試語句:
curl 'localhost:9200/_cat/indices?v' --查看elastic中所有的文檔索引
curl -XGET 'localhost:9200/logstash-$Date/_search?pretty&q=response=200' --$Date替換為天時間。形如2016.11.25
curl -XDELETE 'localhost:9200/logstash-2016.11.28' --刪除一個索引,所有數據都會消失。
q=response=200 -> 這里放插敘條件。前面部分為時間logstash-$Date