因为公司的日志存储磁盘给的很小只有2T,索引的清理策略目前无法使用,所以使用curator对ES的所以进行定期清理。
1.1 创建文件夹
bash
mkdir -p /root/ELK/curator
chmod 777 -R /root/ELK/curator
cd /root/ELK/curator
1.2 创建配置文件
yaml
vi config.yml
client:
hosts:
- 172.31.51.0
port: 9200
url_prefix:
use_ssl: False
#certificate:
#client_cert:
#client_key:
ssl_no_validate: False
# 下面用户名密码修改为自己es的用户密码
http_auth: elastic:xxxxxxx
timeout:
master_only: True
logging:
loglevel: INFO
logfile: /software/ELK/Curator/logs/curator.log #日志文件的位置自定义
logformat: default
blacklist: ['elasticsearch', 'urllib3']
1.2 创建配置文件
yaml
vi action.yml
actions:
1: # 操作1
..........
2: # 操作 2
action: delete_indices # 这里执行操作类型为删除索引
description: "delete index expire date"
options:
ignore_empty_list: True
timeout_override:
continue_if_exception: False
disable_action: False
filters:
- filtertype: pattern
kind: regex #使用正则匹配想要清理的index
value: '^(skywalking-9.4_segment-|skywalking-9.4_records-all-|skywalking-9.4_metrics-all-|skywalking-9.4_log-).*$'
#value: '^(skywalking-9.4_log-).*$'
# 这里匹配时间
- filtertype: age
source: name # 这里不单可以根据name来匹配,还可以根据字段等,详见官方文档应该是index的名称
direction: older
# 这里定义的是days,还有weeks,months等,总时间为unit * unit_count
unit: days #时间格式
unit_count: 1 #时间定义
timestring: '%Y%m%d' # 这里是跟在logstash-后面的时间的格式
1.3 定时执行docker启动清理
bash
[root@backproject126 curator]# crontab -l
# 定时任务
0 1 * * * docker run --rm --name index_clear -v /root/ELK/curator:/.curator untergeek/curator:9.0.0 --config /.curator/config.yml /.curator/action.yml