2016-11-25 45 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