tmp ubuntu 自动删除吗_转:Linux系统下/tmp目录文件重启后自动删除,不重启自动删除10天前的/TMP的文件...

本文探讨了Ubuntu和Solaris系统中,/tmp目录文件在重启后自动删除的原因,以及CentOS系统中tmpwatch脚本如何删除10天前的文件。在CentOS7中,系统使用systemd-tmpfiles进行临时文件管理,可以通过配置tmp.conf文件来调整清理规则。
摘要由CSDN通过智能技术生成

ubuntu和solaris系统

/tmp目录文件重启后自动删除现在知道有ubuntu和solaris系统

source:http://blog.chinaunix.net/uid-26212859-id-3567875.html

经常会把临时性的log或抓包等文件放在/tmp目录下,重启后发现文件都丢失了。查下资料发现,可以通过设置解决这个问题。

在/etc/default/目录下有个rcS文件,文件内容如下:

1 #2 # /etc/default/rcS3 #4 # Default settings for the scripts in /etc/rcS.d/

5 #6 # For information about these variables see the rcS(5) manual page.7 #8 # This file belongs to the "initscripts"package.9

10

11 TMPTIME=0

12 SULOGIN=no13 DELAYLOGIN=no14 UTC=yes15 VERBOSE=no16 FSCKFIX=no17 RAMRUN=no18 RAMLOCK=no

红色字体TMPTIME=0。值为0表示重启后删除文件,值为-1就不会自动删除文件,职位正整数表示/tmp目录下文件保留时间。

Centos系统

关于linux tmp下文件自动删除的问题

source:http://www.tuicool.com/articles/6Jj6rq

关于linux tmp下文件自动删除的问题

近日发现有一台机器tmp 下放置的文件无辜丢失,而且排查发现是自动丢失,并且,只是删除10天之前的文件….

本来以为是哪位写了一个自动执行脚本, find 了一下10天前的文件删除了….

结果,排查所有用户的crontab 计划,没有任何用户执行了自动脚本

监测了一下服务器登录情况,在删除文件期间也没有任何人登录

最终,通过不懈的百度,终于找到正解

CentOS6

从/var/log/cron 日志中发现,服务器除了调用用户的计划任务外,还会执行系统自己的,比如:

/etc/cron.hourly

/etc/cron.daily

进入 /etc/cron.daily ,可以看到一个tmpwatch

#! /bin/shflags=-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_*' -X '/tmp/.hdb*lock' -X '/tmp/.sapstartsrv*.log'\

10d/tmp/usr/sbin/tmpwatch "$flags" 30d /var/tmpfor d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do

if [ -d "$d" ]; then

/usr/sbin/tmpwatch "$flags" -f 30d "$d"

fi

done

可以看到调用了一个叫tmpwatch 的脚本,并且,我们可以看到传入参数中 对我们有意义的有 /tmp  240  ;然后我们 man tmpwatch

#mantmpwatch

SYNOPSIS

tmpwatch [-u|-m|-c] [-MUadfqstvx] [--verbose] [--force] [--all]

[--nodirs] [--nosymlinks] [--test] [--fuser] [--quiet]

[--atime|--mtime|--ctime] [--dirmtime] [--exclude ]

[--exclude-user ]

有一个 hours  240 = 10*24 整好是10天

具体原因是 tmp是一个特殊的文件夹,系统会自动清理,所以大家最好不要把文件放到这个地方,被清理了就不好了

CentOS7

CentOS6以下系统(含)使用watchtmp + cron来实现定时清理临时文件的效果,这点在CentOS7发生了变化,在CentOS7下,系统使用systemd管理易变与临时文件,与之相关的系统服务有3个:

systemd-tmpfiles-setup.service :Create Volatile Files and Directories

systemd-tmpfiles-setup-dev.service:Create static device nodes in /dev

systemd-tmpfiles-clean.service :Cleanup of Temporary Directories

相关的配置文件也有3个地方:

/etc/tmpfiles.d/*.conf

/run/tmpfiles.d/*.conf

/usr/lib/tmpfiles.d/*.conf

/tmp目录的清理规则主要取决于/usr/lib/tmpfiles.d/tmp.conf文件的设定,默认的配置内容为:

# This fileis part of systemd.

#

# systemd isfree software; you can redistribute it and/or modify it

# under the terms of the GNU Lesser General Public License as published by

# the Free Software Foundation; either version2.1of the License, or

# (at your option) any later version.

# See tmpfiles.d(5) fordetails

# Clear tmp directories separately, tomakethem easier to override

v/tmp 1777 root root 10d # 清理/tmp下10天前的目录和文件

v/var/tmp 1777 root root 30d # 清理/var/tmp下30天前的目录和文件

# Exclude namespace mountpoints created with PrivateTmp=yes

x/tmp/systemd-private-%b-*X/tmp/systemd-private-%b-*/tmp

x/var/tmp/systemd-private-%b-*X/var/tmp/systemd-private-%b-*/tmp

我们可以配置这个文件,比如你不想让系统自动清理/tmp下以tomcat开头的目录,那么增加下面这条内容到配置文件中即可:

x /tmp/tomcat.*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值