当Linux系统出现磁盘空间不足问题时,可以按照以下步骤进行排查和解决:
# 查看各分区使用情况
df -h
# 查看当前目录下各文件/目录大小
du -sh *
# 查看/var/log目录大小
du -sh /var/log
# 清理旧日志(保留最近7天)
find /var/log -type f -mtime +7 -exec rm -f {} \;
# 清空大日志文件(先确认内容)
echo "" > /var/log/large_log_file.log
# 对于Debian/Ubuntu系统
apt-get clean
apt-get autoclean
# 对于CentOS/RHEL系统
yum clean all
dnf clean all
# Debian/Ubuntu
dpkg --list | grep linux-image
apt-get purge linux-image-x.x.x-xx-generic
# CentOS/RHEL
rpm -q kernel
yum remove kernel-x.x.x-xx.el7
# 查找大于100MB的文件
find / -type f -size +100M -exec ls -lh {} \;
# 查找并删除7天前的大于50MB的文件
find / -type f -size +50M -mtime +7 -exec rm -f {} \;
# 清理/tmp目录
rm -rf /tmp/*
# 清理用户缓存
rm -rf ~/.cache/*
# 查看Docker磁盘使用
docker system df
# 清理无用镜像、容器、卷
docker system prune -a
如果清理后空间仍然不足,考虑: - 扩展虚拟机磁盘 - 添加新磁盘并挂载 - 使用LVM扩展逻辑卷
通过以上步骤,通常可以有效地解决Linux系统的磁盘空间不足问题。