/tmp目錄下的hsperfdata_$user目錄被刪了,確認沒人動tmp目錄,查了一下是自動清理掉的,於是查找資料發現了tmp目錄清理規則,記錄一下
不同的 Linux 發行版其實對 /tmp 目錄的清理方式有所不同:
在某些發行版里, tmp 目錄原來只有在啟動的時候才會被清理
在 Debian-like 的系統,啟動的時候才會清理 (規則定義在 /etc/default/rcS )
在 RedHat-like 的系統,按文件存在時間定時清理 (RHEL6 規則定義在 /etc/cron.daily/tmpwatch ; RHEL7 以及 RedHat-like with systemd 規則定義在 /usr/lib/tmpfiles.d/tmp.conf , 通過 systemd-tmpfiles-clean.service 服務調用)
在 CentOS 里,是按文件存在時間清理的 (通過 crontab 的配置 /etc/cron.daily 定時執行 tmpwatch 來實現)
在 Gentoo 里也是啟動清理,規則定義在 /etc/conf.d/bootmisc ,但 Gentoo 就是不走尋常路
對於那些只能開機清理臨時文件的發行版,如果作為服務器,這種不重啟就對臨時文件目錄的垃圾不問不管的做事風格實在是很不靠譜。不過從上面其他發行版大家估計也會發現,解決此問題的關鍵就在於 tmpwatch 和定時任務的配合使用。
tmpwatch 是專門用於解決“刪除 xxx 天沒有被訪問/修改過的文件”這樣需求的命令。使用方式也極其簡單:
$ tmpwatch 30d /tmp/
注意在 Ubuntu 的 apt-get 是無法直接安裝 tmpwatch 的,tmpwatch 在 Ubuntu 里叫 tmpreaper:
$ sudoapt-get installtmpreaper
$ sudotmpreaper 30d /tmp
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 file is part of systemd.
#
# systemd is free 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 version 2.1 of the License, or
# (at your option) any later version.
# See tmpfiles.d(5) for details
# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 7d
v /var/tmp 1777 root root 30d
# 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.*
原文鏈接:https://blog.csdn.net/qq_21137441/article/details/90031390
原文鏈接:https://blog.csdn.net/Scott_kang/article/details/108419275