只保留七天的索引

shell版

#!/bin/bash
#hexm@2016.10.
#只保留一周es日志 logName=(
-nginxaccesslog
-nginxerrorlog
-phperrorlog
)
#es配置文件
config=/usr/local/app/elasticsearch-2.3./config/elasticsearch.yml
#日期
time=`date -d "7 day ago" +-%Y.%m.%d`
ip=`grep "network.host" ${config} | awk '{print$2}'`
port=`grep "http.port" ${config} | awk '{print$2}'`
#es监听的ip和端口
ipPort=${ip}:${port}
#循环删除
for ((i=;i<${#logName[*]};i++))
do
name=${logName[$i]}${time}
curl -XDELETE "http://${ipPort}/${name}"
done

python版

#!/usr/bin/python
# -*- coding:utf-8 -*-
#hexm@2016.10.18
#只保留一周es日志
#
import commands
from datetime import datetime, timedelta config = "/usr/local/app/elasticsearch-2.3.4/config/elasticsearch.yml"
logName = ('51-nginxaccesslog', '51-nginxerrorlog', '51-phperrorlog')
ip = commands.getoutput(""" grep "network.host" %s | awk '{print$2}' """ % config)
port = commands.getoutput(""" grep "http.port" %s | awk '{print$2}' """ % config) tm = datetime.now() + timedelta(days=-7)
tm = tm.strftime("%Y.%m.%d") for name in logName:
url = "http://" + str(ip) + ":" + str(port) + "/" + name + "-" + tm
print url

每天凌晨三点执行

###删除es索引
* * * /bin/bash /root/bin/delete_es.sh &>/dev/null &

删除elasticsearch索引脚本的更多相关文章

  1. 定时删除elasticsearch索引

    从去年搭建了日志系统后,就没有去管它了,最近发现大半年各种日志的index也蛮多的,就想着写个脚本定时清理一下,把一些太久的日志清理掉. 脚本思路:通过获取index的尾部时间与我们设定的过期时间进行 ...

  2. 自动删除 Elasticsearch 索引

    #!/bin/bash # author: Wang XiaoQiang# crontab -e# 0 0 * * * /root/script/del_esindex.sh # auto delet ...

  3. Elasticsearch 索引、更新、删除文档

    一.Elasticsearch 索引(新建)一个文档的命令: curl XPUT ' http://localhost:9200/test_es_order_index/test_es_order_t ...

  4. Elasticsearch索引的操作,利用kibana(如何创建/删除一个es的索引?)

    我们已经通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射.现在我们需要对这个建立索引的过程做更多的控制:我们想要确保这个索引有数量适中的主分 ...

  5. Elasticsearch索引的操作,利用kibana 创建/删除一个es的索引及mapping映射

    索引的创建及删除 1. 通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射. 利用Kibana提供的DevTools来执行命令,要创建一个索引 ...

  6. ES3:ElasticSearch 索引

    ElasticSearch是文档型数据库,索引(Index)定义了文档的逻辑存储和字段类型,每个索引可以包含多个文档类型,文档类型是文档的集合,文档以索引定义的逻辑存储模型,比如,指定分片和副本的数量 ...

  7. Elasticsearch索引和文档操作

    列出所有索引 现在来看看我们的索引 GET /_cat/indices?v 响应 health status index uuid pri rep docs.count docs.deleted st ...

  8. Elasticsearch 索引的全量/增量更新

    Elasticsearch 索引的全量/增量更新 当你的es 索引数据从mysql 全量导入之后,如何根据其他客户端改变索引数据源带来的变动来更新 es 索引数据呢. 首先用 Python 全量生成 ...

  9. windows系统中 利用kibana创建elasticsearch索引等操作

    elasticsearch之借用kibana平台创建索引 1.安装好kibana平台 确保kibana以及elasticsearch正常运行 2.打开kibana平台在Dev Tools 3.创建一个 ...

随机推荐

  1. tornado和django的结合使用 tornado Server for django WSGI APP

    #!/usr/bin/env python # Run this with # Serves by default at # http://localhost:8080/hello-tornado a ...

  2. MVC认知路【点点滴滴支离破碎】【二】----Razor服务器标记语言

    Razor 代码块包含在 @{....}中 内嵌表达式(变量和函数)已 @ 开头 代码语句用分号结束 变量使用 var 关键字声明 字符创用引号括起来 C#代码区分大小写 C#文件的扩展是 .csht ...

  3. 1008win7与虚拟机中的linux共享文件的(详细)方法

    转自http://jingyan.baidu.com/article/ca00d56c74dde4e99eebcfd2.html 好东西一起分享 win7与虚拟机中的linux共享文件的(详细)方法 ...

  4. 收藏Javascript中常用的55个经典技巧

    1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu ...

  5. android 入门笔迹(1)

    环境搭建JDK,JRE,Android SDK,ADT,Eclipse,安卓模拟器AVD xml控制UI界面  Java代码控制UI界面  XML与Java混合控制UI界面  UI:userinter ...

  6. webService访问加密-Soapheader

    WebService head加密,可以对 WebService设置访问用户名和密码,增强 WebService的安全性 使 WebService只能被授权用户使用. 具体实现步骤: 1. 定义一个  ...

  7. Entity Framework Code First (六)存储过程

    声明:本文只针对 EF6+ 默认情况下,Code First 对实体进行插入.更新.删除操作是直接在表上进行的,从 EF6 开始你可以选择使用存储过程(Stored Procedures) 简单实体映 ...

  8. mysql-存储过程案例-存储过程中创建表和修改表数据

    -- 本存储过程有特殊执行循环数量的要求,是对security_market_history表进行修正 -- 判断存储过程是否存在 drop PROCEDURE if exists proc_secu ...

  9. jquery-追加元素

    一.在元素内部/外部追加元素 append,prepend:添加到子元素 before,after:作为兄弟元素添加 html: <div id="content"> ...

  10. 【凯子哥带你学Framework】Activity启动过程全解析

    It’s right time to learn Android’s Framework ! 前言 学习目标 写作方式 主要对象功能介绍 主要流程介绍 zygote是什么有什么作用 SystemSer ...