1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ディスク容量確認コマンドについて

Posted at

はじめに

サーバーのログサイズが大きくなってディスクを逼迫するケースがあります。
障害対応時にはディスク容量の調査コマンドを実行する必要があります。

調査コマンド

ディスク容量を確認して残りサイズを確認する

[root@localhost log]# df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
devtmpfs                  908M     0  908M    0% /dev
tmpfs                     919M     0  919M    0% /dev/shm
tmpfs                     919M  8.6M  911M    1% /run
tmpfs                     919M     0  919M    0% /sys/fs/cgroup
/dev/mapper/centos-root    17G  1.8G   16G   11% /
/dev/sda1                1014M  150M  865M   15% /boot
tmpfs                     184M     0  184M    0% /run/user/0

ログサイズをランキング10で表示

サーバーのログサイズが大きくなった際は以下のコマンドを実行して
ログサイズが大きい順番にTop10が表示されます

[root@localhost log]# du -h /var/log | sort -rh | head -10
4.2M    /var/log
1.7M    /var/log/anaconda
1.4M    /var/log/audit
20K     /var/log/tuned
12K     /var/log/test_dir
0       /var/log/rhsm
0       /var/log/chrony

ログを圧縮するコマンド

ログのサイズが大きい場合はログを圧縮します。

tar cvzf ファイル名.tar.gz ファイル名

例
[root@localhost log]# tar cvzf messages-20240121.tar.gz messages-20240121

ファイルが作成されます
-rw-r--r--  1 root   root    43760  5月 17 21:27 messages-20240121.tar.gz

元のログファイルが不要な場合は削除します
rm -i  messages-20240121

フォルダを圧縮するコマンド

過去のログをフォルダに移動させて圧縮する

mkdir 202401

2024年1月のログを表示させる

[root@localhost log]# ls -ltr *-202401??
-rw-------. 1 root root      0  1月 18 21:34 spooler-20240121
-rw-------. 1 root root   1199  1月 21 18:36 maillog-20240121
-rw-------. 1 root root 218030  1月 21 19:30 messages-20240121
-rw-------. 1 root root   7443  1月 21 19:30 secure-20240121
-rw-------. 1 root root   4049  1月 21 19:32 cron-20240121
-rw-------. 1 root root  24984  1月 21 19:32 boot.log-20240121

2024年1月のログを202401フォルダへ移動させる

mv *-202401?? 202401

202401フォルダへ移動したことを確認する

[root@localhost log]# ls -tlr 202401
合計 260
-rw-------. 1 root root      0  1月 18 21:34 spooler-20240121
-rw-------. 1 root root   1199  1月 21 18:36 maillog-20240121
-rw-------. 1 root root 218030  1月 21 19:30 messages-20240121
-rw-------. 1 root root   7443  1月 21 19:30 secure-20240121
-rw-------. 1 root root   4049  1月 21 19:32 cron-20240121
-rw-------. 1 root root  24984  1月 21 19:32 boot.log-20240121

2024年のフォルダを圧縮する

tar cvzf ファイル名.tar.gz フォルダ名

[root@localhost log]# tar cvzf 202401.tar.gz 202401
202401/
202401/boot.log-20240121
202401/cron-20240121
202401/maillog-20240121
202401/messages-20240121
202401/secure-20240121
202401/spooler-20240121

圧縮後、tar.gzファイルの中身を確認する
tarコマンド tオプション アーカイブの内容の一覧を表示する

以下のサイトが参考になりました。
https://atmarkit.itmedia.co.jp/ait/articles/1608/18/news021.html

[root@localhost log]# tar tvf 202401.tar.gz
drwxr-xr-x root/root         0 2024-05-17 21:34 202401/
-rw------- root/root     24984 2024-01-21 19:32 202401/boot.log-20240121
-rw------- root/root      4049 2024-01-21 19:32 202401/cron-20240121
-rw------- root/root      1199 2024-01-21 18:36 202401/maillog-20240121
-rw------- root/root    218030 2024-01-21 19:30 202401/messages-20240121
-rw------- root/root      7443 2024-01-21 19:30 202401/secure-20240121
-rw------- root/root         0 2024-01-18 21:34 202401/spooler-20240121
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?