原先是在 apache 的 httpd.conf 使用 logroate 來分割apache 的日誌檔。目前想要改要 rsyslog 將日誌集中到遠端主機。但目前access_log 的生成時間似乎每次都不同? 並不是想像中的每週固定時間。
[root@centos httpd]# ll |grep access_
-rw-r--r--. 1 root root 0 Apr 23 04:47 access_log
-rw-r--r--. 1 root root 102604 Nov 16 12:29 access_log-20161110
-rw-r--r--. 1 root root 278866 Dec 8 18:04 access_log-20161117
-rw-r--r--. 1 root root 140882 Apr 20 16:42 access_log-20170421
-rw-r--r--. 1 root root 137474 Apr 24 12:06 access_log-20170423
我的 /etc/logrotate.d/httpd 設定如下
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
delaycompress
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}
所以看起來是 套用 上層的 /etc/logrotate.conf 的設定,內容如下
# see "man logrotate" for details
# 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
}
# system-specific logs may be also be configured here.
而在 /etc/crontab 並沒有看到指定 logrotate 的排程,如下
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
MAILTO=""
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
請問在 centos linux 上面 每日是在甚麼時間做 logroate 呢?
旋轉週期是每週weekly. 但為什麼沒有旋轉?
這是因為logrotate並非時間到就rotate, 而是會檢視對象log紀錄:
從您的log紀錄, 每個log檔容量都很小, 而且間隔不定, 表示有好長的一段時間並無任何異動, 並沒有符合這兩個條件中的任何一個, 因此並不會"定時"rotate,