2016-11-25 43 views
0

我从Logstash解析Apache访问日志并将其索引到Elasticsearch索引中。我也索引了geoipagent字段。索引时,我观察到elasticsearch索引大小为6.7x大于实际文件大小(磁盘空间)。所以我只想了解这是正确的行为还是我在这里做错了什么?我正在使用Elasticsearch 5.0Logstash 5.0Kibana 5.0版本。我也试过best_compression,但它的磁盘大小相同。以下是我迄今尝试过的配置文件的完整观察。Elasticsearch best_compression不起作用

我的观察:

使用案例1:

Apache Log file Size:211 MB
Total number of lines:1,000,000
Index Size:1.5 GB
Observation:索引为6.7x大于文件大小。

使用案例2:

我已经找到了几个解决方案来压缩elasticsearch索引,那么我想它。

- Disable `_all` fields 
- Remove unwanted fields that has been created by `geoip` and `agent` parsing. 
- Enable `best_compression` [ index.codec": "best_compression"] 

Apache Log file Size:211 MB
Total number of lines:人民币100
Index Size:1.3 GB
Observation:指数大于文件大小

日志文件格式6.16x更大:

127.0.0.1 - - [24/Nov/2016:02:03:08 -0800] "GET /wp-admin HTTP/1.0" 200 4916 "http://trujillo-carpenter.com/" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 5.01; Trident/5.1)" 

我发现Logstash + Elasticsearch Storage Experients他们是sayi ng他们已经从6.23x减少了指数大小到1.57x。但这是相当古老的解决方案,这些解决方案在Elasticsearch 5.0中不再有效。

一些更多的参考我已经尝试:
- Part 2.0: The true story behind Elasticsearch storage requirements
- https://github.com/elastic/elk-index-size-tests

有没有什么更好的方法来优化Elasticseach索引大小时,你的目的是只显示在Kibana可视化?

回答

0

由于索引设置未应用于索引,因此我正面临此问题。我的索引名称和模板名称不同。使用相同的模板名称和索引名称后,压缩应用正常。

在下面的示例中,我使用索引名称apache_access_logs和模板名称elk_workshop

共享纠正的模板和logstash配置。

Logstash.conf

output { 
    elasticsearch { 
    hosts => ["localhost:9200"] 
    index => "apache_access_logs" 
    template => "apache_sizing_2.json" 
    template_name => "apache_access_logs" /* it was elk_workshop */ 
    template_overwrite => true 
    } 
} 

模板:

{ 

    "template": "apache_access_logs", /* it was elk_workshop */ 
    "settings": { 
     "index.refresh_interval": "5s", 
     "index.refresh_interval": "30s", 
     "number_of_shards": 5, 
     "number_of_replicas": 0 
    }, 
    .. 
}   

参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#indices-templates