侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Linux 查看空间使用情况的实例详解

linux  /  管理员 发布于 7年前   158

Linux 查看空间使用情况的实例详解

在日常的Linux巡检中,我们会遇到文件系统目录使用空间很高的情况,例如如下利用”df -h “查看到根目录空间使用超过80%。而我们仅仅知道是根目录空间使用过高,这样是不够的。还需要知道是目录还是文件让根目录空间使用过高。通常我们使用的命令是”du -sh *”。

第一步:查看Linux系统的文件系统使用情况,如下可以看到根目录”/”已经使用81%。

[root@hostname ~]# df -hFilesystem      Size Used Avail Use% Mounted on/dev/sda6       67G  51G  13G 81% /tmpfs         16G 152K  16G  1% /dev/shm/dev/sda3       99G 188M  94G  1% /arch/dev/sda1       197G 188M 187G  1% /u01/dev/sda2       197G  50G 138G 27% /u02

第二步:进入根目录,利用du -sh 命令查询各个目录或者文件占用空间的情况,因为/u02是独立的文件系统,所以可以忽略。我们关注的是root这个目录,占用了空间47G。

[root@hostname ~]# cd /[root@hostname /]# du -sh *20K   arch7.6M  bin27M   boot324K  dev36M   etc36K   home136M  lib26M   lib6416K   lost+found4.0K  media0    misc4.0K  mnt0    net8.0K  opt4.0K  orbit-root--省略/proc目录统计的报错0    proc47G   root  ##根目录文件系统使用最大的目录15M   sbin0    selinux4.0K  srv0    sys80K   tmp20K   u0149G   u02

第三步:进入root目录,其实也是root用户的主目录。我们从ls命令可以猜到可能是【apache-tomcat-6.0.36-linux】这个tomcat的程序目录占用比较多。

[root@hostname /]# cd root[root@hostname ~]# lsanaconda-ks.cfg apache-tomcat-6.0.36-linux Desktop Documents Downloads install.log install.log.syslog Music Pictures Public Templates Videos

第四步:通过统计发现,确实是【apache-tomcat-6.0.36-linux】这个目录占用了47G。但是到此问题还没有结束,因为既然是应用程序的目录,根据我的经验很可能是tomcat的日志文件占用空间比较多。

[root@hostname ~]# du -sh *4.0K  anaconda-ks.cfg47G   apache-tomcat-6.0.36-linux4.0K  Desktop4.0K  Documents4.0K  Downloads56K   install.log12K   install.log.syslog4.0K  Music4.0K  Pictures4.0K  Public4.0K  Templates4.0K  Videos

第五步:既然看到有tomcat的目录,很可能这个tomcat运行着,利用ps命令查看是否有tomcat的进程,一般可以过滤java这个关键词。如下,果然有tomcat在运行着。那么很可能占用空间最多就是tomcat的日志文件。

[root@hostname ~]# ps -ef|grep javaroot   4879 4836 0 08:26 pts/0  00:00:00 grep javaroot   11864   1 47 Aug16 ?    26-03:11:29 /usr/bin/java -Djava.util.logging.config.file=/root/apache-tomcat-6.0.36-linux/conf/logging.properties -Xms512m -Xmx1024m -XX:PermSize=128M -XX:MaxPermSize=256m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/root/apache-tomcat-6.0.36-linux/endorsed -classpath /root/apache-tomcat-6.0.36-linux/bin/bootstrap.jar -Dcatalina.base=/root/apache-tomcat-6.0.36-linux -Dcatalina.home=/root/apache-tomcat-6.0.36-linux -Djava.io.tmpdir=/root/apache-tomcat-6.0.36-linux/temp org.apache.catalina.startup.Bootstrap start

第六步:进入tomcat的程序目录,查看哪个目录占用的空间最大。如下,发现是一个【fare】的目录占用了46G,而【logs】是日志目录却占用了23M。

[root@hostname ~]# cd apache-tomcat-6.0.36-linux[root@hostname apache-tomcat-6.0.36-linux]# lsbackup bin conf fare lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work[root@hostname apache-tomcat-6.0.36-linux]# du -sh *92K   backup882M  bin108K  conf46G   fare6.8M  lib40K   LICENSE23M   logs4.0K  NOTICE12K   RELEASE-NOTES16K   RUNNING.txt7.9M  temp188M  webapps7.1M  work

第七步:继续一探究竟【fare】目录里面到底存放的是什么类型的目录或者文件。如下看到有很多类似日志文件,如common.log和pricing.log。通过和开发人员沟通之后,确定确实日志文件。

[root@hostname apache-tomcat-6.0.36-linux]# cd fare[root@hostname fare]# lscommon.log       common.log.2017-09-21 common.log.2017-10-03   pricing.log.2017-09-10 pricing.log.2017-09-22 pricing.log.2017-10-04common.log.2017-09-10 common.log.2017-09-22 common.log.2017-10-04   pricing.log.2017-09-11 pricing.log.2017-09-23 pricing.log.2017-10-05common.log.2017-09-11 common.log.2017-09-23 common.log.2017-10-05   pricing.log.2017-09-12 pricing.log.2017-09-24 pricing.log.2017-10-06common.log.2017-09-12 common.log.2017-09-24 common.log.2017-10-06   pricing.log.2017-09-13 pricing.log.2017-09-25 pricing.log.2017-10-07common.log.2017-09-13 common.log.2017-09-25 common.log.2017-10-07   pricing.log.2017-09-14 pricing.log.2017-09-26 pricing.log.2017-10-08common.log.2017-09-14 common.log.2017-09-26 common.log.2017-10-08   pricing.log.2017-09-15 pricing.log.2017-09-27 pricing.log.2017-10-09common.log.2017-09-15 common.log.2017-09-27 common.log.2017-10-09   pricing.log.2017-09-16 pricing.log.2017-09-28 spring.logcommon.log.2017-09-16 common.log.2017-09-28 common.zip        pricing.log.2017-09-17 pricing.log.2017-09-29 struts2.logcommon.log.2017-09-17 common.log.2017-09-29 framework.log       pricing.log.2017-09-18 pricing.log.2017-09-30 xwork2.logcommon.log.2017-09-18 common.log.2017-09-30 hibernate.log       pricing.log.2017-09-19 pricing.log.2017-10-01common.log.2017-09-19 common.log.2017-10-01 hibernate.log.2017-01-03 pricing.log.2017-09-20 pricing.log.2017-10-02common.log.2017-09-20 common.log.2017-10-02 pricing.log        pricing.log.2017-09-21 pricing.log.2017-10-03

第八步:继续查看哪个目录或者文件占用的空间最大,发现都是common.log和pricing.log相关的文件占用的空间最大,都是700M以上。至此,已经查明占用根目录”/”空间最多的原因是tomcat的日志文件太多,而且每一个日志文件都很大。

[root@hostname fare]# du -sh *|sort -h0    framework.log0    hibernate.log.2017-01-030    spring.log0    struts2.log0    xwork2.log4.0K  hibernate.log17M   common.zip215M  pricing.log216M  common.log667M  pricing.log.2017-10-08668M  common.log.2017-10-08674M  common.log.2017-10-05674M  pricing.log.2017-10-05678M  common.log.2017-10-07678M  pricing.log.2017-10-07679M  common.log.2017-10-06679M  pricing.log.2017-10-06683M  common.log.2017-10-04683M  pricing.log.2017-10-04690M  pricing.log.2017-09-10691M  common.log.2017-09-10711M  common.log.2017-09-12711M  pricing.log.2017-09-12719M  pricing.log.2017-09-11720M  common.log.2017-09-11737M  common.log.2017-09-30737M  pricing.log.2017-09-28737M  pricing.log.2017-09-30738M  common.log.2017-09-28742M  common.log.2017-09-29742M  pricing.log.2017-09-29744M  pricing.log.2017-10-09745M  common.log.2017-10-09751M  common.log.2017-10-01751M  pricing.log.2017-10-01754M  common.log.2017-09-13754M  pricing.log.2017-09-13760M  common.log.2017-10-03760M  pricing.log.2017-10-03783M  pricing.log.2017-10-02784M  common.log.2017-10-02791M  pricing.log.2017-09-18792M  common.log.2017-09-18797M  common.log.2017-09-27797M  pricing.log.2017-09-27804M  common.log.2017-09-17804M  common.log.2017-09-19804M  pricing.log.2017-09-17804M  pricing.log.2017-09-19808M  common.log.2017-09-26808M  pricing.log.2017-09-26815M  pricing.log.2017-09-24816M  common.log.2017-09-24821M  common.log.2017-09-14821M  pricing.log.2017-09-14821M  pricing.log.2017-09-23822M  common.log.2017-09-23826M  common.log.2017-09-25826M  pricing.log.2017-09-25827M  common.log.2017-09-16827M  pricing.log.2017-09-15827M  pricing.log.2017-09-16828M  common.log.2017-09-15831M  common.log.2017-09-22831M  pricing.log.2017-09-22851M  common.log.2017-09-21851M  pricing.log.2017-09-21860M  common.log.2017-09-20860M  pricing.log.2017-09-20

 第九步:从文件的命令规律,可以看出日志文件日期保留一个月,检查root用户是否有定时删除日志文件计划。如下命令查看所示,确实有每天凌晨03:15进行日志文件删除的计划。但是由于日志文件太多和根目录空间大小原因,导致根目录空间使用比例过高。在有部署自动监控工具,如zabbix等,会自动发送告警。

[root@hostname ~]# crontab -l15 3 * * * /u02/shell/rm_log_pricing.sh[root@hostname ~]# cat /u02/shell/rm_log_pricing.shfind /root/apache-tomcat-6.0.36-linux/bin/fare/ -name "common.log.2*" -mtime +30 | xargs rm -ffind /root/apache-tomcat-6.0.36-linux/bin/fare/ -name "pricing.log.2*" -mtime +30 | xargs rm -f

总结:

从运维的角度,不建议tomcat等应用程序部署在和Linux操作系统相关的文件系统中,尤其是直接部署在根目录下。一般都建议使用独立的文件系统来部署应用程序,无论从IO性能监控,文件系统空间使用监控都是有利的。

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


  • 上一条:
    CentOS 6.5 web服务器apache的安装与基本设置
    下一条:
    linux中快速列出文件列表的多种方法总结
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客