본문 바로가기
카테고리 없음

[Linux] '/tmp' 디렉토리 삭제 관련 설정, 'tmpwatch' 설정 파일

by 왕 달팽이 2020. 2. 12.
반응형

리눅스 계열의 운영체제에서 잠깐 사용하고 마는 파일은 대체로 '/tmp' 디렉토리에 넣어 놓는다. 이 경로에 넣어두면 시스템이 재부팅될 때 자동으로 지워주기 때문에 별도의 관리를 하지 않아도 된다.

'/tmp' 디렉토리를 정리하는 규칙은 리눅스 구현체마다 조금씩 다르다.

  • Debian
    • 시스템 부팅시 삭제
    • /etc/default/rcS 파일에 관련 룰이 저장됨
    • 대략 다음과 같이 생김
# /etc/default/rcS
#
# Default settings for the scripts in /etc/rcS.d/
#
# For information about these variables see the rcS(5) manual page.
#
# This file belongs to the "initscripts" package.

# delete files in /tmp during boot older than x days.
# '0' means always, -1 or 'infinite' disables the feature
#TMPTIME=0

# spawn sulogin during boot, continue normal boot if not used in 30 seconds
#SULOGIN=no

# do not allow users to log in until the boot has completed
#DELAYLOGIN=no

# be more verbose during the boot process
#VERBOSE=no

# automatically repair filesystems with inconsistencies during boot
#FSCKFIX=no

​CentOS 유저라서 우분투는 자세히 알아보지 않겠다. 

  • CentOS/RHEL
    • systemd가 주기적으로 체크해서 오랫동안 사용되지 않은 파일을 정리
    • tmpwatch 기능
      • CentOS/RHEL 6에서는 Cron에 의해 호출됨
      • CentOS.RHEL 7에서는 systemd의 타이머에 의해 실행됨

/tmp 디렉토리의 주요 목적은 운영체제 혹은 소프트웨어를 설치할 때, 임시로 파일을 저장하기 위함이다. 어느 정도 파일이 접근되지 않았으면 /tmp 디렉토리에 있는 파일은 시스템에서 제거되는게 옳다.

웹 서버 같이 장시간 떠 있는 서비스에서 /tmp 파일에 뭔가를 저장해 사용하는 경우, tmpwatch 기능에 의해 파일들이 삭제되는 경우가 있다. 이런 경우 원치않는 에러가 발생할 수 있다.

사용자가 tmpwatch 기능에 대한 설정을 변경할 수도 있다. tmpwatch에 대한 설정은 /etc/cron.daily/tmpwatch 파일에서 찾아 볼 수 있다.

# cat /etc/cron.daily/tmpwatch
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
        -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
        -X '/tmp/hsperfdata_*' 240 /tmp
/usr/sbin/tmpwatch "$flags" 720 /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
     if [ -d "$d" ]; then
        /usr/sbin/tmpwatch "$flags" -f 720 "$d"
     fi
done

man tmpwatch 명령을 실행해보면 더 자세한 정보를 얻을 수 있다.

반응형

댓글