您好,登錄后才能下訂單哦!
由于公司zabbix的歷史數(shù)據(jù)存儲(chǔ)在elasticsearch中,有個(gè)需求是盡可能地把監(jiān)控的歷史數(shù)據(jù)存儲(chǔ)的長(zhǎng)一點(diǎn),最好是一年,目前的情況是三臺(tái)ES節(jié)點(diǎn),每天監(jiān)控歷史數(shù)據(jù)量有5G,目前最多可存儲(chǔ)一個(gè)月的數(shù)據(jù),超過(guò)30天的會(huì)被定時(shí)刪除,每臺(tái)內(nèi)存分了8G,且全部使用機(jī)械硬盤(pán),主分片為5,副本分片為1,查詢(xún)需求一般只獲取一周的歷史數(shù)據(jù),偶爾會(huì)有查一個(gè)月到兩個(gè)月歷史數(shù)據(jù)的需求。
為了讓ES能存儲(chǔ)更長(zhǎng)的歷史數(shù)據(jù),以及考慮到后續(xù)監(jiān)控項(xiàng)添加導(dǎo)致數(shù)據(jù)的增長(zhǎng),我將節(jié)點(diǎn)數(shù)量增加至4節(jié)點(diǎn),并將部分節(jié)點(diǎn)內(nèi)存提高,部分節(jié)點(diǎn)采用SSD存儲(chǔ)
192.168.179.133 200GSSD 4G內(nèi)存 tag:hot node.name=es1
192.168.179.134 200GSSD 4G內(nèi)存 tag:hot node.name=es2
192.168.179.135 1THDD 32G內(nèi)存 tag:cold node.name=es3 node.master=false
192.168.179.136 1THDD 32G內(nèi)存 tag:cold node.name=es4 node.master=false
對(duì)數(shù)據(jù)mapping重新建模,對(duì)str類(lèi)型的數(shù)據(jù)不進(jìn)行分詞,采用冷熱節(jié)點(diǎn)對(duì)數(shù)據(jù)進(jìn)行存儲(chǔ),前七天數(shù)據(jù)的索引分片設(shè)計(jì)為2主1副,索引存儲(chǔ)在熱節(jié)點(diǎn)上,超過(guò)七天的數(shù)據(jù)將被存儲(chǔ)在冷節(jié)點(diǎn),超過(guò)30天的索引分片設(shè)置為2主0副本,ES提供了一個(gè)shrink的api來(lái)進(jìn)行壓縮。由于ES是基于Lucene的搜索引擎,Lucene的索引由多個(gè)segment組成,每一個(gè)段都會(huì)消耗文件句柄,內(nèi)存和CPU運(yùn)行周期,段數(shù)量過(guò)多會(huì)使資源消耗變大,搜索也會(huì)變慢,這里我將前一天的索引分片強(qiáng)制合并為1個(gè)segment,修改refresh的時(shí)間間隔至60s,減少段的產(chǎn)生頻率。對(duì)超過(guò)3個(gè)月的索引進(jìn)行關(guān)閉。以上操作均使用ES的管理工具curator來(lái)定時(shí)執(zhí)行。
ES地址填寫(xiě)集群中任意一個(gè)節(jié)點(diǎn)就可以
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
熱節(jié)點(diǎn)配置
node.attr.box_type=hot
冷節(jié)點(diǎn)配置
node.attr.box_type=cold
每種數(shù)據(jù)類(lèi)型的模板都需要?jiǎng)?chuàng)建,可以根據(jù)elasticsearch.map文件來(lái)獲取api的信息,模板定義內(nèi)容有匹配的索引,主副分片數(shù)設(shè)置,refresh間隔,新建索引分配節(jié)點(diǎn)設(shè)置以及mapping的設(shè)置,這里我只是以u(píng)int和str數(shù)據(jù)的索引為例
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"
}
}
}
}
}
定義管道的作用是對(duì)寫(xiě)入索引之前的數(shù)據(jù)進(jìn)行預(yù)處理,使其按天產(chǎn)生索引。
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是否有數(shù)據(jù)
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天以前的索引分配到冷節(jié)點(diǎn)
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
將前一天的索引強(qiáng)制合并,每個(gè)分片1個(gè)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
超過(guò)30天的索引將主分片數(shù)量修改為2,副本分片為0,執(zhí)行shrink操作的節(jié)點(diǎn)不能作為master節(jié)點(diǎn)
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
對(duì)超過(guò)3個(gè)月的索引進(jìn)行關(guān)閉
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
超過(guò)一年的索引進(jìn)行刪除
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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。