(Past correspondence memo)
I want to prevent the bottom of / tmp from being deleted without permission. Tmpwatch is missing from RHEL7. It seems that systemd-tmpfiles-clean.timer is cleaning the tmp area.
The configuration file is here: /usr/lib/tmpfiles.d/tmp.conf
Copy this file to /etc/tmpfiles.d/ You may want to rewrite it to exclude / tmp / *.
VM (CetnOS7) (Production VM is RHEL7) XenServer
Confirm with man command
# man tmpfiles.d
--------------------------------------------
CONFIGURATION FORMAT
Files in /etc/tmpfiles.d override files with the same name in /usr/lib/tmpfiles.d and /run/tmpfiles.d.
Files in /run/tmpfiles.d override files with the same name in /usr/lib/tmpfiles.d.
Packages should install their configuration files in /usr/lib/tmpfiles.d.
Files in /etc/tmpfiles.d are reserved for the local administrator, who may use this logic to override the configuration files installed by vendor packages.
All configuration files are sorted by their filename in lexicographic order, regardless of which of the directories they reside in.
If multiple files specify the same path, the entry in the file with the lexicographically earliest name will be applied.
All other conflicting entries will be logged as errors.
When two lines are prefix and suffix of each other, then the prefix is always processed first, the suffix later.
Otherwise, the files/directories are processed in the order they are listed.
If the administrator wants to disable a configuration file supplied by the vendor, the recommended way is to place a symlink to /dev/null in /etc/tmpfiles.d/ bearing the same filename.
--------------------------------------------
/etc/tmpfiles.d > /run/tmpfiles.d > /usr/lib/tmpfiles.d It seems to be strong in that order.
Since systemd-tmpfiles-clean.timer checks all atime / mtime / ctime, Just create a file and then change the timestamp with touch I can't confirm whether it will be deleted. (Because ctime cannot be changed)
Check settings
# cat /usr/lib/tmpfiles.d/tmp.conf
-----------------------------
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d
→ /Under tmp, things older than 10 days disappear
-----------------------------
Stop NTP
# systemctl disable ntpd.service
chronyd also stopped
# systemctl stop chronyd
# systemctl disable chronyd
Create a file directory
# cd /tmp/
# touch test
# mkdir miisuke
Check time
# stat test
Access: 2020-03-27 18:54:15.333822690 +0900
Modify: 2020-03-27 18:54:15.333822690 +0900
Change: 2020-03-27 18:54:15.333822690 +0900
# stat miisuke
Access: 2020-03-27 18:54:27.822006515 +0900
Modify: 2020-03-27 18:54:27.822006515 +0900
Change: 2020-03-27 18:54:27.822006515 +0900
Shift the server time
# date
Friday, March 27, 2020 19:09:58 JST
# date -s "03/28 20:00 2030"
# date
Thursday, March 28, 2030 20:00:02 JST
File creation at this point
# touch test2
# mkdir miisuke2
# stat test2
Access: 2030-03-28 20:00:37.166547096 +0900
Modify: 2030-03-28 20:00:37.166547096 +0900
Change: 2030-03-28 20:00:37.166547096 +0900
# stat miisuke2
Access: 2030-03-28 20:00:39.423580319 +0900
Modify: 2030-03-28 20:00:39.423580319 +0900
Change: 2030-03-28 20:00:39.423580319 +0900
Try restarting the server
# shutdown -r now
Should test and miisuke disappear?
$ date
Friday, March 27, 2020 19:16:12 JST
→ The time has returned after restarting. Is it synced on the xen host? ??
Redo
Make the server time old
# date -s "03/28 20:00 2010"
# date
Sunday, March 28, 2010 20:00:01 JST
Create file here
# cd /tmp/
# touch test3
# mkdir miisuke3
# stat test3
Access: 2010-03-28 20:01:47.397000000 +0900
Modify: 2010-03-28 20:01:47.397000000 +0900
Change: 2010-03-28 20:01:47.397000000 +0900
# stat miisuke3
Access: 2010-03-28 20:01:50.509000000 +0900
Modify: 2010-03-28 20:01:50.509000000 +0900
Change: 2010-03-28 20:01:50.509000000 +0900
Try restarting the server
# shutdown -r now
Should miisuke3 and test3 disappear when the time goes back?
# date
Friday, March 27, 2020 19:22:41 JST
# ls -l /tmp/
Total 0
drwxr-xr-x 2 root root 6 March 27 18:54 miisuke
drwxr-xr-x 2 root root 6 March 28 2030 miisuke2
drwxr-xr-x 2 root root 6 March 28 2010 miisuke3
-rw-r--r--1 root root 0 March 27 18:54 test
-rw-r--r--1 root root 0 March 28 2030 test2
-rw-r--r--1 root root 0 March 28 2010 test3
Not disappear.
Manually execute the deletion process
# SYSTEMD_LOG_TARGET=console SYSTEMD_LOG_LEVEL=debug /usr/bin/systemd-tmpfiles --clean
# ls -l /tmp/
drwxr-xr-x 2 root root 6 March 27 18:54 miisuke
drwxr-xr-x 2 root root 6 March 28 2030 miisuke2
-rw-r--r--1 root root 0 March 27 18:54 test
-rw-r--r--1 root root 0 March 28 2030 test2
Had disappeared.
Try to enable the process.
Create configuration file
# cd /etc/tmpfiles.d/
# cp -pi /usr/lib/tmpfiles.d/tmp.conf .
# vi tmp.conf
----------------
x /tmp/*
x /var/tmp/*
----------------
Make the server time old
# date -s "03/28 20:00 2010"
# date
Sunday, March 28, 2010 20:00:02 JST
Create file here
# cd /tmp/
# touch test3
# mkdir miisuke3
# stat test3
Access: 2010-03-28 20:00:16.230000000 +0900
Modify: 2010-03-28 20:00:16.230000000 +0900
Change: 2010-03-28 20:00:16.230000000 +0900
# stat miisuke3
Access: 2010-03-28 20:00:19.255000000 +0900
Modify: 2010-03-28 20:00:19.255000000 +0900
Change: 2010-03-28 20:00:19.255000000 +0900
Try restarting the server
# shutdown -r now
# date
Friday, March 27, 2020 19:51:03 JST
# ls -l /tmp/
It hasn't disappeared yet.
Manually execute the deletion process
# SYSTEMD_LOG_TARGET=console SYSTEMD_LOG_LEVEL=debug /usr/bin/systemd-tmpfiles --clean
# ls -l /tmp/
Total 0
drwxr-xr-x 2 root root 6 March 27 18:54 miisuke
drwxr-xr-x 2 root root 6 March 28 2030 miisuke2
drwxr-xr-x 2 root root 6 March 28 2010 miisuke3
-rw-r--r--1 root root 0 March 27 18:54 test
-rw-r--r--1 root root 0 March 28 2030 test2
-rw-r--r--1 root root 0 March 28 2010 test3
It didn't disappear!
Implemented on RHEL7 server
Create configuration file
# cd /etc/tmpfiles.d/
# cp -pi /usr/lib/tmpfiles.d/tmp.conf .
# vi tmp.conf
----------------
x /tmp/*
x /var/tmp/*
----------------
# mv tmp.conf aaa_tmp.conf(.If it's conf, any name looks good)
I referred to the following.
Differences in behavior between tmpwatch (up to CentOS6) and systemd-tmpfiles (CentOS7) Four pitfalls of CentOS 7 that you should be addicted to and cry [Linux] [Cent OS] The story that files under / tmp and / var / tmp are deleted without permission [Linux] Regarding the deletion process of the tmp folder of CentOS 7 How systemd-tmpfiles cleans up /tmp/ or /var/tmp (replacement of tmpwatch) in CentOS / RHEL 7
Recommended Posts