I read the man logrotate, but it's still unclear to me. My questions are mainly related to the NGINX webserver logs.
This is my current logrotate.conf:
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
and in /etc/logrotate.d I have among the others also: nginx:
/var/log/nginx/*log {
create 0644 nginx nginx
daily
rotate 10
missingok
notifempty
compress
sharedscripts
postrotate
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
endscript
}
And these are some of the .gz I can see:
access.log-20150430.gz
access.log-20150509.gz (created after ~10 days)
access.log-20150524.gz (created after ~15 days)
access.log-20150528.gz (created after ~4 days)
- Why the .gz logs are created so often and at so "random" timeframes?
- What should I change in order to have new .gz created every 6 months and/or after a .log file will be bigger than 100MB?
- With rotate 10 does it mean that if I have already 10 .gz files, then when it compresses the 11th, it will automatically delete the oldest .gz file? If yes, how can I avoid deleting logfiles? I must keep them all, even if very old.
- What is the difference between daily and rotate 10?
- Is the create permission for those files ok?
- After I change something on the logrotate.conf, should I restart some service, or the changes should be applied immediately?
Best Answer
I think logrotate manual is clear about most of your points. Here are my answers:
daily
causes log rotation to happen every day. So, you need to check why it is not happening on daily basis. For example, this can be caused by the other optionnotifempty
if the log file was empty for few days.monthly
andyearly
. For the size confitions, you can usesize 100M
.daily
specifies how often to rotate whilerotate
specifies number of log files kept.