Linuxは空間使用状況の実例を調べて詳しく説明します.

8771 ワード

Linuxは空間使用状況の実例を調べて詳しく説明します.
日常のLinux巡回検査では、ファイルシステムディレクトリの使用空間が高い場合に遭遇します.例えば、「df-h」を利用して、ルートディレクトリの空間が80%以上使用されていることを確認します.ルートディレクトリの空間が高すぎるということだけを知っています.カタログですか?それともファイルですか?ルートディレクトリの空間が高すぎるということも分かります.通常使用されている命令は”du-sh*」
第一歩:Linuxシステムのファイルシステムの使用状況を確認します.ルートディレクトリが以下の通り見えます.


[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


第二ステップ:ルートディレクトリに入り、du-shコマンドで各ディレクトリまたはファイルの空き領域を調べます.私たちが注目しているのはrootというディレクトリで、空間47 Gを占有しています.

[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
--  /proc       
0    proc
47G   root  ##              
15M   sbin
0    selinux
4.0K  srv
0    sys
80K   tmp
20K   u01
49G   u02

第三ステップ:rootディレクトリに入ると、実はrootユーザーのメインディレクトリです.私たちはlsコマンドから「apache-tomcat-6.0.36-linux」というtomcatのプログラムディレクトリの占有が多いと推測できます.

[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
第四ステップ:統計によると、確かに「apache-tomcat-6.0.36-linux」というディレクトリは47 Gを占有しています.しかし、この問題はまだ終わっていません.アプリケーションのディレクトリである以上、私の経験から言えば、tomcatのログファイルの占有空間が多いかもしれません.

[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

第五ステップ:tomcatのディレクトリがあることを見た以上、このtomcatが実行している可能性が高いです.psコマンドを利用してtomcatのプロセスがあるかどうかを確認します.普通はjavaというキーワードをフィルタできます.次のように、やっぱりtomcatが運行しています.では、占有可能な空間は最大でtomcatのログファイルです.

[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

第六ステップ:tomcatのプログラムディレクトリに入ると、どのディレクトリが占有しているかを確認する空間が一番大きいです.以下のように、「fare」というディレクトリが46 Gを占めていますが、「logs」はログディレクトリで23 Mを占めています.

[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

第七歩:「fare」カタログにどのような種類のカタログやファイルが保存されているかを確認し続けます.以下のような多くの類似のログファイルを見ました.開発者とコミュニケーションした後、確実なログファイルを確定します.

[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

第8ステップ:どのディレクトリまたはファイルが占有されているかを確認し続けると、comon.logとprincing.logに関するファイルが占有する空間が最大で、全部700 M以上であることが分かります.これまでルートディレクトリを占有していると判明しました.

[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

 ステップ9:ファイルの命令規則から、ログファイルの日付が一ヶ月間保留されていることが分かります.rootユーザがログファイルのスケジュールを削除するタイミングがあるかどうかを確認します.下記のコマンドで確認します.確かに毎日午前03時15分にログファイルの削除を行う計画があります.しかし、ログファイルが多すぎて、ルートディレクトリのスペースが大きすぎて、ルートディレクトリの空間使用率が高すぎます.自動監視ツールが配備されています.zabbixなど、自動的に警告を送ります.


[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

まとめ:
オペレーティングシステムに関連するファイルシステムにtomcatなどのアプリケーションを配置することは推奨されません.特にルートディレクトリの下に直接配置されます.一般的には、独立したファイルシステムを使用してアプリケーションを展開することが推奨されており、IO性能モニタからファイルシステム空間を監視することが有利である.
疑問があれば、メッセージをお願いします.あるいは、当駅のコミュニティで交流して討論してください.ありがとうございます.