zoukankan      html  css  js  c++  java
  • ElasticSearch查看删除关闭索引

    curl -XDELETE 'http://10.1.2.2:9200/iis_log_2019-07'     #删除名为/iis_log_2019-07的索引

    curl -XPOST 'http://10.1.2.2:9200/iis_log_2019-07/_close/'   #关闭名为/iis_log_2019-07的索引(_open打开)

    curl  10.1.2.2:9200/_cat/indices/iis_log* #查看iis_log开头的所有索引

    curl  10.1.2.2:9200/_cat/indices/iis_log_2018-07' #查看iis_log_2018-07的索引

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import datetime,os
    from dateutil.relativedelta import relativedelta
    
    #关闭前第3个月的索引
    def index_close(indexname,hmonths):
        dt_m = (datetime.date.today() - relativedelta(months=hmonths)).strftime('%Y-%m')
        iname = '%s_%s' % (indexname,dt_m)
        url = 'http://10.1.2.2:9200/%s/_close/' % iname
        print(url)
        m = os.popen('curl -XPOST %s' % url)
        print(m.readlines())
    
    # index_close('iis_logl',3)
    
    #删除前第12个月的索引
    def index_delete(indexname,hmonths):
        dt_m = (datetime.date.today() - relativedelta(months=hmonths)).strftime('%Y-%m')
        iname = '%s_%s' % (indexname,dt_m)
        url = 'http://10.1.2.2:9200/%s' % iname
        print(url)
        m = os.popen('curl -XDELETE %s' % url)
        print(m.readlines())
    
    index_delete('iis_log',12)
    #关闭前1个月的索引,索引以天为单位产生,如sec_mail_2020-04-28)
    def index_close_days(indexname,nmonths):
            dt_m = (datetime.date.today() - relativedelta(months=nmonths)).strftime('%Y-%m')
            dt_n = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            y,m = dt_m.split('-')
            days = (calendar.monthrange(int(y),int(m)))[1]
            for d in range(days):
                d = str(d+1).rjust(2,'0')
                iname = '%s_%s-%s' % (indexname,dt_m,d)
                url = 'http://10.1.2.2:9200/%s/_close/' % iname
                # print(url)
                rs = os.popen('curl -XPOST %s' % url)
                with open(logfile,'a') as fw:
                    fw.write('%s
    %s
    %s
    '% (dt_n,url,rs.read()))
    
    #删除前3个月的索引,索引以天为单位产生,如sec_mail_2020-04-28)
    def index_delete_days(indexname,nmonths):
            dt_m = (datetime.date.today() - relativedelta(months=nmonths)).strftime('%Y-%m')
            dt_n = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            y,m = dt_m.split('-')
            days = (calendar.monthrange(int(y),int(m)))[1]
            for d in range(days):
                d = str(d+1).rjust(2,'0')
                iname = '%s_%s-%s' % (indexname,dt_m,d)
                url = 'http://10.1.2.2:9200/%s' % iname
                # print(url)
                rs = os.popen('curl -XDELETE %s' % url)
                with open(logfile,'a') as fw:
                    fw.write('%s
    %s
    %s
    '% (dt_n,url,rs.read()))
    
    index_close_days('sec_mail',1)
    index_delete_days('sec_mail',3)
  • 相关阅读:
    传输速率转换
    CentOS7 安装 oracleXE(快捷版)教程
    QEMU/KVM虚拟机安装配置
    Nginx 1.10.1 编译、配置文档(支持http_v2,TLSv1.2,openssl v1.0.2)
    IDC机房线路质量测试方案
    Iptables防火墙NAT地址转换与端口转发
    Zabbix使用点滴
    MySQL基本命令
    防DDOS攻击SHELL脚本
    12月份的英文简写
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/11202760.html
Copyright © 2011-2022 走看看