过程记录:
[root@iZ8vb4m3j60ueayf2rziv8Z ~]# df -h //查看空间使用情况
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 38G 0 100% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 436K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 380M 0 380M 0% /run/user/0
[root@iZ8vb4m3j60ueayf2rziv8Z ~]# cd / //跳转根目录
[root@iZ8vb4m3j60ueayf2rziv8Z /]# du -sh * //查看各目录情况
0 bin
218M boot
4.0K data
0 dev
38M etc
466M home
0 lib
0 lib64
16K lost+found
4.0K media
4.0K mnt
4.0K mysql.sql
213M opt
du: cannot access ‘proc/5646/task/5646/fd/4’: No such file or directory
du: cannot access ‘proc/5646/task/5646/fdinfo/4’: No such file or directory
du: cannot access ‘proc/5646/fd/4’: No such file or directory
du: cannot access ‘proc/5646/fdinfo/4’: No such file or directory
0 proc
220K root
468K run
0 sbin
4.0K srv
0 sys
7.8M tmp
14G usr
23G var
[root@iZ8vb4m3j60ueayf2rziv8Z /]# cd /usr
[root@iZ8vb4m3j60ueayf2rziv8Z usr]# du -sh *
306M bin
4.0K etc
4.0K games
28M include
340M java
670M lib
410M lib64
63M libexec
11G local
443M sbin
368M share
350M src
0 tmp
[root@iZ8vb4m3j60ueayf2rziv8Z usr]# cd local
[root@iZ8vb4m3j60ueayf2rziv8Z local]# du -sh *
351M aegis
12M bin
4.0K etc
4.0K games
4.0K include
4.0K lib
4.0K lib64
4.0K libexec
11G php
4.0K sbin
92K share
65M src
58M svnRepo
[root@iZ8vb4m3j60ueayf2rziv8Z local]# cd php
[root@iZ8vb4m3j60ueayf2rziv8Z php]# du -sh *
116M bin
112K etc
5.0M include
9.3M lib
2.4M log
92K php
3.4M phpredis
39M sbin
10G var
[root@iZ8vb4m3j60ueayf2rziv8Z php]# cd /var
[root@iZ8vb4m3j60ueayf2rziv8Z var]# du -sh *
4.0K adm
9.9G cache
4.0K crash
28K db
8.0K empty
4.0K games
4.0K gopher
12K kerberos
2.5G lib
4.0K local
0 lock
3.9G log
0 mail
4.0K nis
4.0K opt
4.0K preserve
0 run
4.7G spool
179M svn
20K tmp
1.9G www
4.0K yp
[root@iZ8vb4m3j60ueayf2rziv8Z var]# cd log
[root@iZ8vb4m3j60ueayf2rziv8Z log]# du -sh *
40K aliyun-util.log
4.0K anaconda
39M audit
0 boot.log
0 boot.log-20211228
0 boot.log-20211229
0 boot.log-20211230
0 boot.log-20211231
0 boot.log-20220101
0 boot.log-20220102
0 boot.log-20220103
18M btmp
9.2M btmp-20220101
476M caigo
4.0K caigo-error
4.0K chrony
216K cron
704K cron-20211212
984K cron-20211220
708K cron-20211226
856K cron-20220102
36K dmesg
36K dmesg.old
12K firewalld
8.0K grubby
4.0K grubby_prune_debug
3.4G journal
16K lastlog
0 maillog
0 maillog-20211212
0 maillog-20211220
0 maillog-20211226
0 maillog-20220102
284K messages
912K messages-20211212
1.3M messages-20211220
916K messages-20211226
1.1M messages-20220102
28K mysqld.log
4.0M mysql.log20200419before
2.7M nginx
48K ntp.log
4.0K ntpstats
8.0K php-fpm
4.0K ppp
4.0K repair.log
4.0K rhsm
18M sa
16M secure
8.2M secure-20211212
208K secure-20211220
4.0K secure-20211226
4.0K secure-20220102
0 spooler
0 spooler-20211212
0 spooler-20211220
0 spooler-20211226
0 spooler-20220102
0 tallylog
28K tuned
276K wtmp
0 yum.log
40K yum.log-20180101
4.0K yum.log-20190101
4.0K yum.log-20200420
[root@iZ8vb4m3j60ueayf2rziv8Z log]# cd journal/
[root@iZ8vb4m3j60ueayf2rziv8Z journal]# du -sh *
3.4G a9fe31fd96c841a5a16f9c54110b66cc
[root@iZ8vb4m3j60ueayf2rziv8Z journal]# journalctl --disk-usage
Archived and active journals take up 3.3G on disk.
[root@iZ8vb4m3j60ueayf2rziv8Z journal]# journalctl --vacuum-time=30d 只留30天
Deleted archived journal /var/log/journal/a9fe31fd96c841a5a16f9c54110b66cc/system@a04c2e13fe6a4e0b8a6d7aa2908722cb-0000000000000001-0005a3abfd744d0e.journal (64.0M).
Deleted archived journal
……
Deleted archived journal /var/log/journal/a9fe31fd96c841a5a16f9c54110b66cc/system@a04c2e13fe6a4e0b8a6d7aa2908722cb-00000000002498c0-0005d24fc91bef19.journal (8.0M).
Vacuuming done, freed 2.8G of archived journals on disk.
[root@iZ8vb4m3j60ueayf2rziv8Z journal]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 36G 1.9G 96% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 436K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 380M 0 380M 0% /run/user/0
[root@iZ8vb4m3j60ueayf2rziv8Z journal]# cd /
[root@iZ8vb4m3j60ueayf2rziv8Z /]# cd var
[root@iZ8vb4m3j60ueayf2rziv8Z var]# du -sh *
4.0K adm
9.9G cache
4.0K crash
28K db
8.0K empty
4.0K games
4.0K gopher
12K kerberos
1.5G lib
4.0K local
0 lock
1.1G log
0 mail
4.0K nis
4.0K opt
4.0K preserve
0 run
4.7G spool
179M svn
20K tmp
1.9G www
4.0K yp
[root@iZ8vb4m3j60ueayf2rziv8Z var]# cd cache/
[root@iZ8vb4m3j60ueayf2rziv8Z cache]# du -sh *
24K fontconfig
32K ldconfig
1.8M man
9.9G yum
[root@iZ8vb4m3j60ueayf2rziv8Z cache]# yum clean packages
Loaded plugins: fastestmirror, priorities
Cleaning repos: base epel extras mysql-connectors-community mysql-tools-community mysql57-community remi-safe updates webtatic
2227 package files removed
[root@iZ8vb4m3j60ueayf2rziv8Z cache]# yum clean headers
Loaded plugins: fastestmirror, priorities
Cleaning repos: base epel extras mysql-connectors-community mysql-tools-community mysql57-community remi-safe updates webtatic
0 header files removed
[root@iZ8vb4m3j60ueayf2rziv8Z cache]# yum clean oldheaders
Loaded plugins: fastestmirror, priorities
Error: invalid clean argument: 'oldheaders'
Mini usage:
clean [headers|packages|metadata|dbcache|plugins|expire-cache|all]
Remove cached data
[root@iZ8vb4m3j60ueayf2rziv8Z cache]# du -sh *
24K fontconfig
32K ldconfig
1.8M man
436M yum
[root@iZ8vb4m3j60ueayf2rziv8Z cache]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 25G 14G 66% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 436K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 380M 0 380M 0% /run/user/0
Point 1:centos清理/dev/vda1系统盘:
df -h 检查一台服务器磁盘使用空间,发现磁盘已经使用了100%
思路是:
1、cd /usr 当然这里不一定是/usr目录,最好是cd到 根目录再执行下一步
2、du -sh * 看哪个目录占用空间大
3、重复前两步,根据实际情况删除或者移走
4、日志的话可以运行cat /dev/null > file.log清空
5、软件包的可以rpm -e 卸载或者rm -rf dir
即:
具体:可以通过下面的方法进行清理:
使用如下命令查找大于100M的大文件,发现有几个日志文件及临时文件比较大,使用rm –rf删除即可。
find / -size +100M -exec ls -lh {} \;
也可以使用 du -h –max-depth=1 /路径 查询文件夹占用显示该目录占用空间的总和
譬如:du -h –max-depth=1 /var
删除文件时,要小心,不要删除系统文件了 :)
Point 2:Linux yum清除var下目录缓存
Linux下yum发音(丫目)。
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。提供软件查找、安装、删除某一个或一组甚至全部软件包的命令,而且命令简洁而又好记。
yum的命令形式如下:
yum [options] [command] [package …]
常用的命令包括:
#安装软件 yum install packages
#更新软件 yum update packages
#删除软件 yum remove packages
#清除缓存 yum clean packages
重点介绍:
通常,yum 把下载的header和软件 包 都存储在cache中,而不会自动删除。如果你觉得它们占用了大量磁盘空间,可以使用yum clean指令进行清除,更精确 的用法是yum clean headers清除header,yum clean packages清除下载的rpm包,yum clean all全部干掉。
1.清除缓存目录(/var/cache/yum)下的软件 包
命令:yum clean packages
2.清除缓存目录(/var/cache/yum)下的 headers
命令:yum clean headers
3.清除缓存目录(/var/cache/yum)下旧的 headers
命令:yum clean oldheaders
4.清除缓存目录(/var/cache/yum)下的软件 包及旧的headers
Point 3: var/log/journal日志清理:
Linux log日志清理
检查当前journal使用磁盘量
journalctl –disk-usage
清理方法可以采用按照日期清理,或者按照允许保留的容量清理,只保存2天的日志,最大500M
journalctl –vacuum-time=2d
journalctl –vacuum-size=500M
如果要手工删除日志文件,则在删除前需要先轮转一次journal日志
systemctl kill –kill-who=main –signal=SIGUSR2 systemd-journald.service
要启用日志限制持久化配置,可以修改 /etc/systemd/journald.conf
SystemMaxUse=16M
ForwardToSyslog=no
然后重启
systemctl restart systemd-journald.service
检查journal是否运行正常以及日志文件是否完整无损坏
journalctl –verify
————————————————————————————————————————————————————
参考:centos 磁盘清理 /dev/vda1系统盘满了
linux yum清除var目录下缓存的方法
/var/log/journal日志清理