欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > linux >内容正文

linux

附9 elasticsearch-curator + Linux定时任务

发布时间:2025/3/15 linux 42 豆豆
生活随笔 收集整理的这篇文章主要介绍了 附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,必须得有

说明:

  • 例子:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/examples.html#ex_delete_indices
  • https://www.elastic.co/guide/en/elasticsearch/client/curator/current/actionfile.html

 

三、测试

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列要运行的命令

转载于:https://www.cnblogs.com/java-zhao/p/5900590.html

总结

以上是生活随笔为你收集整理的附9 elasticsearch-curator + Linux定时任务的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。