Linux管理磁盘配额
生活随笔
收集整理的這篇文章主要介紹了
Linux管理磁盘配额
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
A、磁盤配額作用限制普通用戶使用磁盤空間,不至于因?yàn)閭€(gè)別人的浪費(fèi)而影響到其它人的正常使用;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> B、需要內(nèi)核的支持; C、只有Ext2/Ext3文件系統(tǒng)目前支持這種功能; D、需要用戶程序quota軟件包.
磁盤配額配置過程 1)、使用usrquota,grpquota選項(xiàng)掛載一個(gè)分區(qū),激活內(nèi)核的支持(只能在分區(qū)上做) 2)、方法:#mount –o usrquota,grpquota /dev/sdb1 /mnt/d1 或 mount –o remount,usrquota,grpquota / (因?yàn)楦夸浺呀?jīng)掛載過,可重新掛載) 3)、init 1 (進(jìn)入單用戶環(huán)境來配置)
4)、quotacheck –cvuga 檢查并創(chuàng)建磁盤配額的數(shù)據(jù)庫文件(存放位置:在每一個(gè)分區(qū)的根目錄下面) -c: 創(chuàng)建create; –v:更詳細(xì)地表述;–u:用戶user;–g:組group;-a:所有all 5)、edquota –u 為指定用戶分配磁盤空間和節(jié)點(diǎn)數(shù)量 6)、quota命令可以查看用戶的配額使用情況 如:[root@localhost root]# ls /mnt cdrom 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 bytes 255 heads, 63 sectors/track, 652 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 652 5237158+ 83 Linux Disk /dev/sdb: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device 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: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 274176 inodes, 548218 blocks 27410 blocks (5.00%) reserved for the super user First data block=0
17 block groups 32768 blocks per group, 32768 fragments per group 16128 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 30 mounts or 180 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 0 none /proc proc rw 0 0 usbdevfs /proc/bus/usb usbdevfs rw 0 0 none /dev/pts devpts rw,gid=5,mode=620 0 0 none /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+found aquota.group 和aquota.user兩個(gè)數(shù)據(jù)文件,用來分配組和用戶的配額情況。 [root@localhost root]# quotaon 或reboot或quotaon /dev/sdb1 [root@localhost root]# edquota -u redhat Disk quotas for user redhat (uid 502): Filesystem blocks soft hard inodes soft hard /dev/sdb1 125 10 0 80 0 10 注:blocks表示:塊的數(shù)量;inodes表示:節(jié)點(diǎn)的數(shù)量或建立文件的個(gè)數(shù);
soft表示:軟限制,可以超過這個(gè)數(shù)值的設(shè)定,但是有天數(shù)限制; hard表示:硬限制,這是一個(gè)任何時(shí)候也不能超過的數(shù)值,永遠(yuǎn)不可能達(dá)到。 [root@localhost root]# \ls /mnt/sd1 aquota.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]$ quota Disk 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 -lh total 8.0K drwxrwxr-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 -ld drwxr-xr-x 4 redhat root 4096 Mar 12 22:41 . [redhat@localhost redhat]$ dd if=/dev/zero of=file1 bs=1k count=1024 1024+0 records in 1024+0 records out [redhat@localhost redhat]$ quota -u redhat Disk 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]$ ls file1 file2 file3 file4 file5
[redhat@localhost redhat]$ quota -u redhat Disk 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 file9 sd(8,17): write failed, user file limit reached. touch: creating `file9': Disk quota exceeded [redhat@localhost redhat]$ touch file10 touch: creating `file10': Disk quota exceeded
[redhat@localhost redhat]$ quota -u redhat Disk 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/fstab LABEL=/ / ext3 defaults 1 1 none /dev/pts devpts gid=5,mode=620 0 0 none /proc proc defaults 0 0 none /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/sdb1 Block grace time: 7days; Inode grace time: 7days Block limits File limits
User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 20 0 0 2 0 0 redhat +- 1032 10 0 7days 9 0 9 #quotaoff /mnt/sdb1 #edquota –u redhat
如果要永久用配額限制的話,可以手動(dòng)編輯/etc/fstab 增加: /dev/sdb1 /mnt/sb1 ext3 defaults,usrquota,grpquota 0 0 保存退出! 取消磁盤配額的方法: 1)、使用命令quotaoff –a 關(guān)閉對(duì)應(yīng)磁盤分區(qū)上的配額文件 2)、可編輯/etc/fstab文件 3)、刪除/mnt/sd1目錄下的aquota.usr、aquota.group兩個(gè)數(shù)據(jù)庫文件.
磁盤配額配置過程 1)、使用usrquota,grpquota選項(xiàng)掛載一個(gè)分區(qū),激活內(nèi)核的支持(只能在分區(qū)上做) 2)、方法:#mount –o usrquota,grpquota /dev/sdb1 /mnt/d1 或 mount –o remount,usrquota,grpquota / (因?yàn)楦夸浺呀?jīng)掛載過,可重新掛載) 3)、init 1 (進(jìn)入單用戶環(huán)境來配置)
4)、quotacheck –cvuga 檢查并創(chuàng)建磁盤配額的數(shù)據(jù)庫文件(存放位置:在每一個(gè)分區(qū)的根目錄下面) -c: 創(chuàng)建create; –v:更詳細(xì)地表述;–u:用戶user;–g:組group;-a:所有all 5)、edquota –u 為指定用戶分配磁盤空間和節(jié)點(diǎn)數(shù)量 6)、quota命令可以查看用戶的配額使用情況 如:[root@localhost root]# ls /mnt cdrom 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 bytes 255 heads, 63 sectors/track, 652 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 652 5237158+ 83 Linux Disk /dev/sdb: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device 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: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 274176 inodes, 548218 blocks 27410 blocks (5.00%) reserved for the super user First data block=0
17 block groups 32768 blocks per group, 32768 fragments per group 16128 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 30 mounts or 180 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 0 none /proc proc rw 0 0 usbdevfs /proc/bus/usb usbdevfs rw 0 0 none /dev/pts devpts rw,gid=5,mode=620 0 0 none /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+found aquota.group 和aquota.user兩個(gè)數(shù)據(jù)文件,用來分配組和用戶的配額情況。 [root@localhost root]# quotaon 或reboot或quotaon /dev/sdb1 [root@localhost root]# edquota -u redhat Disk quotas for user redhat (uid 502): Filesystem blocks soft hard inodes soft hard /dev/sdb1 125 10 0 80 0 10 注:blocks表示:塊的數(shù)量;inodes表示:節(jié)點(diǎn)的數(shù)量或建立文件的個(gè)數(shù);
soft表示:軟限制,可以超過這個(gè)數(shù)值的設(shè)定,但是有天數(shù)限制; hard表示:硬限制,這是一個(gè)任何時(shí)候也不能超過的數(shù)值,永遠(yuǎn)不可能達(dá)到。 [root@localhost root]# \ls /mnt/sd1 aquota.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]$ quota Disk 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 -lh total 8.0K drwxrwxr-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 -ld drwxr-xr-x 4 redhat root 4096 Mar 12 22:41 . [redhat@localhost redhat]$ dd if=/dev/zero of=file1 bs=1k count=1024 1024+0 records in 1024+0 records out [redhat@localhost redhat]$ quota -u redhat Disk 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]$ ls file1 file2 file3 file4 file5
[redhat@localhost redhat]$ quota -u redhat Disk 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 file9 sd(8,17): write failed, user file limit reached. touch: creating `file9': Disk quota exceeded [redhat@localhost redhat]$ touch file10 touch: creating `file10': Disk quota exceeded
[redhat@localhost redhat]$ quota -u redhat Disk 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/fstab LABEL=/ / ext3 defaults 1 1 none /dev/pts devpts gid=5,mode=620 0 0 none /proc proc defaults 0 0 none /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/sdb1 Block grace time: 7days; Inode grace time: 7days Block limits File limits
User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 20 0 0 2 0 0 redhat +- 1032 10 0 7days 9 0 9 #quotaoff /mnt/sdb1 #edquota –u redhat
如果要永久用配額限制的話,可以手動(dòng)編輯/etc/fstab 增加: /dev/sdb1 /mnt/sb1 ext3 defaults,usrquota,grpquota 0 0 保存退出! 取消磁盤配額的方法: 1)、使用命令quotaoff –a 關(guān)閉對(duì)應(yīng)磁盤分區(qū)上的配額文件 2)、可編輯/etc/fstab文件 3)、刪除/mnt/sd1目錄下的aquota.usr、aquota.group兩個(gè)數(shù)據(jù)庫文件.
轉(zhuǎn)載于:https://blog.51cto.com/tzsky/237305
總結(jié)
以上是生活随笔為你收集整理的Linux管理磁盘配额的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到狼追我是什么意思
- 下一篇: 厂家官网常用链接