大多数文件系统都会保留一部分空间留作紧急情况时用(比如硬盘空间满了),这样能保证有些关键应用(比如数据库)在硬盘满的时候有点余地,不致于马上就 crash,给监控系统和管理员一点时间去察觉。不过有时候这部分预留的硬盘空间不用的话有点浪费。如何释放这部分系统预留的空间呢?
在 Linux ext2/ext3/ext4 文件系统上通常默认预留5%的硬盘空间,如果硬盘是 4TB 的话就意味着有 200GB 的空间就这样浪费了,我们可以通过 tune2fs 来改变5%的默认设置,比如只预留1%的空间。可不可以设成0%呢?当然可以,但是不推荐。
调整 /dev/sdd1,只预留1%的空间:
# tune2fs -m 1 /dev/sdd1tune2fs 1.41.12 (17-May-2010)Setting reserved blocks percentage to 1% (2684381 blocks)
调整后检查数据如下:
问题发生的时候:
[root@it-zabbixdb04.wj ~]#df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4 75G 2.1G 69G 3% /
tmpfs tmpfs 16G 0 16G 0% /dev/shm
/dev/sda1 ext4 485M 33M 427M 8% /boot
/dev/sdb1 ext4 3.0T 2.8T 126G 100% /opt
磁盘有剩余空间,但是使用了是100%
[root@it-zabbixdb04.wj ~]#tune2fs -l /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: /opt
Filesystem UUID: 5886b7c0-2301-4d20-a009-a5be5ccd30bb
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 201326592
Block count: 805306359
Reserved block count: 8053063 ##保留块
Free blocks: 644464000
Free inodes: 201325541
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 832
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Fri Sep 23 00:55:38 2016
Last mount time: Thu Oct 27 13:51:01 2016
Last write time: Mon Apr 10 09:58:45 2017
Mount count: 4
Maximum mount count: 38
Last checked: Fri Sep 23 00:55:38 2016
Check interval: 15552000 (6 months)
Next check after: Wed Mar 22 00:55:38 2017
Lifetime writes: 18 TB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 7f85d235-189b-4c8a-be27-a9bd0535b763
Journal backup: inode blocks
[root@it-zabbixdb04.wj ~]#
8053063.0/805306359 =0.0099999999999 = 1%
参考:
另外的一种情况是:
机器df和du的结果为啥不一样...
处理方法是lsof | grep delete