您的位置:首页 > 运维架构 > Linux

Linux管理磁盘配额

2009-12-01 14:40 656 查看
A、磁盘配额作用限制普通用户使用磁盘空间,不至于因为个别人的浪费而影响到其它人的正常使用;B、需要内核的支持;C、只有Ext2/Ext3文件系统目前支持这种功能;D、需要用户程序quota软件包.
                 磁盘配额配置过程1)、使用usrquota,grpquota选项挂载一个分区,激活内核的支持(只能在分区上做)2)、方法:#mount –o usrquota,grpquota /dev/sdb1 /mnt/d1或 mount –o remount,usrquota,grpquota / (因为根目录已经挂载过,可重新挂载)3)、init 1 (进入单用户环境来配置)
4)、quotacheck –cvuga 检查并创建磁盘配额的数据库文件(存放位置:在每一个分区的根目录下面)-c: 创建create; –v:更详细地表述;–u:用户user;–g:组group;-a:所有all5)、edquota –u 为指定用户分配磁盘空间和节点数量6)、quota命令可以查看用户的配额使用情况如:[root@localhost root]# ls /mntcdrom floppy[root@localhost root]# mkfs.ext3 /dev/sdb1 /mnt/sd1/
mke2fs 1.32 (09-Nov-2002)mkfs.ext3: bad blocks count - /mnt/sd1/[root@localhost root]# mkfs.ext3 -f /dev/sdb1 /mnt/sd1/[root@localhost root]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sda1 * 1 652 5237158+ 83 LinuxDisk /dev/sdb: 4294 MB, 4294967296 bytes255 heads, 63 sectors/track, 522 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sdb1 250 522 2192872+ 83 Linux[root@localhost root]# mkfs.ext3 /dev/sdb1
mke2fs 1.32 (09-Nov-2002)
Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)274176 inodes, 548218 blocks27410 blocks (5.00%) reserved for the super userFirst data block=0
17 block groups32768 blocks per group, 32768 fragments per group16128 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912Writing inode tables: doneCreating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 30 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@localhost root]# mount /dev/sdb1 /mnt/sd1 -o usrquota,grpquota
[root@localhost root]# mount/dev/sda1 on / type ext3 (rw)none on /proc type proc (rw)
usbdevfs on /proc/bus/usb type usbdevfs (rw)none on /dev/pts type devpts (rw,gid=5,mode=620)
none on /dev/shm type tmpfs (rw)/dev/sdb1 on /mnt/sd1 type ext3 (rw,usrquota,grpquota)[root@localhost root]# more /etc/mtab/dev/sda1 / ext3 rw 0 0none /proc proc rw 0 0usbdevfs /proc/bus/usb usbdevfs rw 0 0none /dev/pts devpts rw,gid=5,mode=620 0 0none /dev/shm tmpfs rw 0 0/dev/sdb1 /mnt/sd1 ext3 rw,usrquota,grpquota 0 0[root@localhost root]# quotacheck –cvuga <-------quotacheck: Scanning /dev/sdb1 [/mnt/sd1] done
quotacheck: Checked 2 directories and 0 files[root@localhost root]# ls /mnt/sd1/aquota.group aquota.user lost+foundaquota.group 和aquota.user两个数据文件,用来分配组和用户的配额情况。[root@localhost root]# quotaon 或reboot或quotaon /dev/sdb1[root@localhost root]# edquota -u redhatDisk quotas for user redhat (uid 502):Filesystem blocks soft hard inodes soft hard/dev/sdb1 125 10 0 80 0 10注:blocks表示:块的数量;inodes表示:节点的数量或建立文件的个数;
soft表示:软限制,可以超过这个数值的设定,但是有天数限制;hard表示:硬限制,这是一个任何时候也不能超过的数值,永远不可能达到。[root@localhost root]# \ls /mnt/sd1aquota.group aquota.user lost+found[root@localhost root]# mkdir /mnt/sd1/redhat[root@localhost root]# chown redhat /mnt/sd1/redhat/[root@localhost root]# su - redhat[redhat@localhost redhat]$ pwd/home/redhat[redhat@localhost redhat]$ cd /mnt/sd1/redhat/[redhat@localhost redhat]$ pwd
/mnt/sd1/redhat[redhat@localhost redhat]$ quotaDisk quotas for user redhat (uid 502):Filesystem blocks quota limit grace files quota limit grace/dev/sdb1 4 10 0 1 0 9[redhat@localhost redhat]$ ls -lhtotal 8.0Kdrwxrwxr-x 2 redhat redhat 4.0K Mar 12 22:41 dir
drwxrwxr-x 2 redhat redhat 4.0K Mar 12 22:41 dir1[redhat@localhost redhat]$ ls -lddrwxr-xr-x 4 redhat root 4096 Mar 12 22:41 .[redhat@localhost redhat]$ dd if=/dev/zero of=file1 bs=1k count=10241024+0 records in1024+0 records out[redhat@localhost redhat]$ quota -u redhatDisk quotas for user redhat (uid 502):Filesystem blocks quota limit grace files quota limit grace/dev/sdb1 1040* 10 0 6days 4 0 9
[redhat@localhost redhat]$ touch file1[redhat@localhost redhat]$ touch file2[redhat@localhost redhat]$ touch file3[redhat@localhost redhat]$ touch file4[redhat@localhost redhat]$ touch file5[redhat@localhost redhat]$ lsfile1 file2 file3 file4 file5
[redhat@localhost redhat]$ quota -u redhatDisk quotas for user redhat (uid 502):Filesystem blocks quota limit grace files quota limit grace/dev/sdb1 1032* 10 0 6days 6 0 9
[redhat@localhost redhat]$ touch file6[redhat@localhost redhat]$ touch file7[redhat@localhost redhat]$ touch file8[redhat@localhost redhat]$ touch file9sd(8,17): write failed, user file limit reached.touch: creating `file9': Disk quota exceeded[redhat@localhost redhat]$ touch file10touch: creating `file10': Disk quota exceeded
[redhat@localhost redhat]$ quota -u redhatDisk quotas for user redhat (uid 502):Filesystem blocks quota limit grace files quota limit grace/dev/sdb1 1032* 10 0 6days 9* 0 9[redhat@localhost redhat]$ cat /etc/fstabLABEL=/ / ext3 defaults 1 1none /dev/pts devpts gid=5,mode=620 0 0none /proc proc defaults 0 0none /dev/shm tmpfs defaults 0 0/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0/dev/sdb5 /mnt/sdb5 ext3 defaults 0 0[root@localhost root]# repquota -a*** Report for user quotas on device /dev/sdb1Block grace time: 7days; Inode grace time: 7daysBlock limits File limits
User used soft hard grace used soft hard grace----------------------------------------------------------------------root -- 20 0 0 2 0 0redhat +- 1032 10 0 7days 9 0 9#quotaoff /mnt/sdb1#edquota –u redhat
如果要永久用配额限制的话,可以手动编辑/etc/fstab 增加:/dev/sdb1 /mnt/sb1 ext3 defaults,usrquota,grpquota 0 0保存退出!取消磁盘配额的方法:1)、使用命令quotaoff –a 关闭对应磁盘分区上的配额文件 2)、可编辑/etc/fstab文件 3)、删除/mnt/sd1目录下的aquota.usr、aquota.group两个数据库文件.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: