로그 오류 통계 실패: LogRotation 중 권한이 거부되었습니다.

로그 오류 통계 실패: LogRotation 중 권한이 거부되었습니다.

새로운 CentOS 6.0 서버를 설치한 후 logrotate는 완벽하게 작동합니다. 그러던 어느 날 커널 패닉으로 인해 서버를 하드 부팅해야 했고, 로그 회전으로 인해 더 이상 로그가 회전하지 않습니다.

그래서 수동으로 로그 회전을 강제하기 위해 별도의 cron 항목을 만들고 출력을 로그 파일로 리디렉션하고 각 파일에 대해 다음 줄을 얻었습니다.

rotating pattern: /home/mail3/log/popMailProcessing.log  forced from command line (60 rotations)
empty log files are rotated, old logs are removed
considering log /home/mail3/log/popMailProcessing.log
error: stat of /home/mail3/log/popMailProcessing.log failed: Permission denied

그러나 명령줄에서 수동으로 로그 회전을 수행하면 완벽하게 작동합니다. 명령줄에서 사용하는 명령은 다음과 같습니다.

logrotate -v -f /etc/logrotate.d/mail3-logs

내 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.

cron 작업을 통해 logrotate에서 사용하는 로그 회전 파일은 다음과 같습니다.

dateext
/home/mail3/log/pop.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/oc4j.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/incoming.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/mailpro.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/imap.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/outgoing.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/smtpout.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/retry.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/mailinglist.log {
        daily
        rotate 60
        copytruncate
        compress
}
/home/mail3/log/migrate.log {
        daily
        rotate 60
        copytruncate
        compress
}

내 crontab 항목은 다음과 같습니다.

03 00 * * * root /usr/sbin/logrotate -f -v /etc/logrotate.d/mail3-logs &>> /var/log/logrotate/rotate.log

SELinux가 시행되고 있으며 하드 부팅 전에도 시행됩니다. 로그가 저장되는 디렉터리의 소유자는 루트이며 해당 디렉터리는 모든 권한을 갖습니다.

권한 거부 오류를 일으키는 단서가 있습니까?

답변1

원래 오류 메시지는 실행 중인 항목과 관련이 있습니다 logrotate.

rotating pattern: /home/mail3/log/popMailProcessing.log  forced from command line (60 rotations)
empty log files are rotated, old logs are removed
considering log /home//log/popMailProcessing.log
error: stat of /home/mail3/log/popMailProcessing.log failed: Permission denied

이 경로들은 무엇을 하게 될까요 /home/mail3/log/*? 또한 누락된 줄은 무엇입니까 /home//log/popMailProcessing.log? 귀하의 질문은 실제 상황을 보여주는 것 같습니다.

디버깅 문제

다음 줄을 쉘 스크립트에 넣으세요 logrotate.sh:

#!/bin/bash
/usr/sbin/logrotate -f -v /etc/logrotate.d/mail3-logs &>> /var/log/logrotate/rotate.log

실행 가능하게 만들고 cron에서 실행하십시오.

03 00 * * * root strace -s 2000 -o /tmp/strace.log /path/to/logrotate.bash

출력을 보면 어떤 권한 문제가 문제를 일으키는지 확인할 수 있습니다.

편집 #1

OP와 대화한 후 그는 위의 디버깅 기술을 통해 SELinux가 활성화되었음을 발견했다고 언급했습니다. 그는 이전에 명령으로 비활성화했기 때문에 왜 이런 일이 발생하는지 혼란스러워했습니다 setenforce 0.

이런 방식으로 SELinux를 비활성화하면 다음에 재부팅할 때까지 그대로 유지됩니다. SELinux의 기본 모드는 Fedora/CentOS에서 다음 파일로 지정됩니다.

$ cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#   enforcing - SELinux security policy is enforced.
#   permissive - SELinux prints warnings instead of enforcing.
#   disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#   targeted - Only targeted network daemons are protected.
#   strict - Full SELinux protection.
SELINUXTYPE=targeted

SELinux를 영구적으로 비활성화하려면 이 줄을 , , 3 SELINUX=..가지 상태 중 하나로 변경해야 합니다 .enforcingpermissivedisabled

그러나 시간을 내어 SELinux가 이러한 로그 파일이 있는 디렉터리에 대한 액세스를 허용하지 않는 이유를 이해하고 SELinux가 이 액세스를 허용하도록 적절한 컨텍스트를 추가하는 것이 좋습니다. SELinux는 이를 사용하는 Linux 배포판에서 추진되는 계층형 보안 모델의 중요한 부분이며 이를 맹목적으로 비활성화하면 중요한 계층 중 하나가 제거됩니다.

인용하다

답변2

나는 SELinux를 비활성화하는 것이 최선의 선택이라고 생각하지 않습니다. 더 나은 해결책은 정책을 만들고 적용하는 것이라고 생각합니다. 다음은 다른 전략에 대해 이를 수행하는 방법에 대한 예입니다.http://www.greenvalleyconsulting.org/2015/01/28/installing-coldfusion-11-on-centos-6-6-with-selinux-enforcing/. 링크에 설명된 대로 httpd_t 대신 logrotate_t 전략에도 동일한 개념이 적용됩니다.

링크에서policycoreutils-python을 설치하는 단계를 참조하세요. 그런 다음 실행

grep logrotate /var/log/audit/audit.log | audit2why

audit2allow -a

logrotate_t를 찾으세요. 다음과 같을 가능성이 더 높습니다.

#============= logrotate_t ============== 
allow logrotate_t file_t:file getattr;

그런 다음 실행

audit2allow -a -M logrotate_t

semodule -i logrotate_t.pp

chcon -R -t logrotate_t /[your log file location]/*.log

답변3

긴급 상황에서는 다음 방법으로 이 문제를 해결할 수 있습니다.

semanage permissive -a logrotate_t

이 시간은logrotate_selinux 매뉴얼 페이지.

을 사용하여 메시지(최종적으로 처리해야 함)를 계속 볼 수 있습니다 audit2allow.

답변4

su group user블록 외부의 사용 으로 인해 이 오류가 발생했습니다 {…}. 의 다른 규칙과 충돌하는 것 같습니다 /etc/logrotate.d/.

사용자가 소유한 파일에 대한 규칙에서 및 를 사용하여 su root root문제를 해결했습니다 .create 664 www-data www-datawww-data

이렇게 하면 root파일이 회전하지만 www-data기본 파일이 있습니다.

관련 정보