ElasticSearch——Curator索引管理
简介
curator 是一个官方的,可以管理elasticsearch索引的工具,可以实现创建,删除,段合并等等操作。详见官方文档
功能
curator允许对索引和快照执行许多不同的操作,包括:
- 从别名添加或删除索引(或两者!)
- 更改分片路由分配
- 关闭索引
- 创建索引
- 删除索引
- 删除快照
- 打开被关闭的索引
- 对索引执行forcemerge段合并操作
- reindex索引,包括来自远程集群的索引
- 更改索引的每个分片的副本数
- rollover索引
- 生成索引的快照(备份)
- 还原快照
版本

安装
有多种安装方法,本人采用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索引管理的更多相关文章
- 使用curator 来管理elasticsearch的index
这里我们参考官网安装curator https://www.cookiesinn.org/elasticsearch_curator_delete_indices/ https://www.elast ...
- ElasticSearch 命令行管理工具Curator
一.背景 elastic官网现在已经大面积升级到了5.x版本,然而针对elasticsearch的命令行管理工具curator现在仍然是4.0版本. 刚开始找到此工具,深深的怕因为版本更迭无法使用,还 ...
- ElasticSearch权威指南学习(索引管理)
创建索引 当我们需要确保索引被创建在适当数量的分片上,在索引数据之前设置好分析器和类型映射. 手动创建索引,在请求中加入所有设置和类型映射,如下所示: PUT /my_index { "se ...
- elasticsearch系列二:索引详解(快速入门、索引管理、映射详解、索引别名)
一.快速入门 1. 查看集群的健康状况 http://localhost:9200/_cat http://localhost:9200/_cat/health?v 说明:v是用来要求在结果中返回表头 ...
- elasticsearch最全详细使用教程:入门、索引管理、映射详解、索引别名、分词器、文档管理、路由、搜索详解
一.快速入门1. 查看集群的健康状况http://localhost:9200/_cat http://localhost:9200/_cat/health?v 说明:v是用来要求在结果中返回表头 状 ...
- 一文带您了解 Elasticsearch 中,如何进行索引管理(图文教程)
欢迎关注笔者的公众号: 小哈学Java, 每日推送 Java 领域干货文章,关注即免费无套路附送 100G 海量学习.面试资源哟!! 个人网站: https://www.exception.site/ ...
- Elasticsearch系列---生产集群的索引管理
概要 索引是我们使用Elasticsearch里最频繁的部分日常的操作都与索引有关,本篇从运维人员的视角,来玩一玩Elasticsearch的索引操作. 基本操作 在运维童鞋的视角里,索引的日常操作除 ...
- ElasticSearch+Kibana 索引操作
ElasticSearch+Kibana 索引操作 一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引 ...
- MySQL索引管理
一.索引介绍 1.什么是索引 1.索引好比一本书的目录,它能让你更快的找到自己想要的内容. 2.让获取的数据更有目的性,从而提高数据库索引数据的性能. 2.索引类型介绍 1.BTREE:B+树索引 2 ...
随机推荐
- .NET Core WebAPI IIS 部署问题
虽然建了 .NET Core 的项目,基本的一些功能也实现了,运行什么的也没有问题,但是一直没有直接发布. 今天就进行了发布测试,结果问题还是来了,只是你不去做自然就不会出现. 一.基本发布 1.先是 ...
- java继承(implements与extends)总结
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/weixin_39938767/article/details/80056922 关键字impl ...
- django-haystack 安装No local packages or working download links found for setuptools_scm
在虚拟环境中安装drf-haystack时,pip报错 Liang-2:~ langying$ pip install django-haystack Collecting django-haysta ...
- cc 视频的使用
1. 先上传视频 2.复制代码 3.贴在页面上就可以使用了 4.通过id指定播放那个视频
- 简述 CGI、FastCGI和php-FPM的区别
1.CGI是联系webserver 跟php解析器的一个桥梁 2.FastCGI是CGI改良的版本 3.php-FPM 是FastCGI 的进程管理器
- 作业调度系统PBS(Torque)的设置
1.修改/var/spool/torque/server_priv/目录下的nodes文件 Node1 np=16 gpus=4 Node2 np=16 gpus=4 ... 其中Node1为计算节点 ...
- 搭建自己的博客(九):使用shell模式批量添加博客文章并增加分页功能
想做个博客分页功能,但是没有太多的文章.所以使用shell命令行创建多篇文章. 1.打开pycharm下的terminal终端 python manage.py shell # 打开python终端 ...
- linux 下搭建ELK(rpm包版)
一.安装环境查看 注意:新的安装包要在centos 7.x的版本上安装 二.软件版本选用 注意:这边根据实际情况 jdk 1.8.0_171 #jdk安装这边就不说了 elasticsearch-7. ...
- maven管理的jsp-web应用如何添加servlet、jsp相关依赖(org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp)
明明tomcat下面就有这些包,然而还需要在maven依赖里面加上这个依赖 <!--引入Servlet开始--> <dependency> <groupId>jav ...
- Linux find,grep 命令
使用实验楼Linux环境开发,部分内容有所参考,link:https://www.shiyanlou.com/ 概述: find: 在目录中搜索文件,它的使用权限是所有用户 命令格式: find [路 ...