首先说一下quota磁盘配额。
磁盘配额是针对某个分区来设置的,我们知道/home 是所用普通用户的家,假设/home共100G。普通用户有tom,jerry,yuri,nicholas。他们四个人共用这100G,但是yuri这个人喜欢看电影,他给他的家目录下放了一堆小电影。导致一共就100G的空间。光yuri就占了80G。这是很不公平的。所以就出现了磁盘配额。
磁盘的磁盘配额功能需要挂载时就添加的,假若磁盘没有quota功能可以挂载
[root@www mnt]# mount -o usrquota /dev/sdb3 /mnt/tmp
[root@www mnt]# mount |tail -n 1
/dev/sdb3 on /mnt/tmp type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)
输入edquota -u wjx(用户名)。来配置他的磁盘配额
Disk quotas for user wjx (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/sdb3 0 0 30000 0 0 0
比较特别的是xfs的quota是整合到文件系统中的。并不是其他的外挂程序来管理、可以通过xfs_quota来直接管理
xfs 主要针对 群组,个人,或单独的目录来进行磁盘使用率的限制
xfs_quota -x -c "指令" [挂载点]
查看该分区的状况
[root@www mnt]# xfs_quota -x -c "report" /mnt/tmp
User quota on /mnt/tmp (/dev/sdb3)
Blocks
User ID Used Soft Hard Warn/Grace
---------- --------------------------------------------------
root 0 0 0 00 [--------]
wjx 0 0 30000 00 [--------]
设置限制
[root@www mnt]# xfs_quota -x -c "limit -u bsoft=250M bhard=300M wjx" /mnt/tmp
[root@www mnt]# xfs_quota -x -c "report" /mnt/tmp
User quota on /mnt/tmp (/dev/sdb3)
Blocks
User ID Used Soft Hard Warn/Grace
---------- --------------------------------------------------
root 0 0 0 00 [--------]
wjx 0 256000 307200 00 [--------]
设置宽限时间
[root@www mnt]# xfs_quota -x -c "timer -u -b 14days" /mnt/tmp #时间改为14days
查看quota分区状态
[root@www mnt]# xfs_quota -x -c "state" /mnt/tmp
User quota state on /mnt/tmp (/dev/sdb3)
Accounting: ON
Enforcement: ON
Inode: #131 (2 blocks, 2 extents)
Group quota state on /mnt/tmp (/dev/sdb3)
Accounting: OFF
Enforcement: OFF
Inode: #0 (0 blocks, 0 extents)
Project quota state on /mnt/tmp (/dev/sdb3)
Accounting: OFF
Enforcement: OFF
Inode: #0 (0 blocks, 0 extents)
Blocks grace time: [14 days 00:00:30]
Inodes grace time: [7 days 00:00:30]
Realtime Blocks grace time: [7 days 00:00:30]
再说一下磁盘加密。
磁盘加密是基于磁盘的加密。是最安全的加密方式。cryptsetup
[root@www mnt]# cryptsetup luksFormat /dev/sdb3
WARNING!
========
This will overwrite data on /dev/sdb3 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
[root@www mnt]# cryptsetup open /dev/sdb3 secret
Enter passphrase for /dev/sdb3:
格式化。并挂载(注意。这里是/dev/mapper/secret)
[root@www mnt]# mkfs.xfs /dev/mapper/secret
meta-data=/dev/mapper/secret isize=256 agcount=4, agsize=130944 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=523776, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@www mnt]# mount /dev/mapper/secret /mnt/tmp/
最后使用完了再卸载加密
[root@www mnt]# umount tmp
[root@www mnt]# cryptsetup close secret
cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile //将两个文件关联
使用上面的那个命令就可以将这块磁盘写进fstab中自动挂载。系统开机时会去读/root/lukspsfile去找密码