log rotate 不拆分文件并减少它

log rotate does not split the file and reduce it

我正在尝试在我的流式处理作业中实施日志轮换。这是我的测试配置文件。

/home/hadoop/first* {
    daily
    rotate 3
    size 1M
    compress
    delaycompress
}

当我尝试 运行 logrotate 时,所发生的只是日志文件 first_run.out 附加了 .1 文件没有拆分,拆分文件也没有压缩。

编辑: 当我尝试使用 -v 选项时,我得到这个日志

[hadoop@ip-10-27-90-253 ~]$ sudo logrotate -vf /etc/logrotate.d/apache2.conf
reading config file /etc/logrotate.d/apache2.conf
reading config info for /home/hadoop/first* 

Handling 1 logs

rotating pattern: /home/hadoop/first*  forced from command line (3 rotations)
empty log files are rotated, old logs are removed
considering log /home/hadoop/first_run.out.1.1.1.1.1.1
  log needs rotating
rotating log /home/hadoop/first_run.out.1.1.1.1.1.1, log->rotateCount is 3
dateext suffix '-20190411'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /home/hadoop/first_run.out.1.1.1.1.1.1.1 does not exist
renaming /home/hadoop/first_run.out.1.1.1.1.1.1.3.gz to /home/hadoop/first_run.out.1.1.1.1.1.1.4.gz (rotatecount 3, logstart 1, i 3), 
old log /home/hadoop/first_run.out.1.1.1.1.1.1.3.gz does not exist
renaming /home/hadoop/first_run.out.1.1.1.1.1.1.2.gz to /home/hadoop/first_run.out.1.1.1.1.1.1.3.gz (rotatecount 3, logstart 1, i 2), 
old log /home/hadoop/first_run.out.1.1.1.1.1.1.2.gz does not exist
renaming /home/hadoop/first_run.out.1.1.1.1.1.1.1.gz to /home/hadoop/first_run.out.1.1.1.1.1.1.2.gz (rotatecount 3, logstart 1, i 1), 
old log /home/hadoop/first_run.out.1.1.1.1.1.1.1.gz does not exist
renaming /home/hadoop/first_run.out.1.1.1.1.1.1.0.gz to /home/hadoop/first_run.out.1.1.1.1.1.1.1.gz (rotatecount 3, logstart 1, i 0), 
old log /home/hadoop/first_run.out.1.1.1.1.1.1.0.gz does not exist
log /home/hadoop/first_run.out.1.1.1.1.1.1.4.gz doesn't exist -- won't try to dispose of it
renaming /home/hadoop/first_run.out.1.1.1.1.1.1 to /home/hadoop/first_run.out.1.1.1.1.1.1.1

语法正确。

也许您的文件大小小于 1 MB?

使用-v键,帮你解决问题。例如:logrotate -v logrotateconfig.file


UPD:您的名称文件为 logrotate 生成递归。

first_run.out.1.1.1.1.1.1.1
first_run.out.1.1.1.1.1.1.1.1
first_run.out.1.1.1.1.1.1.1.1.1
....

需要在 logrotate 配置中更精确地指定文件名。