章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • ansible系列文章

  • Kubernetes笔记

  • elk

    • elk安装
    • docker-compose安装elk
    • filebeat-log相关配置指南
    • logstash提取日志字段到kibana仪表盘展示
    • 深入理解 ELK 中 Logstash 的底层原理
    • filebeat及logstash配置
    • es索引定期删除脚本
    • logstash线上配置文件
    • elk报错问题总结
    • es备份和还原
    • ES集群与角色规划
    • ES8.8集群与Kibana部署
    • ElasticSearch可视化工具介绍
    • 使用docker构建ElasticSearch集群
  • jenkins

  • GitLabCI_CD

  • 专题
  • elk
章工运维
2023-04-20

es索引定期删除脚本

#/bin/bash
#指定日期(30天前)
Clear_Time=`date -d "30 days ago" +%Y.%m.%d`
Today=`date`

#拿到15天以前的索引,输出到以15天为时间命名的文件中 如:index.2021.10.12
curl -s -XGET -u elastic:t1Nc9SSHBiFOQK01R44l 'http://172.16.30.247:9200/_cat/indices' |awk '{print $3}'|grep $Clear_Time > /opt/clear_index/index.$Clear_Time

#声明清理动作 (最终会在crontab定义的/opt/ES_Timing_Clear/es_clear.log日志中看到操作)
echo "In $Today start to clear "$Clear_Time" 's old indices>>>>>>>>"

#对新输出到index文件内的索引 进行删除
for i in `cat /opt/clear_index/index.$Clear_Time`
    do
    sleep 3
    curl -s -XDELETE -u elastic:xxxxx http://172.16.30.247:9200/$i
done

echo "======================="
echo        "清理完成"
echo "======================="
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
微信 支付宝
上次更新: 2023/04/21, 08:57:47

← filebeat及logstash配置 logstash线上配置文件→

最近更新
01
不花一分钱从0到1建站教程
04-22
02
批量拿取多台服务器的日志文件
04-21
03
高德MCP智能体搞定旅游计划
04-19
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式