1. Linux服务器磁盘经常占满,使用命令df -h查看哪些磁盘被占满了

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda2        35G   34G 1G    98% /
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G   12K   16G   1% /dev/shm
tmpfs            16G  1.6G   15G  11% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/vda1       477M   92M  356M  21% /boot
/dev/vdb1       197G  171G   16G  92% /data
tmpfs           3.2G     0  3.2G   0% /run/user/1064
tmpfs           3.2G     0  3.2G   0% /run/user/0
tmpfs           3.2G     0  3.2G   0% /run/user/1061
tmpfs           3.2G     0  3.2G   0% /run/user/1000

从上面看/dev/vda2占用98%,这个磁盘指的是Linux除下面所有磁盘中剩余的磁盘空间, 主要的有 /usr /home /opt等

比如/usr可以cd 到该目录,看下占用空间 

du -sh 查看总文件夹的大小

du -sh * 查看当前目录下所有文件夹占用大小

[root@a...usr]# du -sh
1.6G	.
[root@alta1-web-1 usr]# du -sh *
100M	bin
4.0K	etc
4.0K	games
22M	include
316M	java
379M	lib
152M	lib64
62M	libexec
124M	local
40M	sbin
337M	share
67M	src
0	tmp

使用 du -sh * | sort -nr | head 查看占用空间最大的

不过有时候占用空间其实并不大, 但是地df -h显示占用空间很大,绝大多数原因是

此服务器上有写日志的操作,在写的同时把要写入的文件删除了。。因为在写操作不能创建文件的时候会写硬盘的block,这样会使硬盘利用率越来越低,可以使用lsof -n |grep delete 来查看哪些进程在对磁盘进行写操作。

一般都是程序打开了已经删除的文件,导致磁盘未释放该文件。lsof|grep delete之后kill掉该进程,或者直接重启

[root@alta1-tools-web-1 /]# lsof -n |grep delete
superviso    2508                root    3w      REG              253,2    17154032    2097734 /tmp/supervisord.log (deleted)
superviso    2508                root    7r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root    8r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   13r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   15r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   17r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   18r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   20r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   21r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   22r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   26r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   27r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   28r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   29r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   30r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   31r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   32r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   33r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   34r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   35r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   36r      REG             253,17    52512427    9701530 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   38r      REG             253,17    52429432    9703334 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   41r      REG             253,17    52430714    9752748 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   43r      REG             253,17    52430714    9752748 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   50r      REG             253,17    52428907    9706087 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   51r      REG             253,17    52428907    9706087 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
superviso    2508                root   52r      REG             253,17    52428907    9706087 /data/log/atfcapi.driller/supervisord.log.10 (deleted)
gunicorn   444026                root    6u      REG              253,2           0    2097163 /tmp/wgunicorn-McPYB0 (deleted)
gunicorn   444026                root    7u      REG              253,2           0    2097258 /tmp/wgunicorn-4w2MSH (deleted)
gunicorn   444026                root    9u      REG              253,2           0    2097164 /tmp/wgunicorn-gxui49 (deleted)
gunicorn   444026                root   10u      REG              253,2           0    2097234 /tmp/wgunicorn-aag4Xx (deleted)
kill掉以后再查看df -h占用率 发现占用率大大下降
Logo

更多推荐