我每两天使用 ubuntu 14.04 一次,我需要手动删除日志文件:
/var/log/apache2/domains
2 个文件变得太大,大约 5gb,我找到了解决方案,编辑 logrotate.conf 在 etc/logrotate.conf 中找到这是我的 logrorate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# use the syslog group by default, since this is the owning group
# of /var/log/syslog.
su root syslog
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
#compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0660 root utmp
rotate 1
}
# system-specific logs may be configured here
这是我需要为每个日志文件添加的内容,如下所示:/var/log/btmp
/var/log/apache2/domains/domain.com.error.log {
missingok
daily
create 0660 root root
rotate 1
maxsize 2M
}
这样好吗?我需要为此运行 cron 还是只需将其保存在 logrotate.conf 中?
答案1
在日志文件设置中使用 maxsize 命令,如下所示
/var/log/foo {
missingok
monthly
create 0660 root root
rotate 1
maxsize 2M
}
有关尺寸限制的更多信息来自以下文档:
minsize size
Log files are rotated when they grow bigger than size bytes,
but not before the additionally specified time interval (daily,
weekly, monthly, or yearly). The related size option is simi-
lar except that it is mutually exclusive with the time interval
options, and it causes log files to be rotated without regard
for the last rotation time. When minsize is used, both the
size and timestamp of a log file are considered.
size size
Log files are rotated only if they grow bigger then size bytes.
If size is followed by k, the size is assumed to be in kilo-
bytes. If the M is used, the size is in megabytes, and if G is
used, the size is in gigabytes. So size 100, size 100k, size
100M and size 100G are all valid.
maxsize size
Log files are rotated when they grow bigger than size bytes even before
the additionally specified time interval (daily, weekly, monthly,
or yearly). The related size option is similar except that it
is mutually exclusive with the time interval options, and it causes
log files to be rotated without regard for the last rotation time.
When maxsize is used, both the size and timestamp of a log file are
considered.