Linux提示空间已满,找不到大文件
作者:互联网
当我们发现磁盘快满了,然后删除某些服务的日志文件,删除后发现磁盘空间仍然被占用,但我们使用“du –sh /*” 命令,发现目录下没有大文件,这时我们应该考虑,删除日志文件时,只是将所有的硬链接给删除了,但还有服务或程序占用,所以实际数据我们无法查看,但它仍然占用磁盘空间。这时可以重启服务,将占用日志文件的服务或进程重启,就可以释放占用的磁盘空间。
模拟案例:
1. 首先创建一个小空间的模拟磁盘分区:
[root@test ~]# dd if=/dev/zero of=/dev/test bs=1k count=512
记录了512+0 的读入
记录了512+0 的写出
524288字节(524 kB)已复制,0.00172664 秒,304 MB/秒
[root@test ~]# ll /dev/oldboy
-rw-r--r-- 1 root root 524288 10月 18 03:37 /dev/oldboy
2. 格式化磁盘
[root@test ~]# mkfs.ext4 /dev/test
mke2fs 1.41.12 (17-May-2010)
/dev/test is not a block special device.
无论如何也要继续? (y,n) y
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
64 inodes, 512 blocks
25 blocks (4.88%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=524288
1 block group
8192 blocks per group, 8192 fragments per group
64 inodes per group
正在写入inode表: 完成
文件系统小得无法记录日志
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3. 安装一个httpd服务
[root@test ~]# yum install httpd –y
# 将新建的虚拟分区挂载到httpd存放日志的目录下/etc/httpd/logs/
[root@test ~]# mount -o loop /dev/oldboy /etc/httpd/logs/
[root@test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.5G 7.0G 18% /
tmpfs 244M 0 244M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
/dev/sr0 3.7G 3.7G 0 100% /mnt
/dev/test 499K 15K 459K 4% /var/log/httpd
# 打开httpd服务的记录日志功能,将513行注释去掉即可。
[root@test ~]# vi /etc/httpd/conf/httpd.conf
*****************************************
513 #CustomLog logs/access_log common
# 开启httpd服务
[root@test ~]# /etc/init.d/httpd start
正在启动 httpd:httpd: apr_sockaddr_info_get() failed for oldboy
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[确定]
在浏览器上输入虚拟机IP地址,可以访问模拟网页服务,跟踪httpd记录日志文件。
[root@test ~]# tail -f /etc/httpd/logs/access_log
# 刷新页面或者直接在文件里写入内容,使存放日志的分区使用量到100%,可以循环写入内容,使设备没有空间。
[root@test ~]# for n in `seq 10000`;do echo "liangkai">>/etc/httpd/logs/access_log ;done
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
-bash: echo: write error: 设备上没有空间
4. 查看空间已满,删除日志文件后,发现磁盘空间仍是满的。
[root@test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.5G 7.0G 18% /
tmpfs 244M 0 244M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
/dev/sr0 3.7G 3.7G 0 100% /mnt
/dev/test 499K 489K 0 100% /var/log/httpd
[root@test ~]# \rm -f /etc/httpd/logs/access_log
[root@test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.5G 7.0G 18% /
tmpfs 244M 0 244M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
/dev/sr0 3.7G 3.7G 0 100% /mnt
/dev/test 499K 489K 0 100% /var/log/httpd
5. 使用lsof 命令查看进程正在使用的已删除文件,发现有很多
[root@test ~]# lsof |grep deleted
httpd 2008 root 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2008 root 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2013 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2013 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2014 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2014 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2015 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2015 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2016 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2016 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2017 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2017 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2018 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2018 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2019 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2019 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2020 apache 7w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
httpd 2020 apache 8w REG 7,0 420862 13 /var/log/httpd/access_log (deleted)
6. 重启httpd服务,磁盘空间恢复正常。
[root@test ~]# /etc/init.d/httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: apr_sockaddr_info_get() failed for oldboy
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[确定]
[root@test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.5G 7.0G 18% /
tmpfs 244M 0 244M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
/dev/sr0 3.7G 3.7G 0 100% /mnt
/dev/test 499K 78K 396K 17% /var/log/httpd
标签:httpd,log,提示,dev,access,var,已满,Linux,test 来源: https://blog.csdn.net/xinjing2015/article/details/117945896