查询一下ES当前的线程
1
| curl es.service.consul:10004/_nodes/stats/thread_pool?pretty
|
查询集群状态
1
| curl -s "http://$ES_IP:$ES_REST_PORT/_cluster/health?pretty"
|
查询当前index的状态
1
| curl -s "http://$ES_IP:$ES_REST_PORT/_cat/indices"
|
删除索引和删除文档的区别?
删除索引是会立即释放空间的,不存在所谓的“标记”逻辑。
删除文档的时候,是将新文档写入,同时将旧文档标记为已删除。 磁盘空间是否释放取决于新旧文档是否在同一个segment file里面,因此ES后台的segment merge在合并segment file的过程中有可能触发旧文档的物理删除。
但因为一个shard可能会有上百个segment file,还是有很大几率新旧文档存在于不同的segment里而无法物理删除。想要手动释放空间,只能是定期做一下force merge,并且将max_num_segments设置为1。
仅保存近30天的数据任务分解为:
- delete_by_query设置检索近100天数据;
先执行180d,再执行 90d,再执行 60d,最后执行30d,不要一开始就30d, 可能接口会超时
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
source /data/install/utils.fc echo "before delete:" curl -s "http://$ES_IP:$ES_REST_PORT/_cat/indices/esb_api_log_community" index="esb_api_log_community" now=$(date +%Y%m%d) SAVE_DAY_30_AGO=$(date -d "$now 20 days ago" +%s%3N) curl -XPOST http://${ES_IP}:${ES_REST_PORT}/${index}/_delete_by_query -d '{ "query": { "range" : { "@timestamp" : { "lt" : '$SAVE_DAY_30_AGO' } } } }' echo "after delete_by_query:" curl -s "http://$ES_IP:$ES_REST_PORT/_cat/indices/esb_api_log_community"
|
- 执行forcemerge操作,手动释放磁盘空间。
1
| curl -XPOST "http://$ES_IP:$ES_REST_PORT/_forcemerge?only_expunge_deletes=true&max_num_segments=1"
|
check if has UNASSIGNED index
1
| curl -s "http://$ES_IP:$ES_REST_PORT/_cluster/allocation/explain?pretty"
|
index turn red 2 green
- 取node
curl -s "http://$ES_IP:$ES_REST_PORT/_nodes/process?pretty"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #!/bin/bash
source /data/install/utils.fc NODE="$1" IFS=$'\n' for line in $(curl -s "http://$ES_IP:$ES_REST_PORT/_cat/shards" | fgrep UNASSIGNED); do INDEX=$(echo $line | (awk '{print $1}')) SHARD=$(echo $line | (awk '{print $2}')) curl -XPOST "http://$ES_IP:$ES_REST_PORT/_cluster/reroute" -d '{ "commands": [ { "allocate_stale_primary": { "index": "'$INDEX'", "shard": '$SHARD', "node": "'$NODE'", "accept_data_loss" : true } } ] }' done
|
es迁移节点
将 es-1 es-2 es-3 节点迁移至 es-4 es-5 es-6
- 部署替换节点,确认节点状态正常
1
| curl http://es.service.consul:9200/_cat/nodes?v
|
- 将节点从集群路由策略中排除
1
| curl -XPUT http://es.service.consul:9200/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.exclude._ip":"es-1ip, es-2ip, es-3ip"}}'
|
- 等待迁移完成
1 2 3
| 迁移完成后数量为0 curl http://es.service.consul:9200/_cat/shards?v | grep -E 'es-[1-3]' | wc -l
|
- 迁移中确认集群状态是否正常
1 2
| curl http://es.service.consul:9200/_cluster/health?pretty curl http://es.service.consul:9200/_cluster/pending_tasks?pretty
|
步骤3 数量为0后,下线 es-1 es-2 es-3 节点
恢复路由策略
1
| curl -XPUT "http://es.service.consul:9200/_cluster/settings" -d "{ "transient" : { "cluster.routing.allocation.enable" : "all" } }"
|