zoukankan      html  css  js  c++  java
  • 附9 elasticsearch-curator + Linux定时任务

    官网教程入口:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/index.html

    一、下载安装

    • 下载:sudo pip install elasticsearch-curator
    • 更新:sudo pip install -U elasticsearch-curator

    版本:curator4.1.0

    二、配置文件

    1、config.yml

     1 # Remember, leave a key empty if there is no value.  None will be a string,
     2 # not a Python "NoneType"
     3 client:
     4   hosts: ["127.0.0.1:9200"]
     5   url_prefix: 
     6   use_ssl: False
     7   certificate: 
     8   client_cert: 
     9   client_key: 
    10   aws_key: 
    11   aws_secret_key: 
    12   aws_region: 
    13   ssl_no_validate: False
    14   http_auth: 
    15   timeout: 30
    16   master_only: False
    17 
    18 logging:
    19   loglevel: INFO
    20   logfile: 
    21   logformat: default
    22   blacklist: ['elasticsearch', 'urllib3']
    View Code

    说明:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/configfile.html

    2、action.yml

     1 ---
     2 # Remember, leave a key empty if there is no value.  None will be a string,
     3 # not a Python "NoneType"
     4 #
     5 # Also remember that all examples have 'disable_action' set to True.  If you
     6 # want to use this action as a template, be sure to set this to False after
     7 # copying it.
     8 actions:
     9   1:
    10     action: delete_indices
    11     description: "Delete indices older than 45 days (based on index name), for logstash- prefixed indices. 
    12                   Ignore the error if the filter does not result in an actionable list of indices (ignore_empty_list) and exit cleanly"
    13     options:
    14       timeout_override: 
    15       continue_if_exception: False
    16       disable_action: False
    17     filters:
    18     - filtertype: pattern
    19       kind: prefix
    20       value: logstash-
    21       exclude: 
    22     - filtertype: age
    23       source: name
    24       direction: older
    25       timestring: '%Y.%m.%d'
    26       unit: days
    27       unit_count: 5
    28       exclude: 
    View Code

    注意:action上边那个1是action id,必须得有

    说明:

    三、测试

    curator --config ~/Desktop/server/elk/es-curator-4.1.0/config.yml ~/Desktop/server/elk/es-curator-4.1.0/action.yml

    四、做成Linux定时任务

    1、编写sh脚本:curator-delete-index.sh

    #!/bin/sh
    /usr/local/bin/curator --config /Users/enniu1/Desktop/server/elk/es-curator-4.1.0/config.yml /Users/enniu1/Desktop/server/elk/es-curator-4.1.0/action.yml
    echo "delete index success"

    注意:最好使用命令的全路径名,否则可能找不到。

    2、赋予权限

    • chmod 777 /Users/enniu1/Desktop/server/elk/es-curator-4.1.0/curator-delete-index.sh

    3、创建定时任务:crontab 

    • crontab -e:打开了vi,输入:

      • 30 16 * * * /Users/enniu1/Desktop/server/elk/es-curator-4.1.0/curator-delete-index.sh,之后保存退出vi

    • crontab -l:查看所有的root用户的定时任务

    附:crontab的文件格式

    分 时 日 月 星期 要运行的命令

    • 第1列分钟1~59
    • 第2列小时1~23(0表示子夜)
    • 第3列日1~31
    • 第4列月1~12
    • 第5列星期0~7(0和7表示星期天)
    • 第6列要运行的命令
  • 相关阅读:
    Flask使用mysql数据池
    Flask之WTForms
    Flask用Flask-SQLAlchemy连接MySQL
    Flask之中间件
    Flask之session相关
    Flask之请求和响应
    Flask路由系统与模板系统
    Flask之基本使用与配置
    Flask知识总汇
    Flask之视图函数
  • 原文地址:https://www.cnblogs.com/java-zhao/p/5900590.html
Copyright © 2011-2022 走看看