LVM 中的磁盘使用情况:哪些目录包含最多数据?

LVM 中的磁盘使用情况:哪些目录包含最多数据?

我们有以下卷:

$ df -h
Filesystem                     Size  Used Avail Use% Mounted on
devtmpfs                       3.8G     0  3.8G   0% /dev
tmpfs                          3.9G     0  3.9G   0% /dev/shm
tmpfs                          3.9G  377M  3.5G  10% /run
tmpfs                          3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root           13G   12G  1.3G  91% /
/dev/sda1                     1014M  274M  741M  27% /boot
/dev/mapper/vg_data1-lv_www1    25G   18G  8.0G  69% /var/www
/dev/mapper/vg_data1-lv_mysql  8.0G  6.5G  1.6G  81% /var/lib/mysql
/dev/mapper/vg_data1-lv_logs1  5.0G  3.4G  1.7G  68% /var/log
10.40.33.40:/var/www/html/mnt   35G   23G   13G  65% /var/www/html/mnt
tmpfs                          781M     0  781M   0% /run/user/1000

因此卷/dev/mapper/rhel-root使用了 91% 的内存。现在,我想找出 中大多数数据的位置/,但仅限于该卷中,而不是全部。我可以轻松做到这一点吗?我想做类似的事情du -sch /dev/mapper/rhel-root/*,即/没有/boot/var/www/var/lib/mysql

最后,我想找到占用卷空间的潜在大型和不需要的(被遗忘的)文件/dev/mapper/rhel-root,以便我可以尽可能地删除它们。

答案1

你可以偷偷地做一下:

mount /dev/mapper/rhel-root /mnt

find /mnt -xdev -type f -size +20M -exec ls -lh {} \;

umount /mnt

然后查看结果,当然您可以更改您想要的尺寸。

还有一种可能是,某些内容仍附着在 fd 上,例如,删除了日志而不是轮换它。

为此,您可以检查:

lsof | grep deleted

例子:

[root@xx-xxxxx51:/var/log/wildfly]$ lsof | grep -i delete
S80wildfl  2224       root    1w      REG              253,3   64821642       2432 /var/log/wildfly/console.log-20170331 (deleted)
S80wildfl  2224       root    2w      REG              253,3   64822168       2432 /var/log/wildfly/console.log-20170331 (deleted)
runuser    2228       root    1w      REG              253,3   64825188       2432 /var/log/wildfly/console.log-20170331 (deleted)
runuser    2228       root    2w      REG              253,3   64825188       2432 /var/log/wildfly/console.log-20170331 (deleted)
bash       2235    wildfly    1w      REG              253,3   64825188       2432 /var/log/wildfly/console.log-20170331 (deleted)
bash       2235    wildfly    2w      REG              253,3   64825188       2432 /var/log/wildfly/console.log-20170331 (deleted)
standalon  2237    wildfly    1w      REG              253,3   64825188       2432 /var/log/wildfly/console.log-20170331 (deleted)
standalon  2237    wildfly   10w      REG              253,3   64825188       2432 /var/log/wildfly/console.log-20170331 (deleted)
java       2307    wildfly    1w      REG              253,3   64909558       2432 /var/log/wildfly/console.log-20170331 (deleted)
java       2307    wildfly    2w      REG              253,3   64909558       2432 /var/log/wildfly/console.log-20170331 (deleted)
su        19197       root    2u      CHR              136,1        0t0          4 /dev/pts/1 (deleted)
standalon 19200 terinopadm   10u      CHR              136,1        0t0          4 /dev/pts/1 (deleted)
java      19269 terinopadm    2u      CHR              136,1        0t0          4 /dev/pts/1 (deleted)

恢复已使用空间的临时解决方案:

[root@xx-xxxxx51:/var/log/wildfly]$ lsof -p 2235
COMMAND  PID    USER   FD   TYPE DEVICE   SIZE/OFF   NODE NAME
bash    2235 wildfly  cwd    DIR  253,0       4096      2 /
bash    2235 wildfly  rtd    DIR  253,0       4096      2 /
bash    2235 wildfly  txt    REG  253,0     941880 138736 /bin/bash
bash    2235 wildfly  mem    REG  253,0     161704 131467 /lib64/ld-2.12.so
bash    2235 wildfly  mem    REG  253,0    1930416 131482 /lib64/libc-2.12.so
bash    2235 wildfly  mem    REG  253,0      23088 131492 /lib64/libdl-2.12.so
bash    2235 wildfly  mem    REG  253,0     134792 132059 /lib64/libtinfo.so.5.7
bash    2235 wildfly  mem    REG  253,0   99164480   9874 /usr/lib/locale/locale-archive
bash    2235 wildfly  mem    REG  253,0      26060   2707 /usr/lib64/gconv/gconv-modules.cache
bash    2235 wildfly    0r   CHR    1,3        0t0   3845 /dev/null
bash    2235 wildfly    1w   REG  253,3 4159791104   2432 /var/log/wildfly/console.log-20170331 (deleted)
bash    2235 wildfly    2w   REG  253,3 4159791104   2432 /var/log/wildfly/console.log-20170331 (deleted)

[root@xx-xxxxx51:/var/log/wildfly]$ ll /proc/2235/fd/2
l-wx------ 1 wildfly wildfly 64 Mar 31 08:05 /proc/2235/fd/2 -> /var/log/wildfly/console.log-20170331 (deleted)

[root@xx-xxxxx51:/var/log/wildfly]$ : > "/proc/2235/fd/2"

请注意,在这种情况下,这并不能解决问题,您需要重新启动应用程序或重新启动服务器。

希望能帮助到你。

答案2

对我来说,以下命令之一可以解决问题:

  1. 转到根目录并运行

杜-k |排序 -n | perl -ne '如果 ( /^(\d+)\s+(.$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10$m))),(("K","M","G","T","P")[$m]),,"“x(1.5$l),$2);}'

  1. 当前目录和子目录中的前 20 名

查找 . -xdev -printf "%s %p\n" |sort -nr|head -20

  1. /opt 目录及其子目录中的前 30 个

du -a /opt|sort -n -r|head -n 30

相关内容