본문 바로가기
Linux/운영

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

by A6K 2020. 11. 18.

유닉스 계열의 운영체제에서는 임시 파일을 '/tmp' 디렉토리에 생성한다. 이 경로에 생성한 파일은 시스템이 재부팅될 때 혹은 주기적으로 커널이 지워주기 때문에 별도로 관리를 하지 않아도 된다.

'/tmp' 디렉토리에 생성된 임시파일을 정리하는 규칙은 리눅스 구현체마다 조금씩 다르다.

Ubuntu

데비안(Debian) 계열의 리눅스의 경우 시스템이 재부팅되는 경우에 '/tmp' 디렉토리가 지워진다. 이는 기본 값이고 /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

서버를 운영하면서 우분투를 다룰일이 별로 없으므로 넘어가도록 하겠다.

RHEL

CentOS의 경우 systemd 데몬이 주기적으로 체크해서 오랫동안 사용되지 않은 파일을 정리한다. /tmp 디렉토리의 주요 목적은 운영체제 혹은 소프트웨어를 설치할 때 임시로 파일을 저장하는 것이다. 따라서 어느정도 파일이 접근되지 않았으면 /tmp 디렉토리에 있는 파일은 시스템에서 제거되는 것이 옳다.

웹 서버 같이 장시간 구동되는 서비스에서 '/tmp' 디렉토리에 뭔가를 저장해두고 사용하는 경우 CentOS의 tmpwatch 기능에 의해 파일이 삭제되는 경우가 있을 수 있다. 이런 경우에는 원치않는 에러가 발생할 수 있으니 주의해야한다. (/tmp 가 아닌 별도의 디렉토리에 임시 파일을 보관하는게 좋다)

tmpwatch 기능은 CentOS/RHEL 6에서는 Cron에 의해 호출된다. CentOS/RHEL 7에서는 systemd의 타이머에 의해 실행된다.

시스템 관리자가 tmpwatch 설정을 변경할 수도 있다. tmpwatch에 대한 설정은 /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

좀 더 세심하게 tmpwatch를 사용하려면 man tmpwatch를 실행해보자.

댓글