Linux系统中对磁盘配额(Quota),软阵列(RAID)的实现
1.创建测试的用户和修改挂载的参数
[root@localhost ~]# useradd user1 –新建两个用户
[root@localhost ~]# useradd user2
[root@localhost ~]# mount -o remount,usrquota,grpquota /mnt/sdb –重新挂载,加参数
[root@localhost ~]# mount -l –查看挂载选项
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mnt/sdb type ext4 (rw,usrquota,grpquota)
[root@localhost ~]# quotacheck -avug -mf –生成两个quota文件
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/mnt/sdb] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# ll /mnt/sdb –查看生成的两个文件
total 26
-rw——-. 1 root root 6144 Jan 9 17:59 aquota.group
-rw——-. 1 root root 6144 Jan 9 17:59 aquota.user
drwx——. 2 root root 12288 Jan 9 17:55 lost+found
[root@localhost ~]# quotaon -avug –开启quota功能
/dev/sdb1 [/mnt/sdb]: group quotas turned on
/dev/sdb1 [/mnt/sdb]: user quotas turned on
[root@localhost ~]# edquota -u user1
Disk quotas for user user1 (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 10 20 0 0 0
[root@localhost ~]# edquota -u user2
Disk quotas for user user2 (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 5 10 0 0 0
[root@localhost ~]# useradd user1 –新建两个用户
[root@localhost ~]# useradd user2
[root@localhost ~]# mount -o remount,usrquota,grpquota /mnt/sdb –重新挂载,加参数
[root@localhost ~]# mount -l –查看挂载选项
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mnt/sdb type ext4 (rw,usrquota,grpquota)
[root@localhost ~]# quotacheck -avug -mf –生成两个quota文件
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/mnt/sdb] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# ll /mnt/sdb –查看生成的两个文件
total 26
-rw——-. 1 root root 6144 Jan 9 17:59 aquota.group
-rw——-. 1 root root 6144 Jan 9 17:59 aquota.user
drwx——. 2 root root 12288 Jan 9 17:55 lost+found
[root@localhost ~]# quotaon -avug –开启quota功能
/dev/sdb1 [/mnt/sdb]: group quotas turned on
/dev/sdb1 [/mnt/sdb]: user quotas turned on
[root@localhost ~]# edquota -u user1 –用户user1使用/mnt/sdb目录不要起过20M
Disk quotas for user user1 (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 10000 20000 0 0 0
[root@localhost ~]# edquota -u user2 –用户user2对sdb目录不要超过10M,大于5M超出指定时间删除
Disk quotas for user user2 (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 5000 10000 0 0 0
2.验证配额
[root@localhost ~]# su – user1
[user1@localhost ~]$ cd /mnt/sdb
[user1@localhost sdb]$ dd if=/dev/zero of=12 bs=1M count=5 –创建5M的文件没有警告信息,正常
5+0 records in
5+0 records out
5242880 bytes (5.2 MB) copied, 0.0525754 s, 99.7 MB/s
[user1@localhost sdb]$ ll -h 12
-rw-rw-r–. 1 user1 user1 5.0M Jan 9 18:16 12
[user1@localhost sdb]$ dd if=/dev/zero of=123 bs=1M count=21 –创建12M的文件有警告信息,表示失败
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: writing `123′: Disk quota exceeded
20+0 records in
19+0 records out
20475904 bytes (20 MB) copied, 0.20094 s, 102 MB/s
[user1@localhost sdb]$ ll -h 123
-rw-rw-r–. 1 user1 user1 0 Jan 9 18:17 123
[user1@localhost sdb]$ exit
logout
[root@localhost ~]# su – user2 –用户user2测试
[user2@localhost ~]$ cd /mnt/sdb
[user2@localhost sdb]$ dd if=/dev/zero of=23 bs=1M count=8 –写入8M文件成功
sdb1: warning, user block quota exceeded.
8+0 records in
8+0 records out
8388608 bytes (8.4 MB) copied, 0.0923618 s, 90.8 MB/s
[user2@localhost sdb]$ ll -h 23 –查看文件大小
-rw-rw-r–. 1 user2 user2 8.0M Jan 9 18:23 23
[user2@localhost sdb]$
[user2@localhost sdb]$ dd if=/dev/zero of=23 bs=1M count=11 –写入11M文件失败
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: writing `23′: Disk quota exceeded
10+0 records in
9+0 records out
10235904 bytes (10 MB) copied, 0.106298 s, 96.3 MB/s
[user2@localhost sdb]$
3.查看quota配置,修改警告时间,取消quota
[root@localhost ~]# quota -vu user1 user2 –查找指定的用户quota信息
Disk quotas for user user1 (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 0 10000 20000 0 0 0
Disk quotas for user user2 (uid 501):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 8193* 5000 10000 6days 1 0 0
[root@localhost ~]# repquota -av –所有用户和quota信息
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
———————————————————————-
root — 13 0 0 2 0 0
user1 — 0 10000 20000 0 0 0
user2 +- 8193 5000 10000 6days 1 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 3
Used average: 3.000000
[root@localhost ~]# edquota -t –修改文件警告天数(Block 天数 Inode 天数)
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/sdb1 7days 7days
[root@localhost ~]# vim /etc/warnquota.conf –查看警告信息
[root@localhost ~]# quotaoff /mnt/sdb –关闭quota功能
推荐阅读:
Linux学习笔记:磁盘配额(Quota)与高级文件系统管理 http://www.linuxidc.com/Linux/2013-02/79558.htm
RHCE培训笔记——磁盘配额 http://www.linuxidc.com/Linux/2013-03/81237.htm
Linux下磁盘配额(quota)应用与实战教程 http://www.linuxidc.com/Linux/2012-12/75900.htm
RHEL5.5中创建softRaid10并使用quota限制磁盘配额 http://www.linuxidc.com/Linux/2012-11/75147.htm
VMware下RedHat 5.4磁盘配额(Quota) http://www.linuxidc.com/Linux/2012-09/70937.htm