Linux基础——系统tmp目录占用内存空间导致系统宕机

一、系统/tmp目录

1、目录作用

/tmp:一般用户或正在执行的程序临时存放文件的目录,任何人都可以访问,重要数据不可放置在此目录下

 

 2、目录使用者root

fuser -k -m -v /tmp

 3、/tmp挂载服务进入active

tmp.mount服务

二、排查过程

1、tmp的挂载内存空间和挂载逻辑卷依赖三个服务

/usr/lib/systemd/system/local-fs.target.wants/tmp.mount

/usr/lib/systemd/system/basic.target

/usr/lib/systemd/system/tmp.mount

注:local-fs.target.wants/tmp.mount和basic.target开机都会自动拉起tmp.mount服务,

如果tmp.mount服务mask情况下,容易造成/tmp和/目录只读;

2、删除basic.target服务tmp字段

# 避免开启时,basic.target服务自动拉起tmp.mount服务

cat /usr/lib/systemd/system/basic.target

3、 移除/usr/lib/systemd/system/local-fs.target.wants/tmp.mount

cat /usr/lib/systemd/system/local-fs.target.wants/tmp.mount
mv /usr/lib/systemd/system/local-fs.target.wants/tmp.mount /usr/lib/systemd/system/local-fs.target.wants/tmp.mount.bak

4、卸载/tmp挂载、关闭tmp.mount服务、mask服务

# 停止服务
[root@harbor ~]# systemctl stop tmp.mount
# 检查服务状态
[root@harbor ~]# systemctl status tmp.mount
● tmp.mount - Temporary Directory (/tmp)
Loaded: loaded (/usr/lib/systemd/system/tmp.mount; disabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2024-11-18 10:26:21 CST; 6s ago
Where: /tmp
What: tmpfs
Docs: https://systemd.io/TEMPORARY_DIRECTORIES
man:file-hierarchy(7)
https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems

Nov 18 09:42:33 harbor systemd[1]: tmp.mount: Directory /tmp to mount over is not empty, mounting anyway.
Nov 18 09:42:33 harbor systemd[1]: Mounting Temporary Directory (/tmp)...
Nov 18 09:42:33 harbor systemd[1]: Mounted Temporary Directory (/tmp).
Nov 18 10:26:21 harbor systemd[1]: Unmounting Temporary Directory (/tmp)...
Nov 18 10:26:21 harbor systemd[1]: tmp.mount: Succeeded.
Nov 18 10:26:21 harbor systemd[1]: Unmounted Temporary Directory (/tmp).
# 锁定服务
[root@harbor ~]# systemctl mask tmp.mount
Created symlink /etc/systemd/system/tmp.mount → /dev/null.
# 确认/tmp是否挂载
[root@harbor ~]# df -Th | grep '/tmp'
# 检查mount挂载
[root@harbor ~]# mount | grep '/tmp'

 

 5、重启

# 注:确认basic.tar.get和local-fs.target服务没有tmp.mount相关字段
grep tmp /usr/lib/systemd/system/basic.target
grep tmp /usr/lib/systemd/system/local-fs.target.wants/tmp.mount
reboot

5、检查/tmp详情

# 确认/和/tmp正常读写

 

 

 

posted on 2024-11-20 11:32  gkhost  阅读(564)  评论(0)    收藏  举报

导航