LoginSignup
0
0

More than 1 year has passed since last update.

RockyLinux8 vps環境設定10) /tmpフォルダのファイルの削除処理の変更

Last updated at Posted at 2022-09-18

RockyLinux8 vps環境設定9) サーバ再起動時の設定
https://qiita.com/naga_kt/items/11026238e56b134e93ad
の続き。WebArena Indigo(RockyLinux8.4)及びKagoya(RockyLinux8.5)での環境設定について述べる。

systemd-tmpfilesの設定変更

/tmpに作成したファイルが時々削除されていることに気付いた。これはCentOS7以降の仕様とのこと(参考記事参照)。

 systemd-tmpfilesが/tmp以下のファイルの削除を行う。/tmp削除の設定は/usr/lib/tmpfiles.d/tmp.confに記述されている。

$ cat /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
q /tmp 1777 root root 10d
q /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

# Remove top-level private temporary directories on each boot
R! /tmp/systemd-private-*
R! /var/tmp/systemd-private-*

 上記にあるように/tmp以下のファイルが10日(10d)経ったら削除されるように設定されている。mtime(最終変更時間)、atime(最終アクセス時間)、ctime(最終属性変更時間)の全ての時間が削除までの期間を超過した時にファイルが削除される。

 設定を変更するためには、上記のファイルを/etc/tmpfiles.dにコピーして、設定を追加する。/etc/tmpfiles.d/での設定は、/usr/lib/tmpfiles.d/の設定より優先される。
 以下のように行った。

# cp -p /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/
# vi /etc/tmpfiles.d/tmp.conf

 ファイルに以下を追記した。

X /tmp/xxxxx

 systemd-tmpfilesの挙動の確認は、以下のようにするとデバッグログが吐き出されて、削除しなかった理由が述べられる。

$ SYSTEMD_LOG_TARGET=console SYSTEMD_LOG_LEVEL=debug /usr/bin/systemd-tmpfiles --clean

Running clean action for entry X /tmp/xxxxx

RockyLinux8 vps環境設定11) 権限の最終的な設定
https://qiita.com/naga_kt/items/6c42e031751876f36c97
に続く。


参考記事

お前らもさっさとハマって泣くべきCentOS7の落とし穴4つ
https://qiita.com/suemoc/items/e29285e8e67263298f35

tmpwatch(CentOS6まで)とsystemd-tmpfiles(CentOS7)の挙動の違い
https://qiita.com/kuroneko9/items/70a102a7bb1aa53661a2

【CentOS】/tmp配下のファイルが消える理由
https://densan-hoshigumi.com/server/tmp-file-disappearance

【systemd-tmpfiles】CentOS8でディレクトリ内のファイルを定期的に消す方法
https://mikemikeblog.com/how-to-use-systemd-tmpfiles-with-centos8/

tmpfiles.d(5) [centos man page]
https://www.unix.com/man-page/centos/5/tmpfiles.d/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0