Linux view a detailed example of space usage

  • 2020-06-15 10:57:36
  • OfStack

Linux view a detailed example of space usage

During the daily Linux tour, we will encounter cases where the file system directory is very high in space usage, such as using "ES5en-ES6en" to see that the root directory space is more than 80% used. It is not enough to know that the root directory space is overused. You also need to know whether the directory or the file is overusing the root directory space. Usually the command we use is "du-ES8en *".

Step 1: Look at the file system usage for the Linux system. You can see below that the root directory "/" has been used 81%.



[root@hostname ~]# df -h
Filesystem      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


Step 2: Go to the root directory and use the ES15en-ES16en command to query the space occupied by each directory or file, as /u02 is a separate file system and can be ignored. We are concerned with the root directory, which takes up space 47G.


[root@hostname ~]# cd /

[root@hostname /]# du -sh *
20K   arch
7.6M  bin
27M   boot
324K  dev
36M   etc
36K   home
136M  lib
26M   lib64
16K   lost+found
4.0K  media
0    misc
4.0K  mnt
0    net
8.0K  opt
4.0K  orbit-root
-- omit /proc Error in catalog statistics 
0    proc
47G   root  ## The root file system USES the largest directory 
15M   sbin
0    selinux
4.0K  srv
0    sys
80K   tmp
20K   u01
49G   u02

Step 3: Enter the root directory, which is also the root user's home directory. We can guess from the ls command may be [ES26en-ES27en-6.0.36-ES28en] this tomcat program directory occupies more.


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

Step 4: According to statistics, it is indeed [ES33en-ES34en-6.0.36-ES35en] that the directory occupies 47G. But that's not the end of the story, because since it's the directory of the application, in my experience it's likely that tomcat's log files take up more space.


[root@hostname ~]# du -sh *
4.0K  anaconda-ks.cfg
47G   apache-tomcat-6.0.36-linux
4.0K  Desktop
4.0K  Documents
4.0K  Downloads
56K   install.log
12K   install.log.syslog
4.0K  Music
4.0K  Pictures
4.0K  Public
4.0K  Templates
4.0K  Videos

Step 5: Now that you see the tomcat directory, it is likely that the tomcat is running. Use the ps command to see if there are tomcat processes. As it turns out, tomcat is running. It is likely that tomcat's log files will take up the most space.


[root@hostname ~]# ps -ef|grep java
root   4879 4836 0 08:26 pts/0  00:00:00 grep java
root   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

Step 6: Go to the tomcat program directory and see which takes up the most space. As follows, it is found that 1 [fare] directory occupies 46G, while [logs] log directory occupies 23M.


[root@hostname ~]# cd apache-tomcat-6.0.36-linux
[root@hostname apache-tomcat-6.0.36-linux]# ls
backup 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   backup
882M  bin
108K  conf
46G   fare
6.8M  lib
40K   LICENSE
23M   logs
4.0K  NOTICE
12K   RELEASE-NOTES
16K   RUNNING.txt
7.9M  temp
188M  webapps
7.1M  work

Step 7: Continue 1 to find out what type of directory or file is in the [fare] directory. You can see below that there are many similar log files, such as common.log and pricing.log. After communicating with the developer, determine the exact log file.


[root@hostname apache-tomcat-6.0.36-linux]# cd fare
[root@hostname fare]# ls
common.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-04
common.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-05
common.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-06
common.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-07
common.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-08
common.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-09
common.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.log
common.log.2017-09-16 common.log.2017-09-28 common.zip        pricing.log.2017-09-17 pricing.log.2017-09-29 struts2.log
common.log.2017-09-17 common.log.2017-09-29 framework.log       pricing.log.2017-09-18 pricing.log.2017-09-30 xwork2.log
common.log.2017-09-18 common.log.2017-09-30 hibernate.log       pricing.log.2017-09-19 pricing.log.2017-10-01
common.log.2017-09-19 common.log.2017-10-01 hibernate.log.2017-01-03 pricing.log.2017-09-20 pricing.log.2017-10-02
common.log.2017-09-20 common.log.2017-10-02 pricing.log        pricing.log.2017-09-21 pricing.log.2017-10-03

Step 8: Continue to check which directory or file takes up the most space and find that the files related to common.log and ES69en.log take up the most space, both 700M and above. At this point, it has been identified that the reason for taking up the most "/" space in the root directory is that tomcat has too many log files, and each log file is large.


[root@hostname fare]# du -sh *|sort -h
0    framework.log
0    hibernate.log.2017-01-03
0    spring.log
0    struts2.log
0    xwork2.log
4.0K  hibernate.log
17M   common.zip
215M  pricing.log
216M  common.log
667M  pricing.log.2017-10-08
668M  common.log.2017-10-08
674M  common.log.2017-10-05
674M  pricing.log.2017-10-05
678M  common.log.2017-10-07
678M  pricing.log.2017-10-07
679M  common.log.2017-10-06
679M  pricing.log.2017-10-06
683M  common.log.2017-10-04
683M  pricing.log.2017-10-04
690M  pricing.log.2017-09-10
691M  common.log.2017-09-10
711M  common.log.2017-09-12
711M  pricing.log.2017-09-12
719M  pricing.log.2017-09-11
720M  common.log.2017-09-11
737M  common.log.2017-09-30
737M  pricing.log.2017-09-28
737M  pricing.log.2017-09-30
738M  common.log.2017-09-28
742M  common.log.2017-09-29
742M  pricing.log.2017-09-29
744M  pricing.log.2017-10-09
745M  common.log.2017-10-09
751M  common.log.2017-10-01
751M  pricing.log.2017-10-01
754M  common.log.2017-09-13
754M  pricing.log.2017-09-13
760M  common.log.2017-10-03
760M  pricing.log.2017-10-03
783M  pricing.log.2017-10-02
784M  common.log.2017-10-02
791M  pricing.log.2017-09-18
792M  common.log.2017-09-18
797M  common.log.2017-09-27
797M  pricing.log.2017-09-27
804M  common.log.2017-09-17
804M  common.log.2017-09-19
804M  pricing.log.2017-09-17
804M  pricing.log.2017-09-19
808M  common.log.2017-09-26
808M  pricing.log.2017-09-26
815M  pricing.log.2017-09-24
816M  common.log.2017-09-24
821M  common.log.2017-09-14
821M  pricing.log.2017-09-14
821M  pricing.log.2017-09-23
822M  common.log.2017-09-23
826M  common.log.2017-09-25
826M  pricing.log.2017-09-25
827M  common.log.2017-09-16
827M  pricing.log.2017-09-15
827M  pricing.log.2017-09-16
828M  common.log.2017-09-15
831M  common.log.2017-09-22
831M  pricing.log.2017-09-22
851M  common.log.2017-09-21
851M  pricing.log.2017-09-21
860M  common.log.2017-09-20
860M  pricing.log.2017-09-20

Step 9: From the command pattern of the file, it can be seen that the date of the log file is retained for one month, and check whether the root user has a plan to regularly delete the log file. As the following command shows, there is indeed a plan for daily log file deletion at 03:15 am. However, due to too many log files and the size of the root directory space, the root directory space is overused. In the deployment of automatic monitoring tools, such as zabbix, will automatically send alerts.



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

Conclusion:

From an operational perspective, it is not recommended that applications such as tomcat be deployed in the file system associated with the Linux operating system, especially directly in the root directory. It is generally recommended to use a separate file system for application deployment, whether from IO performance monitoring, file system space usage monitoring is beneficial.

If you have any questions, please leave a message or go to this site community exchange discussion, thank you for reading, hope to help you, thank you for your support to this site!


Related articles: