Logstash的部署
1、下载logstash
链接地址:Download Logstash
下载 tar.gz 复制下载链接:https://artifacts.elastic.co/downloads/logstash/logstash-6.3.0.tar.gz
linux 上 :wget https://artifacts.elastic.co/downloads/logstash/logstash-6.3.0.tar.gz
下载完成后:解压 tar -xzvf
2、安装启动:
官网上一个简单的start
logstash.conf的内容:
终端上输入 终端上输出:
复杂一点:输出到elasticsearch(前提已启动本地es)
匹配解释:
logstash-plugins/logstash-patterns-core正则匹配每个提取的字段。
终端输入:
127.0.0.1 - - [11/Dec/2013:00:01:45 -0800] "GET /xampp/status.php HTTP/1.1" 200 3891 "http://cadenza/xampp/navi.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0"
到es中查看:
GET _cat/indices?v
GET logstash-2018.07.03 查看其中的一条索引
Logstash可以足够灵巧的在Elasticsearch上建立索引... 每天会按照默认格式是logstash-YYYY.MM.DD来建立索引.而这种写法是必须要读@timestamp这个字段的。默认情况下@timestamp字段显示的是当前时间,但我们可能需要记录的是日志中的字符串类型的时间,所以我们需要把日志中字符串类型的时间覆盖掉@timestamp中的当前时间。
创建配置文件 code.conf
input {
stdin{}
}
filter {
grok {
match => ["message", "%{TIMESTAMP_ISO8601:logdate}"]
}
date {
match => ["logdate", "yyyy-MM-dd HH:mm:ss,SSS"]
target => "@timestamp"
}
}
output{
stdout{
codec=>rubydebug{}
}
}
说明:标红出为日志中的时间格式,这个根据具体的日志自行修改或自己开发正则去匹配。
这里我用的是logstash自带的正则。要查看自带了哪些正则可查看文件:/logstash-2.2.0/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-2.0.2/patterns/grok-patterns
测试:
./logstash -f code.conf
手动输入:
2016-08-24 18:05:39,830
索引模板:
- {
- "logstash": {
- "order": 0,
- "version": 60001,
- "index_patterns": [
- "logstash-*"
- ],
- "settings": {
- "index": {
- "refresh_interval": "5s"
- }
- },
- "mappings": {
- "_default_": {
- "dynamic_templates": [
- {
- "message_field": {
- "path_match": "message",
- "match_mapping_type": "string",
- "mapping": {
- "type": "text",
- "norms": false
- }
- }
- },
- {
- "string_fields": {
- "match": "*",
- "match_mapping_type": "string",
- "mapping": {
- "type": "text",
- "norms": false,
- "fields": {
- "keyword": {
- "type": "keyword",
- "ignore_above": 256
- }
- }
- }
- }
- }
- ],
- "properties": {
- "@timestamp": {
- "type": "date"
- },
- "@version": {
- "type": "keyword"
- },
- "geoip": {
- "dynamic": true,
- "properties": {
- "ip": {
- "type": "ip"
- },
- "location": {
- "type": "geo_point"
- },
- "latitude": {
- "type": "half_float"
- },
- "longitude": {
- "type": "half_float"
- }
- }
- }
- }
- }
- },
- "aliases": {}
- }
- }
相关文章