런타임 시 로그 파일 이름을 바꿀 수 있는 권한이 거부되는 이유는 무엇입니까? logrotate
? 아래 표시된 로그 파일은 rajohns
아래 표시된 명령을 실행하여 로그인한 동일한 사용자가 소유하고 있습니다 logrotate
.
$ 고양이 /etc/logrotate.d/judgecard-api-0.0.1
/var/log/judgecard-api-0.0.1.log {
su rajohns rajohns
weekly
rotate 4
create 0777 rajohns rajohns
missingok
notifempty
postrotate
systemctl restart judgecard-api-0.0.1.service > /dev/null
endscript
}
$ ls -l /var/log/judgecard-api-0.0.1.log
-rwxrwxrwx 1 rajohns rajohns 10578 Feb 12 23:01 /var/log/judgecard-api-0.0.1.log
$ sudo logrotate -vf -s ~/logrotate_test_status_file Judgecard-api-0.0.1
reading config file judgecard-api-0.0.1
Handling 1 logs
rotating pattern: /var/log/judgecard-api-0.0.1.log forced from command line (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 1000 and egid to 1000
considering log /var/log/judgecard-api-0.0.1.log
log needs rotating
rotating log /var/log/judgecard-api-0.0.1.log, log->rotateCount is 4
dateext suffix '-20180212'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/judgecard-api-0.0.1.log.4 to /var/log/judgecard-api-0.0.1.log.5 (rotatecount 4, logstart 1, i 4),
old log /var/log/judgecard-api-0.0.1.log.4 does not exist
renaming /var/log/judgecard-api-0.0.1.log.3 to /var/log/judgecard-api-0.0.1.log.4 (rotatecount 4, logstart 1, i 3),
old log /var/log/judgecard-api-0.0.1.log.3 does not exist
renaming /var/log/judgecard-api-0.0.1.log.2 to /var/log/judgecard-api-0.0.1.log.3 (rotatecount 4, logstart 1, i 2),
old log /var/log/judgecard-api-0.0.1.log.2 does not exist
renaming /var/log/judgecard-api-0.0.1.log.1 to /var/log/judgecard-api-0.0.1.log.2 (rotatecount 4, logstart 1, i 1),
old log /var/log/judgecard-api-0.0.1.log.1 does not exist
renaming /var/log/judgecard-api-0.0.1.log.0 to /var/log/judgecard-api-0.0.1.log.1 (rotatecount 4, logstart 1, i 0),
old log /var/log/judgecard-api-0.0.1.log.0 does not exist
log /var/log/judgecard-api-0.0.1.log.5 doesn't exist -- won't try to dispose of it
renaming /var/log/judgecard-api-0.0.1.log to /var/log/judgecard-api-0.0.1.log.1
error: failed to rename /var/log/judgecard-api-0.0.1.log to /var/log/judgecard-api-0.0.1.log.1: Permission denied
switching euid to 0 and egid to 0
답변1
분명히 해당 디렉토리는 일반적으로 root:adm에 속하기 때문에 /var/log의 회전이 실패했습니다.
Apache와 다른 사람들을 보고 그들이 어떻게 하는지 볼 수 있습니다.
일반적인 접근 방식은 /var/log 아래에 하위 디렉터리를 만들고 다른 사용자를 그 소유자로 만드는 것입니다.
sudo mkdir /var/log/judgecards
chown rajohns /var/log/judgecards
그런 다음 이전 로그를 이동하고 여기에서 애플리케이션에 대한 새 로그를 만듭니다.