logrotate는 로그 파일을 분할하지 않습니다.

logrotate는 로그 파일을 분할하지 않습니다.

OpenResty 서버 로그에서 logrotate를 작동시키려고 합니다. 내 logrotate 프로필은 /etc/logrotate.d/openresty매일 실행되어야 하며 이것이 내가 사용하려는 기본 동작입니다 sudo logrotate -vfd /etc/logrotate.d/openresty.

제가 구성한 방법은 다음과 같습니다.

/home/appname/logs/openresty/*.log /var/log/openresty/*.log {
        su root root
        size 100M
        missingok
        rotate 14
        compress
        delaycompress
        notifempty
        create 0660 root root
        sharedscripts
        prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                run-parts /etc/logrotate.d/httpd-prerotate; \
        fi \
        endscript
}

하지만 내 로그 디렉터리( ~/logs/openresty)는 다음과 같습니다.

total 1.3G
-rw-r----- 1 root     root 1.2G Jul 23 09:41 access.log.1
-rw-r----- 1 www-data adm  154K Jul 13 11:43 access.log.2.gz
-rw-r----- 1 www-data adm  159M Jul 13 11:18 access.log.3.gz
-rw-r----- 1 root     root 572K Oct  5 04:24 error.log
-rw-r----- 1 root     root  62K Jul 23 02:52 error.log.1
-rw-r----- 1 www-data adm   12K Jul 13 10:55 error.log.2.gz

보시다시피 기본 로그 파일은 100MB 제한을 훨씬 초과하며 원래대로 분할되지 않습니다. 또한 이름이 왜 access.log.1대신 지정되었는지 잘 모르겠습니다 access.log(서버에서 구성되는 방식입니다).

실행하면 sudo logrotate -v /etc/logrotate.d/openresty다음과 같은 결과가 나타납니다.

reading config file /etc/logrotate.d/openresty

Handling 1 logs

rotating pattern: /home/appname/logs/openresty/*.log /var/log/openresty/*.log  104857600 bytes (14 rotations)
empty log files are not rotated, old logs are removed
considering log /home/appname/logs/openresty/error.log
  log does not need rotating
considering log /var/log/openresty/access.log
  log needs rotating
considering log /var/log/openresty/error.log
  log does not need rotating
rotating log /var/log/openresty/access.log, log->rotateCount is 14
dateext suffix '-20201005'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/openresty/access.log.14.gz to /var/log/openresty/access.log.15.gz (rotatecount 14, logstart 1, i 14),
old log /var/log/openresty/access.log.14.gz does not exist
renaming /var/log/openresty/access.log.13.gz to /var/log/openresty/access.log.14.gz (rotatecount 14, logstart 1, i 13),
old log /var/log/openresty/access.log.13.gz does not exist
renaming /var/log/openresty/access.log.12.gz to /var/log/openresty/access.log.13.gz (rotatecount 14, logstart 1, i 12),
old log /var/log/openresty/access.log.12.gz does not exist
renaming /var/log/openresty/access.log.11.gz to /var/log/openresty/access.log.12.gz (rotatecount 14, logstart 1, i 11),
old log /var/log/openresty/access.log.11.gz does not exist
renaming /var/log/openresty/access.log.10.gz to /var/log/openresty/access.log.11.gz (rotatecount 14, logstart 1, i 10),
old log /var/log/openresty/access.log.10.gz does not exist
renaming /var/log/openresty/access.log.9.gz to /var/log/openresty/access.log.10.gz (rotatecount 14, logstart 1, i 9),
old log /var/log/openresty/access.log.9.gz does not exist
renaming /var/log/openresty/access.log.8.gz to /var/log/openresty/access.log.9.gz (rotatecount 14, logstart 1, i 8),
old log /var/log/openresty/access.log.8.gz does not exist
renaming /var/log/openresty/access.log.7.gz to /var/log/openresty/access.log.8.gz (rotatecount 14, logstart 1, i 7),
old log /var/log/openresty/access.log.7.gz does not exist
renaming /var/log/openresty/access.log.6.gz to /var/log/openresty/access.log.7.gz (rotatecount 14, logstart 1, i 6),
old log /var/log/openresty/access.log.6.gz does not exist
renaming /var/log/openresty/access.log.5.gz to /var/log/openresty/access.log.6.gz (rotatecount 14, logstart 1, i 5),
old log /var/log/openresty/access.log.5.gz does not exist
renaming /var/log/openresty/access.log.4.gz to /var/log/openresty/access.log.5.gz (rotatecount 14, logstart 1, i 4),
old log /var/log/openresty/access.log.4.gz does not exist
renaming /var/log/openresty/access.log.3.gz to /var/log/openresty/access.log.4.gz (rotatecount 14, logstart 1, i 3),
renaming /var/log/openresty/access.log.2.gz to /var/log/openresty/access.log.3.gz (rotatecount 14, logstart 1, i 2),
renaming /var/log/openresty/access.log.1.gz to /var/log/openresty/access.log.2.gz (rotatecount 14, logstart 1, i 1),
renaming /var/log/openresty/access.log.0.gz to /var/log/openresty/access.log.1.gz (rotatecount 14, logstart 1, i 0),
old log /var/log/openresty/access.log.0.gz does not exist
log /var/log/openresty/access.log.15.gz doesn't exist -- won't try to dispose of it
running prerotate script
renaming /var/log/openresty/access.log to /var/log/openresty/access.log.1
creating new /var/log/openresty/access.log mode = 0660 uid = 0 gid = 0

그러나 회전하는 것은 전혀 없습니다 ~/logs/openresty. 그것은 단지 모든 것을 무시합니다.

/var/log/openresty새로운 빈 로그가 생성되지만 access.log이전 로그는 분할되지 않고 여전히 100MB를 초과합니다.

total 379M
-rw-rw---- 1 root     root    0 Oct  5 08:51 access.log
-rw-r----- 1 root     root 366M Oct  5 08:53 access.log.1
-rw-r----- 1 root     root 5.1M Jul 23 09:41 access.log.2.gz
-rw-r----- 1 www-data adm  8.0K Jul 13 11:42 access.log.3.gz
-rw-r----- 1 root     root 8.2M Jul 13 11:18 access.log.4.gz
-rw-r----- 1 www-data adm   70K Oct  4 14:17 error.log
-rw-r----- 1 root     root  948 Jun 26 10:24 error.log.1

또한 어떤 이유로 서버 access.log.1access.log.

답변1

Logrotate는 작동하지만 openresty는 새 로그 파일에 써야 한다는 것을 모릅니다(그래서 계속해서 쓰고 있습니다 access.log.1).

postrotate구성에 스크립트를 추가 해야 합니다 .

postrotate
  /usr/local/bin/openresty -s reload
endscript

(저는 openresty에 익숙하지 않으므로 이는 openresty -s reload추측일 뿐입니다. 문서에서 찾아봐야 합니다.)

관련 정보