简介

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. AtCoder Grand Contest 032 B - Balanced Neighbors——构造

    题意 B - Balanced Neighbors 给定一个整数 $N$($3\leq N \leq 100$),构造一个顶点编号为 $1...N$ 的无向图,需满足如下两个条件: 简单图且连通 存在 ...

  2. yum安装出现No package crontabs available解决办法

    其意思是:yum中不存在这个包 所以解决办法是 1.更新yum   更新yum仓库: yum -y update 2.查看包名在yum中是什么   yum search  all crontabs

  3. vue init webpack-simple

    vue init webpack-simple  .. 将我们的项目更加方便,更有助于开发者快速开发. vue init webpack-simple的项目默认打包后之后一个html和一个js文件,而 ...

  4. Connecting Graph

    Given n nodes in a graph labeled from 1 to n. There is no edges in the graph at beginning. You need ...

  5. emit传多个参数

    https://blog.csdn.net/lxy123456780/article/details/87811113 子组件: this.$emit('closeChange',false,true ...

  6. react图片预览插件尝试

    npm install react-zmage -S https://blog.csdn.net/Wcharles666/article/details/90262525 启动报错 直接执行  npm ...

  7. P4092 [HEOI2016/TJOI2016]树

    题目描述 在2016年,佳媛姐姐刚刚学习了树,非常开心.现在他想解决这样一个问题:给定一颗有根树(根为1),有以下两种操作: 标记操作:对某个结点打上标记(在最开始,只有结点1有标记,其他结点均无标记 ...

  8. MyBatis中in 的使用方法

    在MyBatis中使用in关键字参数为集合时,需要使用到foreach标签. 下面详细介绍以下foreach标签的几个参数 foreach属性.png 实例: <select id=" ...

  9. java关于Integer设置-128到127的静态缓存

    今天在一个java群里,看到有个群友问到如下为什么第一个为true,第二个为false. System.out.println(Integer.valueOf("50")==Int ...

  10. 使用WebSocket实现服务端和客户端的通信

    开发中经常会有这样的使用场景.如某个用户在一个数据上做了xx操作, 与该数据相关的用户在线上的话,需要实时接收到一条信息. 这种可以使用WebSocket来实现. 另外,对于消息,可以定义一个类进行固 ...