LoginSignup
0
0

More than 1 year has passed since last update.

WebArena Indigo 環境設定6)/tmpフォルダのファイルの削除処理の変更

Last updated at Posted at 2022-03-16

WebArena Indigo 環境設定5)プロセス最大値の変更
https://qiita.com/naga_kt/items/49d04303c26d2a612529
の続き。

systemd-tmpfilesの設定変更(CentOS7/RockyLinux8)

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

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

(CentOS7の場合)

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

(RockyLinux8の場合)

$ 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

systemd-tmpfilesの設定変更(Ubuntu20.04)

 /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
D /tmp 1777 root root -
#q /var/tmp 1777 root root 30d

 以下のように行った。

# 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

WebArena Indigo 環境設定7)Swapの設定
https://qiita.com/naga_kt/items/4ff37e048b7413eb90fc
に続く


参考記事

お前らもさっさとハマって泣くべき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