您好,登錄后才能下訂單哦!
由于公司zabbix的歷史數據存儲在elasticsearch中,有個需求是盡可能地把監控的歷史數據存儲的長一點,最好是一年,目前的情況是三臺ES節點,每天監控歷史數據量有5G,目前最多可存儲一個月的數據,超過30天的會被定時刪除,每臺內存分了8G,且全部使用機械硬盤,主分片為5,副本分片為1,查詢需求一般只獲取一周的歷史數據,偶爾會有查一個月到兩個月歷史數據的需求。
為了讓ES能存儲更長的歷史數據,以及考慮到后續監控項添加導致數據的增長,我將節點數量增加至4節點,并將部分節點內存提高,部分節點采用SSD存儲
192.168.179.133 200GSSD 4G內存 tag:hot node.name=es1
192.168.179.134 200GSSD 4G內存 tag:hot node.name=es2
192.168.179.135 1THDD 32G內存 tag:cold node.name=es3 node.master=false
192.168.179.136 1THDD 32G內存 tag:cold node.name=es4 node.master=false
對數據mapping重新建模,對str類型的數據不進行分詞,采用冷熱節點對數據進行存儲,前七天數據的索引分片設計為2主1副,索引存儲在熱節點上,超過七天的數據將被存儲在冷節點,超過30天的索引分片設置為2主0副本,ES提供了一個shrink的api來進行壓縮。由于ES是基于Lucene的搜索引擎,Lucene的索引由多個segment組成,每一個段都會消耗文件句柄,內存和CPU運行周期,段數量過多會使資源消耗變大,搜索也會變慢,這里我將前一天的索引分片強制合并為1個segment,修改refresh的時間間隔至60s,減少段的產生頻率。對超過3個月的索引進行關閉。以上操作均使用ES的管理工具curator來定時執行。
ES地址填寫集群中任意一個節點就可以
HistoryStorageURL=192.168.179.133:9200
HistoryStorageTypes=str,text,log,uint,dbl
HistoryStorageDateIndex=1
global $DB, $HISTORY;
$HISTORY['url'] = 'http://192.168.179.133:9200';
// Value types stored in Elasticsearch.
$HISTORY['types'] = ['str', 'text', 'log','uint','dbl'];
vim elasticsearch.yml
熱節點配置
node.attr.box_type=hot
冷節點配置
node.attr.box_type=cold
每種數據類型的模板都需要創建,可以根據elasticsearch.map文件來獲取api的信息,模板定義內容有匹配的索引,主副分片數設置,refresh間隔,新建索引分配節點設置以及mapping的設置,這里我只是以uint和str數據的索引為例
PUT _template/uint_template
{
"template": "uint*",
"index_patterns": ["uint*"],
"settings" : {
"index" : {
"routing.allocation.require.box_type": "hot",
"refresh_interval": "60s",
"number_of_replicas" : 1,
"number_of_shards" : 2
}
},
"mappings" : {
"values" : {
"properties" : {
"itemid" : {
"type" : "long"
},
"clock" : {
"format" : "epoch_second",
"type" : "date"
},
"value" : {
"type" : "long"
}
}
}
}
}
PUT _template/str_template
{
"template": "str*",
"index_patterns": ["str*"],
"settings" : {
"index" : {
"routing.allocation.require.box_type": "hot",
"refresh_interval": "60s",
"number_of_replicas" : 1,
"number_of_shards" : 2
}
},
"mappings" : {
"values" : {
"properties" : {
"itemid" : {
"type" : "long"
},
"clock" : {
"format" : "epoch_second",
"type" : "date"
},
"value" : {
"index" : false,
"type" : "keyword"
}
}
}
}
}
定義管道的作用是對寫入索引之前的數據進行預處理,使其按天產生索引。
PUT _ingest/pipeline/uint-pipeline
{
"description": "daily uint index naming",
"processors": [
{
"date_index_name": {
"field": "clock",
"date_formats": ["UNIX"],
"index_name_prefix": "uint-",
"date_rounding": "d"
}
}
]
}
PUT _ingest/pipeline/str-pipeline
{
"description": "daily str index naming",
"processors": [
{
"date_index_name": {
"field": "clock",
"date_formats": ["UNIX"],
"index_name_prefix": "str-",
"date_rounding": "d"
}
}
]
}
4.修改完成后重啟zabbix,并查看zabbix是否有數據
systemctl restart zabbix-server
curator官方文檔地址如下
https://www.elastic.co/guide/en/elasticsearch/client/curator/5.8/installation.html
pip install -U elasticsearch-curator
mkdir /root/.curator
vim /root/.curator/curator.yml
---
client:
hosts:
- 192.168.179.133
- 192.168.179.134
port: 9200
url_prefix:
use_ssl: False
certificate:
client_cert:
client_key:
ssl_no_validate: False
http_auth:
timeout: 30
master_only: False
logging:
loglevel: INFO
logfile:
logformat: default
blacklist: ['elasticsearch', 'urllib3']
將7天以前的索引分配到冷節點
1:
action: allocation
description: "Apply shard allocation filtering rules to the specified indices"
options:
key: box_type
value: cold
allocation_type: require
wait_for_completion: true
timeout_override:
continue_if_exception: false
disable_action: false
filters:
- filtertype: pattern
kind: regex
value: '^(uint-|dbl-|str-).*$'
- filtertype: age
source: name
direction: older
timestring: '%Y-%m-%d'
unit: days
unit_count: 7
將前一天的索引強制合并,每個分片1個segment。
2:
action: forcemerge
description: "Perform a forceMerge on selected indices to 'max_num_segments' per shard"
options:
max_num_segments: 1
delay:
timeout_override: 21600
continue_if_exception: false
disable_action: false
filters:
- filtertype: pattern
kind: regex
value: '^(uint-|dbl-|str-).*$'
- filtertype: age
source: name
direction: older
timestring: '%Y-%m-%d'
unit: days
unit_count: 1
超過30天的索引將主分片數量修改為2,副本分片為0,執行shrink操作的節點不能作為master節點
3:
action: shrink
description: "Change the number of primary shards to one, and the copy shards to 0"
options:
ignore_empty_list: True
shrink_node: DETERMINISTIC
node_filters:
permit_masters: False
exclude_nodes: ['es1','es2']
number_of_shards: 2
number_of_replicas: 0
shrink_prefix:
shrink_suffix: '-shrink'
delete_after: True
post_allocation:
allocation_type: include
key: box_type
value: cold
wait_for_active_shards: 1
extra_settings:
settings:
index.codec: best_compression
wait_for_completion: True
wait_for_rebalance: True
wait_interval: 9
max_wait: -1
filters:
- filtertype: pattern
kind: regex
value: '^(uint-|dbl-|str-).*$'
- filtertype: age
source: name
direction: older
timestring: '%Y-%m-%d'
unit: days
unit_count: 30
對超過3個月的索引進行關閉
4:
action: close
description: "Close selected indices"
options:
delete_aliases: false
skip_flush: false
ignore_sync_failures: false
filters:
- filtertype: pattern
kind: regex
value: '^(uint-|dbl-|str-).*$'
- filtertype: age
source: name
direction: older
timestring: '%Y-%m-%d'
unit: days
unit_count: 90
超過一年的索引進行刪除
5:
action: delete_indices
description: "Delete selected indices"
options:
continue_if_exception: False
filters:
- filtertype: pattern
kind: regex
value: '^(uint-|dbl-|str-).*$'
- filtertype: age
source: name
direction: older
timestring: '%Y-%m-%d'
unit: days
unit_count: 365
curator action.yml
crontab -e
10 0 * * * curator /root/action.yml
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。