起因
随着系统运行, CentOS 空间不断减少, 对此非常焦虑, 到底磁盘空间被哪些新增文件占用了呢?
分析过程, 主要使用 du 命令, 逐层找出消耗空间的目录
1, 在根目录下检索一下文件的占用情况, 执行 du 命令
- [test@t-ng-01 /]$ sudo du -sh *
- 0 bin
- 54M boot
- 0 dev
- 31M etc
- 160M home
- 0 lib
- 0 lib64
- 0 media
- 24K mnt
- 0 opt
- 0 proc
- 56K root
- 673M run
- 0 sbin
- 0 srv
- 0 sys
- 0 tmp
- 12G usr
- 296M var
发现 usr 目录占用了 12G!!
2, 进入 usr 目录, 继续执行 du 命令
- [test@t-ng-01 /]$ cd /usr
- [test@t-ng-01 usr]$ sudo du -sh *
- 107M bin
- 0 etc
- 0 games
- 12M include
- 441M lib
- 190M lib64
- 40M libexec
- 11G local
- 48M sbin
- 366M share
- 0 src
- 0 tmp
local 目录占用了 11G!!
3, 进入 local 目录继续分析
- [test@t-ng-01 usr]$ cd local
- [test@t-ng-01 local]$ sudo du -sh *
- 0 bin
- 0 etc
- 0 games
- 0 include
- 0 lib
- 0 lib64
- 0 libexec
- 11G openresty
- 0 sbin
- 0 share
- 0 src
OpenResty 目录占用 11G, 距离真相越来越近了
4, 进入 OpenResty 目录继续分析
- [test@t-ng-01 local]$ cd openresty
- [test@t-ng-01 openresty]$ sudo du -sh *
- 148K bin
- 24K COPYRIGHT
- 12M luajit
- 576K lualib
- 11G nginx
- 2.7M pod
- 216K resty.index
- 0 site
5, 进入 Nginx 目录继续分析
- [test@t--ng-01 openresty]$ cd nginx
- [test@t-ng-01 nginx]$ sudo du -sh *
- 151M bak
- 12K certs
- 0 client_body_temp
- 100K conf
- 72K conf-bak
- 92K conf-v2
- 82M data
- 24K data-v2
- 0 fastcgi_temp
- 8.0K html
- 9.4G logs
- 208K lua
- 120K lua-v2
- 512M on
- 40K proxy_temp
- 16M sbin
- 0 scgi_temp
- 0 uwsgi_temp
6, 最后到 Log 目录下探个究竟
- [test@t-ng-01 nginx]$ cd logs
- [test@t-ng-01 logs]$ sudo du -sh *
- 36K access-0621.log
- 710M access.log
- 2.9G access.log-20190101
- 2.8G access.log-20190102
- 3.0G access.log-20190103
- 192K error.log
- 908K error.log-20181221
- 940K error.log-20181222
- 872K error.log-20181223
- 840K error.log-20181224
- 880K error.log-20181225
- 924K error.log-20181226
- 976K error.log-20181227
- 116M error.log-20181228
- 1.3M error.log-20181229
- 1.1M error.log-20181230
- 1.0M error.log-20181231
- 908K error.log-20190101
- 844K error.log-20190102
- 7.1M error.log-20190103
- 4.0K nginx.pid
结论
1, Nginx 的访问日志历史备份文件占用了大部分磁盘空间, 果断删除比较早的, 只保留 1 天备份
2, 在 Nginx 根目录下有一个异常的 On 文件, 占用 512M 空间, 分析 Nginx.conf 文件, 是某处设置错误, 导致一直写访问日志.
来源: http://www.bubuko.com/infodetail-2906942.html