es数据的冷热分离实验
admin
2023-02-22 21:00:08
0

注意:演示用的2节点es,有些参数配置不太合理,生产环境还需要更严格的参数设定(例如必须开启密码验证)。


系统版本:CentOS7


节点规划:

热数据节点:  192.168.2.4

温数据节点:  192.168.2.190

PS:这里就没分 hot warm cold 这种三级存储,我们一般使用 hot warm 2种即可。


我们这里使用 tar.gz 通用二进制文件


useradd es


# cat /etc/security/limits.d/elasticsearch.conf 

es - nofile 65535
es - noproc 65535
es - memlock unlimited



cd /usr/local/elasticsearch-7.4.2/

mkdir data logs 

chown es.es  /usr/local/elasticsearch-7.4.2/ -R


su - es

cd /usr/local/elasticsearch-7.4.2/


热数据节点:  192.168.2.4 的配置如下:

cat config/elasticsearch.yml 

cluster.name: my-application

node.name: node-1
node.attr.rack: r1

node.attr.temperature: hot

path.data: ./data/
path.logs: ./logs

node.master: true
node.data: true
node.ingest: true

bootstrap.memory_lock: true

network.host: 0.0.0.0
http.port: 9200

cluster.initial_master_nodes: 
  - 192.168.2.4:9300
  - 192.168.2.190:9300
  
discovery.seed_hosts:
  - 192.168.2.4
  - 192.168.2.190
  
gateway.recover_after_nodes: 1
#action.destructive_requires_name: true
############# xpack 的配置项 ####################
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.include: access_denied, access_granted, anonymous_access_denied, authentication_failed,connection_denied, tampered_request, run_as_denied, run_as_granted
xpack.security.audit.logfile.emit_node_host_address: true
xpack.security.audit.logfile.emit_node_host_name: true
xpack.sql.enabled: true
xpack.ilm.enabled: true


温数据节点:  192.168.2.190

cat config/elasticsearch.yml 

cluster.name: my-application

node.name: es11
node.attr.rack: r1

node.attr.temperature: warm

path.data: ./data/
path.logs: ./logs

node.master: true
node.data: true
node.ingest: true

bootstrap.memory_lock: true

network.host: 0.0.0.0
http.port: 9200

cluster.initial_master_nodes: 
  - 192.168.2.4:9300
  - 192.168.2.190:9300
  
discovery.seed_hosts:
  - 192.168.2.4
  - 192.168.2.190
gateway.recover_after_nodes: 1

#action.destructive_requires_name: true

############# xpack 的配置项 ####################
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.include: access_denied, access_granted, anonymous_access_denied, authentication_failed,connection_denied, tampered_request, run_as_denied, run_as_granted
xpack.security.audit.logfile.emit_node_host_address: true
xpack.security.audit.logfile.emit_node_host_name: true
xpack.sql.enabled: true
xpack.ilm.enabled: true


启动脚本: 

# cat start.sh 

# es 依赖高版本的jdk 需要先export下
export JAVA_HOME=./jdk/
nohup ./bin/elasticsearch >/dev/null 2>&1 &



停止脚本:

# cat stop.sh 

kill $(jps| grep Elasticsearch | awk '{print $1}')



创建索引,并将数据搬迁到hot节点:

curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19?pretty
curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19/_settings -d '
{
  "index.routing.allocation.require.temperature": "hot"
}'


es数据的冷热分离实验



如果要将 index-2019.10.19 的数据搬迁到温节点,我们使用下面的这个命令就行

curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19/_settings -d '
{
  "index.routing.allocation.require.temperature": "warm"
}'



流程跑通后,我们可以写个脚本,作用有2个:

1、提前创建后一天的索引,并确保将其落到hot节点

2、将7天前的索引,打标签,存放到es的warm节点(大容量HDD磁盘):

#!/bin/bash

# 创建新的索引,语句类似下面5行,需要根据自己情况修改(建议使用for循环创建index)
# curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19?pretty
# curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19/_settings -d '
# {
#   "index.routing.allocation.require.temperature": "hot"
# }'

day=$(date +"%Y.%m.%d" -d -7day)

curl -H 'Content-Type: application/json'  -X PUT http://192.168.2.4:9200/*-${day}/_settings -d '
{
  "index.routing.allocation.require.temperature": "warm"
}'


另外, 在es7里面 提供 index-lifecycle-management 这个功能, 我们在kibana 界面里面就可以进行配置。 具体可以查阅es官方的文档(个人还是比较喜欢用上面的这种脚本的方案)。



相关内容

热门资讯

前微软首席技术专家创办,智用开... 瑞财经 李兰 近日,据智用开物微信公众号,智用开物获近亿元天使+轮融资,由老股东瑞枫资本领投,创享投...
男子再婚后做全职丈夫,照顾岳父... 再婚相伴十余载,放弃工作悉心照料岳父多年,默默扛起家庭重任,感情走向破裂面临离婚,家务劳动与养老照料...
让每一粒粮食住上“空调房” 从田间到餐桌,粮食不仅要种得好,更要存得好。记者从国家粮食和物资储备局了解到,今年,我国将深入推进绿...
涉AI,中方在联合国表态 联合国举行AI主题会议,中方呼吁深化国际合作。 5日,中国、赞比亚常驻联合国代表团和中国科学技术协会...
5年1.3万亿!Anthrop... ▲头图由AI辅助生成 智东西 作者 | 陈佳 编辑 | 漠影 智东西5月6日消息,今日,据The I...
美政府为何酝酿收紧AI监管? 据美国多家媒体日前报道,美国政府正考虑对人工智能(AI)模型在公开发布前实施安全审查,并酝酿通过行政...
从无人机到卡车,大疆第二曲线“... 【文/观察者网 张家栋 编辑/高莘】 据《南华早报》5月5日报道,大疆旗下智能驾驶品牌卓驭(ZYT...
东京审判28名甲级战犯罪行全记... 1946年5月3日远东国际军事法庭在东京开庭11国法官,818次开庭419名证人出庭4336件证据4...
男子称爷爷向天津美院捐赠40件... 近日,康先生在社交平台发布视频称,其爷爷康建章于1996年向天津美术学院捐赠的40件书画作品,自己希...
以军总参谋长:在伊朗仍有一系列... △以色列国防军总参谋长扎米尔(资料图)当地时间5月6日,以色列国防军总参谋长扎米尔表示,以军与美军的...