No meu CentOS, existe um Logstash, que gera muitos arquivos de log. Veja como os arquivos de log se parecem:
logstash-2023-03-09.log logstash-2023-03-20.log logstash-deprecation-2023-03-08-1.log.gz logstash-plain-2023-03-14-1.log.gz logstash-plain-2023-03-25-1.log.gz
logstash-2023-03-10.log logstash-2023-03-21.log logstash-deprecation-2023-03-09-1.log.gz logstash-plain-2023-03-15-1.log.gz logstash-plain-2023-03-26-1.log.gz
logstash-2023-03-11.log logstash-2023-03-22.log logstash-deprecation-2023-03-10-1.log.gz logstash-plain-2023-03-16-1.log.gz logstash-plain-2023-03-27-1.log.gz
logstash-2023-03-12.log logstash-2023-03-23.log logstash-deprecation.log logstash-plain-2023-03-17-1.log.gz logstash-plain-2023-03-28-1.log.gz
logstash-2023-03-13.log logstash-2023-03-24.log logstash-json.log logstash-plain-2023-03-18-1.log.gz logstash-plain.log
logstash-2023-03-14.log logstash-2023-03-25.log logstash-plain-2023-03-07-1.log.gz logstash-plain-2023-03-19-1.log.gz logstash-slowlog-json.log
logstash-2023-03-15.log logstash-2023-03-26.log logstash-plain-2023-03-09-1.log.gz logstash-plain-2023-03-20-1.log.gz logstash-slowlog-plain.log
logstash-2023-03-16.log logstash-2023-03-27.log logstash-plain-2023-03-10-1.log.gz logstash-plain-2023-03-21-1.log.gz
logstash-2023-03-17.log logstash-2023-03-28.log logstash-plain-2023-03-11-1.log.gz logstash-plain-2023-03-22-1.log.gz
logstash-2023-03-18.log logstash-2023-03-29.log logstash-plain-2023-03-12-1.log.gz logstash-plain-2023-03-23-1.log.gz
logstash-2023-03-19.log logstash-deprecation-2023-03-07-1.log.gz logstash-plain-2023-03-13-1.log.gz logstash-plain-2023-03-24-1.log.gz
Todos eles são gerados pelo Logstash.
Agora eu quero usar logrotate
neles para remover os arquivos antigos.
Aqui está minha configuração de logrotate
:
[envoy@mirror-dfh0splogv logstash]$ cat /etc/logrotate.d/logstash
/var/log/logstash/logstash-20*.log {
daily
rotate 15
compress
delaycompress
}
/var/log/logstash/logstash-plain*.log.gz {
daily
rotate 5
}
O que eu quero é bem simples. Para os logstash-20*.log
arquivos, quero manter apenas os 15 arquivos mais recentes. E para o logstash-plain*.log.gz
, quero manter apenas os 5 mais recentes.
No entanto, quando executo o comando logrotate --force /etc/logrotate.d/logstash
, todos os nomes de arquivo são anexados .1
e nenhum arquivo é removido:
logstash-2023-03-09.log.1 logstash-2023-03-20.log.1 logstash-deprecation-2023-03-07-1.log.gz logstash-plain-2023-03-13-1.log.gz.1 logstash-plain-2023-03-24-1.log.gz.1
logstash-2023-03-10.log.1 logstash-2023-03-21.log.1 logstash-deprecation-2023-03-08-1.log.gz logstash-plain-2023-03-14-1.log.gz.1 logstash-plain-2023-03-25-1.log.gz.1
logstash-2023-03-11.log.1 logstash-2023-03-22.log.1 logstash-deprecation-2023-03-09-1.log.gz logstash-plain-2023-03-15-1.log.gz.1 logstash-plain-2023-03-26-1.log.gz.1
logstash-2023-03-12.log.1 logstash-2023-03-23.log.1 logstash-deprecation-2023-03-10-1.log.gz logstash-plain-2023-03-16-1.log.gz.1 logstash-plain-2023-03-27-1.log.gz.1
logstash-2023-03-13.log.1 logstash-2023-03-24.log.1 logstash-deprecation.log logstash-plain-2023-03-17-1.log.gz.1 logstash-plain-2023-03-28-1.log.gz.1
logstash-2023-03-14.log.1 logstash-2023-03-25.log.1 logstash-json.log logstash-plain-2023-03-18-1.log.gz.1 logstash-plain.log
logstash-2023-03-15.log.1 logstash-2023-03-26.log.1 logstash-plain-2023-03-07-1.log.gz.1 logstash-plain-2023-03-19-1.log.gz.1 logstash-slowlog-json.log
logstash-2023-03-16.log.1 logstash-2023-03-27.log.1 logstash-plain-2023-03-09-1.log.gz.1 logstash-plain-2023-03-20-1.log.gz.1 logstash-slowlog-plain.log
logstash-2023-03-17.log.1 logstash-2023-03-28.log.1 logstash-plain-2023-03-10-1.log.gz.1 logstash-plain-2023-03-21-1.log.gz.1
logstash-2023-03-18.log.1 logstash-2023-03-29.log logstash-plain-2023-03-11-1.log.gz.1 logstash-plain-2023-03-22-1.log.gz.1
logstash-2023-03-19.log.1 logstash-2023-03-29.log.1 logstash-plain-2023-03-12-1.log.gz.1 logstash-plain-2023-03-23-1.log.gz.1