1. 磁盘整体使用
使用df -h查看磁盘空间占用情况:
[work@offline-market-Shouhoushahe02-Cqu-01 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 77G 17G 83% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 816K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
tmpfs 1.6G 0 1.6G 0% /run/user/510
...
2. 筛选目录占用的磁盘
使用du -h -s /* | sort -nr命令查看那个目录占用空间大:
[work@offline-market-Shouhoushahe02-Cqu-01 ~]$ du -h -s /* | sort -nr
du: cannot read directory ‘/var/lib/yum/history/2017-10-15/15’: Permission denied
du: cannot read directory ‘/var/empty/sshd’: Permission denied
816K /run
386M /etc
135M /boot
54G /home
19M /tmp
16K /lost+found
9.3G /data
8.0K /opt
4.0K /srv
4.0K /root
4.0K /media
3.8M /mnt
2.7G /usr
2.6G /var
0 /sys
0 /sbin
0 /proc
0 /lib64
0 /lib
0 /dev
0 /bin
再通过du -h -s /* | sort -nr 一层层排查,如上/home目录占用最多,排查该目录:
du -h -s /home/* | sort -nr:
[work@offline-market-Shouhoushahe02-Cqu-01 home]$ du -h -s /home/* | sort -nr
54G /home/work
36K /home/rd
再使用du /home/work --max-depth=1 -h,查看当前目录下文件夹大小情况:
[work@offline-market-Shouhoushahe02-Cqu-01 ~]$ du /home/work --max-depth=1 -h
48G /home/work/www
1.1M /home/work/.cache
1.3G /home/work/package
465M /home/work/backup
28K /home/work/pprof
12K /home/work/logs
8.0K /home/work/.oracle_jre_usage
20K /home/work/.ssh
47M /home/work/consul
4.0K /home/work/bin
12K /home/work/script
203M /home/work/nginx
176K /home/work/.ansible
18M /home/work/confd
20K /home/work/.java
148M /home/work/product
8.0K /home/work/.vim
8.0K /home/work/.pki
3.1G /home/work/elasticsearch
3.1M /home/work/fe
603M /home/work/falcon
24M /home/work/open-falcon
9.3M /home/work/mtail
54G /home/work
[work@offline-market-Shouhoushahe02-Cqu-01 ~]$ du /home/work/www --max-depth=1 -h
223M /home/work/www/aftersale-integration
60M /home/work/www/financing_mng_api
21M /home/work/www/RepairShop
949M /home/work/www/external_api
1.8G /home/work/www/repairshop.web
79M /home/work/www/aftersale_transfer_service
141M /home/work/www/refund-approval-center
721M /home/work/www/aftersale-rop
16G /home/work/www/aftersale_export_task
29G /home/work/www/aftersale-order-center
70M /home/work/www/business-service-web
48G /home/work/www
[work@offline-market-Shouhoushahe02-Cqu-01 ~]$ du /home/work/www/aftersale-order-center/var --max-depth=1 -h
28G /home/work/www/aftersale-order-center/var/log
16K /home/work/www/aftersale-order-center/var/run
28G /home/work/www/aftersale-order-center/var
3. 删除文件
如果找到占用磁盘较大的文件,然后删除,或者使用echo '' > xx.log(这种方式会立即释放空间)
4. 为释放占用空间
如果删除文件后,之前被占用的磁盘空间仍没有释放,那么可以使用 lsof | grep deleted 命令,看看被删除掉的文件是否仍然被进程占用,而没有进行实际删除:
[work@offline-market-Shouhoushahe02-Cqu-01 log]$ lsof | grep deleted
java 1148 work 1w REG 253,1 8053981961 2232845 /home/work/package/logs/canal/canal.log36106298883655344.tmp (deleted)
java 1148 work 2w REG 253,1 8053981961 2232845 /home/work/package/logs/canal/canal.log36106298883655344.tmp (deleted)
java 1148 1149 work 1w REG 253,1 8053981961 2232845 /home/work/package/logs/canal/canal.log36106298883655344.tmp (deleted)
java 1148 1149 work 2w REG 253,1 8053981961 2232845 /home/work/package/logs/canal/canal.log36106298883655344.tmp (deleted)
...
kill -9 pid,然后重启即可。杀掉该进程即可。
|