ELK运维之路(定时清理索引)
因为公司的日志存储磁盘给的很小只有2T,索引的清理策略目前无法使用,所以使用curator对ES的所以进行定期清理。
1.1 创建文件夹
mkdir -p /root/ELK/curator
chmod 777 -R /root/ELK/curator
cd /root/ELK/curator1.2 创建配置文件
vi config.ymlclient:hosts:- 172.31.51.0port: 9200url_prefix:use_ssl: False#certificate:#client_cert:#client_key:ssl_no_validate: False# 下面用户名密码修改为自己es的用户密码http_auth: elastic:xxxxxxxtimeout:master_only: True
logging:loglevel: INFOlogfile: /software/ELK/Curator/logs/curator.log #日志文件的位置自定义logformat: defaultblacklist: ['elasticsearch', 'urllib3']1.2 创建配置文件
vi action.ymlactions:1: # 操作1
..........2: # 操作 2action: delete_indices # 这里执行操作类型为删除索引description: "delete index expire date"options:ignore_empty_list: Truetimeout_override:continue_if_exception: Falsedisable_action: Falsefilters:- filtertype: patternkind: regex #使用正则匹配想要清理的indexvalue: '^(skywalking-9.4_segment-|skywalking-9.4_records-all-|skywalking-9.4_metrics-all-|skywalking-9.4_log-).*$'#value: '^(skywalking-9.4_log-).*$'# 这里匹配时间- filtertype: agesource: name # 这里不单可以根据name来匹配,还可以根据字段等,详见官方文档应该是index的名称direction: older# 这里定义的是days,还有weeks,months等,总时间为unit * unit_countunit: days #时间格式unit_count: 1 #时间定义timestring: '%Y%m%d' # 这里是跟在logstash-后面的时间的格式1.3 定时执行docker启动清理
[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