linux 磁盘分析
一. 案例分析1
1. 首先查看磁盘整体使用率
[root@iZwz97yqubb71vyxhuskfxZ ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.8G 0 3.8G 0% /dev/shm tmpfs 3.8G 616K 3.8G 1% /run tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup /dev/vda3 40G 30G 11G 73% / /dev/vda2 100M 7.3M 93M 8% /boot/efi tmpfs 777M 0 777M 0% /run/user/0 overlay 40G 30G 11G 73% /var/lib/docker/overlay2/da98e6ab24ab9b25d42c3ed32955e349741d3af28e0eb72f2e7b667fb210f098/merged
上面发现已经使用到73%了.
2.在根目录上查看各文件文件占用大小
[root@iZwz97yqubb71vyxhuskfxZ ~]# du -hl -x --max-depth=1 4.0K ./.pip 53M ./.cache 0 ./.ssh 210M ./package 4.4G ./zookeeper 124M ./canal 4.0K ./.config 90M ./scrapyrt_project 97M ./nodejs 4.0K ./.npm 8.0K ./.gnupg 0 ./.local 14M ./webdriver 96M ./filebeat 68K ./.pki 5.0G .
通过分析发现,zookeeper占用了4.4G, 最后一个占用了5G
3.继续zookeeper分析
[root@iZwz97yqubb71vyxhuskfxZ apache-zookeeper-3.7.0-bin]# pwd /root/zookeeper/apache-zookeeper-3.7.0-bin [root@iZwz97yqubb71vyxhuskfxZ apache-zookeeper-3.7.0-bin]# du -hl -x --max-depth=1 28M ./docs 11M ./lib 24K ./conf 76K ./bin 1.6M ./data 4.3G ./logs 4.4G .
最终发现日志占用了4.3G
二. 案例分析2
[root@iZwz97yqubb71vyxhuskfwZ ~]# cd ../ [root@iZwz97yqubb71vyxhuskfwZ /]# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var [root@iZwz97yqubb71vyxhuskfwZ /]# du -hl -x --max-depth=1 265M ./boot 26M ./etc 747M ./root 17G ./var 3.6G ./usr 0 ./home 0 ./media 0 ./mnt 285M ./opt 0 ./srv 36K ./tmp 22G . [root@iZwz97yqubb71vyxhuskfwZ /]# cd var [root@iZwz97yqubb71vyxhuskfwZ var]# du -hl -x --max-depth=1 17G ./lib 296M ./log 63M ./cache 0 ./adm 0 ./db 0 ./empty 0 ./ftp 0 ./games 0 ./gopher 0 ./local 0 ./nis 0 ./opt 0 ./preserve 12K ./spool 4.0K ./tmp 0 ./yp 0 ./kerberos 0 ./crash 0 ./account 17G . [root@iZwz97yqubb71vyxhuskfwZ var]# cd ./lib [root@iZwz97yqubb71vyxhuskfwZ lib]# du -hl -x --max-depth=1 2.6M ./dnf 171M ./rpm 0 ./games 0 ./misc 0 ./rpm-state 48K ./alternatives 27M ./selinux 0 ./dbus 0 ./initramfs 0 ./os-prober 136K ./systemd 0 ./portables 0 ./private 0 ./tpm 0 ./polkit-1 4.0K ./logrotate 0 ./samba 4.0K ./rsyslog 20K ./NetworkManager 4.0K ./unbound 56K ./authselect 0 ./PackageKit 0 ./kdump 0 ./iscsi 4.0K ./plymouth 0 ./setroubleshoot 0 ./fprint 0 ./udisks2 4.0K ./fwupd 34M ./sss 0 ./tuned 4.0K ./chrony 0 ./xfsdump 4.8M ./mlocate 0 ./smartmontools 0 ./dhclient 188K ./cloud 84K ./containerd 17G ./docker 17G .
最终分析出docker占用了17G,接着再分析,最终发现容器中占用了17G
[root@iZwz97yqubb71vyxhuskfwZ lib]# pwd /var/lib [root@iZwz97yqubb71vyxhuskfwZ lib]# cd docker [root@iZwz97yqubb71vyxhuskfwZ docker]# ls builder buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes [root@iZwz97yqubb71vyxhuskfwZ docker]# du -hl -x --max-depth=1 15G ./containers 0 ./plugins 2.1G ./overlay2 3.6M ./image 36K ./volumes 0 ./trust 44K ./network 0 ./swarm 16K ./builder 56K ./buildkit 0 ./tmp 0 ./runtimes 17G .
接着往下分析 cd containers
[root@iZwz97yqubb71vyxhuskfwZ containers]# du -hl -x --max-depth=1 28K ./c96ad5d75bd226938d3b0df63ab4435372fee5af98adb43720396ac92050d33d 14G ./d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff 32K ./0400b00c1a48c247ccf81180e27e4edf79c15334ca96d633cbc1bc9713df1897 1.1G ./369d7f2cba5432667889404f1850c0162575071dc9e9f3a6d252d00abf4afa4d 15G . [root@iZwz97yqubb71vyxhuskfwZ d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff]# ll -h total 14G drwx------ 2 root root 6 Aug 11 10:44 checkpoints -rw------- 1 root root 4.1K Sep 19 10:58 config.v2.json -rw-r----- 1 root root 14G Sep 19 00:02 d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff-json.log -rw-r--r-- 1 root root 1.5K Sep 19 10:58 hostconfig.json -rw-r--r-- 1 root root 13 Aug 11 10:44 hostname -rw-r--r-- 1 root root 174 Aug 11 10:44 hosts drwx-----x 2 root root 6 Aug 11 10:44 mounts -rw-r--r-- 1 root root 340 Aug 11 10:44 resolv.conf -rw-r--r-- 1 root root 71 Aug 11 10:44 resolv.conf.hash
查看到日志文件占用过大,下面是清空日志内容,再次查看日志文件内容没有了
[root@iZwz97yqubb71vyxhuskfwZ d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff]# : > d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff-json.log [root@iZwz97yqubb71vyxhuskfwZ d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff]# ll -h total 28K drwx------ 2 root root 6 Aug 11 10:44 checkpoints -rw------- 1 root root 4.1K Sep 19 10:58 config.v2.json -rw-r----- 1 root root 0 Sep 28 18:51 d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff-json.log -rw-r--r-- 1 root root 1.5K Sep 19 10:58 hostconfig.json -rw-r--r-- 1 root root 13 Aug 11 10:44 hostname -rw-r--r-- 1 root root 174 Aug 11 10:44 hosts drwx-----x 2 root root 6 Aug 11 10:44 mounts -rw-r--r-- 1 root root 340 Aug 11 10:44 resolv.conf -rw-r--r-- 1 root root 71 Aug 11 10:44 resolv.conf.hash [root@iZwz97yqubb71vyxhuskfwZ d820334834a6afbfc020437468c0fb1df2ddafd2bffccc1615f2ae991e0c9fff]#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下