iT邦幫忙

0

請問logrotate 的時間為什麼不是固定的呢?

原先是在 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 呢?

  • 環境: centos 6.8
haoming iT邦好手 1 級 ‧ 2017-04-24 12:37:19 檢舉
補充說明... 其實 我主要是 希望 apache log 內的內容 是分割當日的日誌 但目前看起來 透過 系統logrotate 的並沒有如我期望的讓每個檔案 就是依照日期分割。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
bizpro
iT邦大師 1 級 ‧ 2017-04-24 13:17:18
最佳解答

旋轉週期是每週weekly. 但為什麼沒有旋轉?

這是因為logrotate並非時間到就rotate, 而是會檢視對象log紀錄:

  1. 是否有週期期限最後一天的異動.
  2. 是否有超過設定的容量(size).

從您的log紀錄, 每個log檔容量都很小, 而且間隔不定, 表示有好長的一段時間並無任何異動, 並沒有符合這兩個條件中的任何一個, 因此並不會"定時"rotate,

WilliamHuang
iT邦研究生 1 級 ‧ 2017-04-24 12:37:32
【**此則訊息已被站方移除**】

我要發表回答

立即登入回答