简介

curator 是一个官方的,可以管理elasticsearch索引的工具,可以实现创建,删除,段合并等等操作。详见官方文档

功能

curator允许对索引和快照执行许多不同的操作,包括:

  1. 从别名添加或删除索引(或两者!)
  2. 更改分片路由分配
  3. 关闭索引
  4. 创建索引
  5. 删除索引
  6. 删除快照
  7. 打开被关闭的索引
  8. 对索引执行forcemerge段合并操作
  9. reindex索引,包括来自远程集群的索引
  10. 更改索引的每个分片的副本数
  11. rollover索引
  12. 生成索引的快照(备份)
  13. 还原快照

版本

安装

有多种安装方法,本人采用yun安装,官网下载安装包:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/yum-repository.html

执行以下命令进行安装:

rpm -ivh elasticsearch-curator-5.8.-.x86_64.rpm

默认安装路径为:/opt/elasticsearch-curator,且不能移动到其它位置,命令会识别不了。

执行以下命令验证是否安装成功:

curator --help

创建配置文件

curator运行需两个配置文件config.yml(用于连接ES集群配置)、action.yml(用于配置要执行的操作),文件名称可以随意命名。

config.yml样例如下: 配置说明参考官网说明:config.yml

# Rmember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
client:
hosts: ["10.0.101.100", "10.0.101.101", "10.0.101.102"]    # es集群地址
port: 9200                               # es端口   
url_prefix:
use_ssl: False
certificate:
client_cert:
client_key:
ssl_no_validate: False
http_auth:
timeout:
master_only: False logging:
loglevel: INFO
logfile: /opt/elasticsearch-curator/logs/run.log        # 日志路径
logformat: default
blacklist: ['elasticsearch', 'urllib3']

action.yml样例如下: 配置说明参考官网说明:action.yml

# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
#
# Also remember that all examples have 'disable_action' set to True. If you
# want to use this action as a template, be sure to set this to False after
# copying it.
actions:
:
action: delete_indices        # 这里执行操作类型为删除索引
description: >-
Delete metric indices older than days (based on index name), for zou_data---
prefixed indices. Ignore the error if the filter does not result in an
actionable list of indices (ignore_empty_list) and exit cleanly.
options:
ignore_empty_list: True
filters:
- filtertype: pattern
kind: prefix
value: business-logs-        # 这里是指匹配前缀为 “order_” 的索引,还可以支持正则匹配等,详见官方文档
- filtertype: age            # 这里匹配时间
source: name              # 这里根据索引name来匹配,还可以根据字段等,详见官方文档
direction: older
timestring: '%Y-%m-%d'        # 用于匹配和提取索引或快照名称中的时间戳
unit: days               # 这里定义的是days,还有weeks,months等,总时间为unit * unit_count
unit_count: 3

以上命令删除了3天前,以business-logs-*开头的索引。

执行多个任务

注意:actions: 后面的,依次类推

:执行操作
:执行操作
:执行操作
N:执行操作

运行curator

单次运行:

curator --config config.yml action.yml 

实际生成环境中我们添加一个linux的cron定时任务:

crontab -e

加上如下命令(每天0时运行一次):

0 0 */1 * * curator --config /opt/elasticsearch-curator/config.yml /opt/elasticsearch-curator/action.yml

运行curator_cli

用法举例:curator_cli 关闭全部一天前创建的索引名称为logs_*开头的索引。

curator_cli --host 192.168.1.2 --port  close --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"days","unit_count":1},{"filtertype":"pattern","kind":"prefix","value":"logs_"}]'

总结

curator适用于基于时间或者template其他方式创建的索引,不适合单一索引存储N久历史数据的操作的场景。

例如以下场景:

elasticsearch要想实现只保留固定时间的数据,这里以7天为例,要想每个索引的数据都只保留最近7天的数据,大于7天的则删除,有两种方法:

1. 看你的索引是怎么样的,如果你的索引名称中有时间,比如logstash-2019-01-02 这样,就是每天都会生成一个新的索引,这样的话可以使用官方的Curator 工具

2. 如果你的索引中不带时间,比如,如果是根据应用或者服务名来命名的,那么注意,Curator是无法实现删除索中的某一段数据的!! 这里需要特别注意,网上很多说可以实现的,那是因为他们的索引如上面1 所说,是根据时间日期来生成的。

但实际上,很多索引都不是这样的,按正常的思维,更容易用服务名或应用名作为索引,以此来区分日志所属应用,方便日志的分析对应指定的应用。这种时候需要使用elasticsearch的api:delete_by_query来进行删除指定数据。

具体实现请参考:https://blog.csdn.net/weixin_41004350/article/details/85620572

        https://juejin.im/post/58e5de06ac502e006c254145

参考:

https://blog.csdn.net/laoyang360/article/details/85882832

ElasticSearch——Curator索引管理的更多相关文章

  1. 使用curator 来管理elasticsearch的index

    这里我们参考官网安装curator https://www.cookiesinn.org/elasticsearch_curator_delete_indices/ https://www.elast ...

  2. ElasticSearch 命令行管理工具Curator

    一.背景 elastic官网现在已经大面积升级到了5.x版本,然而针对elasticsearch的命令行管理工具curator现在仍然是4.0版本. 刚开始找到此工具,深深的怕因为版本更迭无法使用,还 ...

  3. ElasticSearch权威指南学习(索引管理)

    创建索引 当我们需要确保索引被创建在适当数量的分片上,在索引数据之前设置好分析器和类型映射. 手动创建索引,在请求中加入所有设置和类型映射,如下所示: PUT /my_index { "se ...

  4. elasticsearch系列二:索引详解(快速入门、索引管理、映射详解、索引别名)

    一.快速入门 1. 查看集群的健康状况 http://localhost:9200/_cat http://localhost:9200/_cat/health?v 说明:v是用来要求在结果中返回表头 ...

  5. elasticsearch最全详细使用教程:入门、索引管理、映射详解、索引别名、分词器、文档管理、路由、搜索详解

    一.快速入门1. 查看集群的健康状况http://localhost:9200/_cat http://localhost:9200/_cat/health?v 说明:v是用来要求在结果中返回表头 状 ...

  6. 一文带您了解 Elasticsearch 中,如何进行索引管理(图文教程)

    欢迎关注笔者的公众号: 小哈学Java, 每日推送 Java 领域干货文章,关注即免费无套路附送 100G 海量学习.面试资源哟!! 个人网站: https://www.exception.site/ ...

  7. Elasticsearch系列---生产集群的索引管理

    概要 索引是我们使用Elasticsearch里最频繁的部分日常的操作都与索引有关,本篇从运维人员的视角,来玩一玩Elasticsearch的索引操作. 基本操作 在运维童鞋的视角里,索引的日常操作除 ...

  8. ElasticSearch+Kibana 索引操作

    ElasticSearch+Kibana 索引操作 一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引 ...

  9. MySQL索引管理

    一.索引介绍 1.什么是索引 1.索引好比一本书的目录,它能让你更快的找到自己想要的内容. 2.让获取的数据更有目的性,从而提高数据库索引数据的性能. 2.索引类型介绍 1.BTREE:B+树索引 2 ...

随机推荐

  1. 搭建jenkins+python+selenium+robot framework环境

    1.安装jenkins 具体参考:https://www.cnblogs.com/dydxw/p/10538103.html 2.下载插件 我是为了方便,把有关python.selenium.robo ...

  2. Git---报错:git Please move or remove them before you can merge 解决方案

    场景: 当前在本地仓库lucky,因修改了123.txt的文件内容,需要将lucky分支push到远程Git库,在push前有其他的同事已删除了远程Git库中的123.txt文件.因此这时就产生了远程 ...

  3. Matplotlib模块的基本使用

    一.折线绘图 import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv("F:\\ml\\机器学习\\01 ...

  4. TOMCAT与http

    一.Tomcat是什么?Tomcat是一个Web应用服务器,同时也是一个Servlet/JSP容器.Tomcat作为Servlet容器,负责处理客户端请求,把请求传送给Servlet,并将Servle ...

  5. go语言-数据类型及类型之间转换

    数据类型分类 一.数据类型-基本数据类型 1.整数型(int.有符号(int8/1字节.int16/2字节.int32/4字节.int64/8字节).无符号(uint.uint8.uint16.uin ...

  6. js中使用Switch

    语法 switch(n) { case 1: 执行代码块 1 break; case 2: 执行代码块 2 break; default: n 与 case 1 和 case 2 不同时执行的代码 } ...

  7. 53、servlet3.0-简介&测试

    53.servlet3.0-简介&测试 Servlet 4.0 : https://www.jcp.org/en/jsr/summary?id=servlet+4.0

  8. HTML 009 CSS

    HTML 样式- CSS CSS (Cascading Style Sheets) 用于渲染HTML元素标签的样式.     Look! Styles and colors Manipulate Te ...

  9. 一、RabbitMQ 基础理解

    RabbitMQ,是一个使用 erlang 编写的 AMQP(高级消息队列协议)的服务实现,简单来说,就是一个功能强大的消息队列服务 概念理解: Producer: 消息发送者 RabbitMQ Vh ...

  10. Greenplum 行存、列存,堆表、AO表的原理和选择

    转载自: https://github.com/digoal/blog/blob/master/201708/20170818_02.md?spm=a2c4e.11153940.blogcont179 ...