1.3 计划采取措施
常规集群模式变更为冷(6个月历史数据)热(1个月数据)集群; 热节点采用固态硬盘替换机械硬盘,提升读写性能。
2.1 预备硬件基本信息
生产环境预备的是:
3主节点:内存64G,8核,5T的机械硬盘; 3热数据节点:内存64G,16核,5T的固态硬盘; 3冷数据节点:内存64G,8核,50T的机械硬盘。

2.2 现状分析
1)主节点磁盘资源使用不完
2)主机数较多
2.3 规划逻辑
1)主节点和数据节点共用主机
2)规划数据量及所需承载节点数
热设备存储30天的数据,冷设备存储6个月的数据,生产环境目前每天产生的数据大概在200G左右,周期为30天之前的数据迁移至冷节点。 总热数据量=200G*30 约6t数据,按单个64g内存数据节点规划可以承载1.85t数据(内存存储比为30),至少需4个热数据节点。 总冷数据量=200G*6*30 约36t数据,按单个64g内存数据节点规划可以承载32t数据(内存存储比为500),至少需要2个冷数据节点。
2.4 规划优化方案
2.5 配置文件
1)生成证书,在node0执行一次即可(xpack开启)
cd elasticsearch
export JAVA_HOME=/home/shsnc/snc_product/elasticsearch/jdk ##修改JDK的环境变量
./bin/elasticsearch-certutil ca ##一直回车即可
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 ##一直回车即可
mv elastic-certificates.p12 ./config/ ##将证书文件放置到node0指定路径
mv elastic-stack-ca.p12 ./config/ ##将证书文件放置到node0指定路径
scp elastic-certificates.p12 elastic-stack-ca.p12 192.168.XXX.178:/home/shsnc/snc_product/elasticsearch/config/ ##将证书文件放置到node1指定路径
scp elastic-certificates.p12 elastic-stack-ca.p12 192.168.XXX.179:/home/shsnc/snc_product/elasticsearch/config/ ##将证书文件放置到node2指定路径
./bin/x-pack-env ##执行环境变量
./bin/x-pack-security-env ##执行环境变量
./bin/elasticsearch-setup-passwords interactive ##手动配置每个用户密码
export JAVA_HOME=/home/shsnc/snc_product/jdk ##还原JDK的环境变量
2)主节点配置
cluster.name: shsnc
node.name: node0
network.host: 192.168.XXX.177
http.port: 9200
transport.tcp.port: 9300
node.master: true
node.data: false
node.ingest: true
bootstrap.memory_lock: true
cluster.routing.allocation.same_shard.host: true
xpack.license.self_generated.type: basic
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: home/shsnc/snc_product/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: home/shsnc/snc_product/elasticsearch/config/elastic-certificates.p12
http.cors.enabled: true
http.cors.allow-origin: "*"
bootstrap.system_call_filter: false
node.attr.box_type: hot
discovery.zen.ping.unicast.hosts: ["192.168.XXX.177:9300","192.168.XXX.178:9300","192.168.XXX.179:9300"]
3)热数据节点配置
cluster.name: shsnc
node.name: node1
path.data: home/shsnc/snc_product/elasticsearch/data
network.host: 192.168.XXX.178
http.port: 9200
transport.tcp.port: 9300
node.master: false
node.data: true
node.ingest: true
bootstrap.memory_lock: true
cluster.routing.allocation.same_shard.host: true
xpack.license.self_generated.type: basic
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: home/shsnc/snc_product/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: home/shsnc/snc_product/elasticsearch/config/elastic-certificates.p12
http.cors.enabled: true
http.cors.allow-origin: "*"
bootstrap.system_call_filter: false
node.attr.box_type: hot
discovery.zen.ping.unicast.hosts: ["192.168.XXX.177:9300","192.168.XXX.178:9300","192.168.XXX.179:9300"]
4)冷数据节点配置
cluster.name: shsnc
node.name: node1
path.data: home/shsnc/snc_product/elasticsearch/data
network.host: 192.168.XXX.179
http.port: 9200
transport.tcp.port: 9300
node.master: false
node.data: true
node.ingest: true
bootstrap.memory_lock: true
cluster.routing.allocation.same_shard.host: true
xpack.license.self_generated.type: basic
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: home/shsnc/snc_product/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: home/shsnc/snc_product/elasticsearch/config/elastic-certificates.p12
http.cors.enabled: true
http.cors.allow-origin: "*"
bootstrap.system_call_filter: false
node.attr.box_type: cold
discovery.zen.ping.unicast.hosts: ["192.168.XXX.177:9300","192.168.XXX.178:9300","192.168.XXX.179:9300"]
5)部署完成后截图例子

ip: 集群中节点的 ip 地址; Heap.perecnt:堆内存的占用百分比; ram.percent:总内存的占用百分比,其实这个不是很准确,因为 buff/cache 和 available 也被当作使用内存; cpu:cpu 占用百分比; load_1m:1 分钟内 cpu 负载; load_5m:5 分钟内 cpu 负载; load_15m:15 分钟内 cpu 负载; node.role:dilm 分别表示 m表示master节点、d表示data节点、i表示ingest节点、l表示机器学习节点; master:* 代表是 master 节点,- 代表普通节点; name:节点的名称。
3.1 修改 dbl_template 模板
curl -XPUT "http://${node0_ip}:${node0_port}/_template/dbl_template?include_type_name=true" \
-H "Content-Type: application/json;charset=UTF-8" -d '
{
"index_patterns": ["dbl*"],
"settings" : {
"index" : {
"routing.allocation.require.box_type" : "hot",
"translog.durability": "async",
"translog.sync_interval":"30s",
"translog.flush_threshold_size":"1g",
"number_of_replicas" : 1,
"number_of_shards" : 3 ,
"lifecycle.name": "datastream_policy",
"max_result_window": 10000000,
"search.slowlog.threshold.fetch.info" : "1s",
"search.slowlog.threshold.fetch.warn" : "3s",
"search.slowlog.threshold.query.info" : "5s",
"search.slowlog.threshold.query.warn" : "10s",
"refresh_interval":"10s"
}
},
"mappings": {
"values": {
"properties": {
"itemid": {
"type": "long"
},
"clock": {
"format": "epoch_second",
"type": "date"
},
"value": {
"type": "double"
}
}
}
}
}'
3.2 修改 log_template 模板
curl -XPUT "http://${node0_ip}:${node0_port}/_template/log_template?include_type_name=true" \
-H "Content-Type: application/json;charset=UTF-8" -d '
{
"index_patterns": ["log*"],
"settings" : {
"index" : {
"routing.allocation.require.box_type" : "hot",
"translog.durability": "async",
"translog.sync_interval":"30s",
"translog.flush_threshold_size":"1g",
"number_of_replicas" : 1,
"number_of_shards" : 3,
"lifecycle.name": "datastream_policy",
"max_result_window": 10000000,
"search.slowlog.threshold.fetch.info" : "1s",
"search.slowlog.threshold.fetch.warn" : "3s",
"search.slowlog.threshold.query.info" : "5s",
"search.slowlog.threshold.query.warn" : "10s",
"refresh_interval":"10s"
}
},
"mappings": {
"values": {
"properties": {
"itemid": {
"type": "long"
},
"clock": {
"format": "epoch_second",
"type": "date"
},
"value": {
"fields": {
"analyzed": {
"index": true,
"type": "text",
"analyzer": "standard"
}
},
"index": false,
"type": "text"
}
}
}
}
}'
3.3 修改 text_template 模板
curl -XPUT "http://${node0_ip}:${node0_port}/_template/text_template?include_type_name=true" \
-H "Content-Type: application/json;charset=UTF-8" -d '
{
"index_patterns": ["text*"],
"settings" : {
"index" : {
"routing.allocation.require.box_type" : "hot",
"translog.durability": "async",
"translog.sync_interval":"30s",
"translog.flush_threshold_size":"1g",
"number_of_replicas" : 1,
"number_of_shards" : 3 ,
"lifecycle.name": "datastream_policy",
"max_result_window": 10000000,
"search.slowlog.threshold.fetch.info" : "1s",
"search.slowlog.threshold.fetch.warn" : "3s",
"search.slowlog.threshold.query.info" : "5s",
"search.slowlog.threshold.query.warn" : "10s",
"refresh_interval":"10s"
}
},
"mappings": {
"values": {
"properties": {
"itemid": {
"type": "long"
},
"clock": {
"format": "epoch_second",
"type": "date"
},
"value": {
"fields": {
"analyzed": {
"index": true,
"type": "text",
"analyzer": "standard"
}
},
"index": false,
"type": "text"
}
}
}
}
}'
3.4 修改 uint_template 模板
curl -XPUT "http://${node0_ip}:${node0_port}/_template/uint_template?include_type_name=true" \
-H "Content-Type: application/json;charset=UTF-8" -d '
{
"index_patterns": ["uint*"],
"settings" : {
"index" : {
"routing.allocation.require.box_type" : "hot",
"translog.durability": "async",
"translog.sync_interval":"30s",
"translog.flush_threshold_size":"1g",
"number_of_replicas" : 1,
"number_of_shards" : 3 ,
"lifecycle.name": "datastream_policy",
"max_result_window": 10000000,
"search.slowlog.threshold.fetch.info" : "1s",
"search.slowlog.threshold.fetch.warn" : "3s",
"search.slowlog.threshold.query.info" : "5s",
"search.slowlog.threshold.query.warn" : "10s",
"refresh_interval":"10s"
}
},
"mappings": {
"values": {
"properties": {
"itemid": {
"type": "long"
},
"clock": {
"format": "epoch_second",
"type": "date"
},
"value": {
"type": "long"
}
}
}
}
}'
3.5 修改 str_template 模板
curl -XPUT "http://${node0_ip}:${node0_port}/_template/str_template?include_type_name=true" \
-H "Content-Type: application/json;charset=UTF-8" -d '
{
"index_patterns": ["str*"],
"settings" : {
"index" : {
"routing.allocation.require.box_type" : "hot",
"translog.durability": "async",
"translog.sync_interval":"30s",
"translog.flush_threshold_size":"1g",
"number_of_replicas" : 1,
"number_of_shards" : 3,
"lifecycle.name": "datastream_policy",
"max_result_window": 10000000,
"search.slowlog.threshold.fetch.info" : "1s",
"search.slowlog.threshold.fetch.warn" : "3s",
"search.slowlog.threshold.query.info" : "5s",
"search.slowlog.threshold.query.warn" : "10s",
"refresh_interval":"10s"
}
},
"mappings": {
"values": {
"properties": {
"itemid": {
"type": "long"
},
"clock": {
"format": "epoch_second",
"type": "date"
},
"value": {
"fields": {
"analyzed": {
"index": true,
"type": "text",
"analyzer": "standard"
}
},
"index": false,
"type": "text"
}
}
}
}
}'
3.6 修改 baseline_template
curl -X PUT http://${node0_ip}:${node0_port}/_template/baseline_template \
-H 'Content-type':'application/json' \
-d '{
"index_patterns": [
"baseline-*"
],
"settings": {
"index": {
"routing.allocation.require.box_type" : "hot",
"translog.durability": "async",
"translog.sync_interval": "300s",
"translog.flush_threshold_size": "1g",
"number_of_replicas": 0,
"number_of_shards": 1
"max_result_window": 100000,
"search.slowlog.threshold.fetch.warn": "3s",
"search.slowlog.threshold.query.info": "5s",
"search.slowlog.threshold.query.warn": "10s",
"refresh_interval": "3600s"
}
},
"mappings": {
"dynamic" : false,
"properties": {
"itemid": {
"type": "long"
},
"min": {
"type": "double"
},
"avg": {
"type": "double"
},
"max": {
"type": "double"
},
"clock": {
"format": "epoch_second",
"type": "date"
},
"slot": {
"type": "integer"
},
"oclock":{
"type": "byte"
}
}
}
}'
3.7 修改 trends_uint-template 模板
curl -X PUT http://${node0_ip}:${node0_port}/_template/trends_uint-template \
-H 'Content-type':'application/json' \
-d '{
"trends_uint-template" : {
"order" : 0,
"index_patterns" : [
"trends_uint-*"
],
"settings" : {
"index" : {
"routing.allocation.require.box_type" : "hot",
"max_result_window" : "10000000",
"search" : {
"slowlog" : {
"threshold" : {
"fetch" : {
"warn" : "3s",
"info" : "1s"
},
"query" : {
"warn" : "10s",
"info" : "5s"
}
}
}
},
"refresh_interval" : "5s",
"number_of_shards" : "3",
"translog" : {
"flush_threshold_size" : "1g",
"sync_interval" : "30s",
"durability" : "async"
},
"number_of_replicas" : "1"
}
},
"mappings" : {
"properties" : {
"itemid" : {
"type" : "long"
},
"valueMax" : {
"type" : "long"
},
"valueMin" : {
"type" : "long"
},
"valueAvg" : {
"type" : "long"
},
"num" : {
"type" : "long"
},
"id" : {
"type" : "keyword"
},
"clock" : {
"format" : "epoch_second",
"type" : "date"
}
}
},
"aliases" : { }
}
}'
3.8 修改 trends-template 模板
curl -X PUT http://${node0_ip}:${node0_port}/_template/trends-template \
-H 'Content-type':'application/json' \
-d '{
"trends-template" : {
"order" : 1,
"index_patterns" : [
"trends-*"
],
"settings" : {
"index" : {
"routing.allocation.require.box_type" : "hot",
"max_result_window" : "10000000",
"search" : {
"slowlog" : {
"threshold" : {
"fetch" : {
"warn" : "3s",
"info" : "1s"
},
"query" : {
"warn" : "10s",
"info" : "5s"
}
}
}
},
"refresh_interval" : "5s",
"number_of_shards" : "3",
"translog" : {
"flush_threshold_size" : "1g",
"sync_interval" : "30s",
"durability" : "async"
},
"number_of_replicas" : "1"
}
},
"mappings" : {
"properties" : {
"itemid" : {
"type" : "long"
},
"valueMax" : {
"type" : "double"
},
"valueMin" : {
"type" : "double"
},
"valueAvg" : {
"type" : "double"
},
"num" : {
"type" : "long"
},
"id" : {
"type" : "keyword"
},
"clock" : {
"format" : "epoch_second",
"type" : "date"
}
}
},
"aliases" : { }
}
}'
#!/bin/bash
node0_ip=192.168.XXX.180
node0_port=9200
index_date=$(date -d '-30 day' '+%Y-%m-%d')
index_type=`echo 'uint,dbl,str,log,text,baseline' |sed 's/,/\n/g'`
for name in ${index_type};do
curl -XPUT "http://${node0_ip}:${node0_port}/${name}-${index_date}/_settings" \
-H "Content-Type: application/json;charset=UTF-8" \
-d '
{
"index.routing.allocation.require.box_type": "cold"
}'
done
冷热分离要修改的索引,请根据实际情况选择,常用的索引为:
1)监控的历史数据索引:dbl-年-月-日,uint-年-月-日,str-年-月-日,log-年-月-日,text-年-月-日; 2)监控的基线数据索引:baseline-年-月-日。

本文作者:禹 栋(上海新炬中北团队)
本文来源:“IT那活儿”公众号





