linux 针对目录空间配额,linux磁盘配额quota
Linux是一個(gè)多用戶多任務(wù)的操作系統(tǒng),在使用中可能會(huì)有幾個(gè)人對(duì)服務(wù)器有操作,幾個(gè)用戶共同使用一個(gè)共享磁盤的情況,因?yàn)槲覀兊挠脖P是有限的,我們需要對(duì)用戶的空間進(jìn)行限制。這里使用磁盤配額,可以很方便的對(duì)用戶的空間進(jìn)行額度限制。
1:加入一塊硬盤,分出一個(gè)主分區(qū):
[root@localhost?~]#?fdisk?/dev/sdb
Device?contains?neither?a?valid?DOS?partition?table,?nor?Sun,?SGI?or?OSF?disklabel
Building?a?new?DOS?disklabel?with?disk?identifier?0xa03faa82.
Changes?will?remain?in?memory?only,?until?you?decide?to?write?them.
After?that,?of?course,?the?previous?content?won't?be?recoverable.
Warning:?invalid?flag?0x0000?of?partition?table?4?will?be?corrected?by?w(rite)
WARNING:?DOS-compatible?mode?is?deprecated.?It's?strongly?recommended?to
switch?off?the?mode?(command?'c')?and?change?display?units?to
sectors?(command?'u').
Command?(m?for?help):?n
Command?action
e???extended
p???primary?partition?(1-4)
p
Partition?number?(1-4):?1
First?cylinder?(1-2610,?default?1):
Using?default?value?1
Last?cylinder,?+cylinders?or?+size{K,M,G}?(1-2610,?default?2610):
Using?default?value?2610
Command?(m?for?help):?p
Disk?/dev/sdb:?21.5?GB,?21474836480?bytes
255?heads,?63?sectors/track,?2610?cylinders
Units?=?cylinders?of?16065?*?512?=?8225280?bytes
Sector?size?(logical/physical):?512?bytes?/?512?bytes
I/O?size?(minimum/optimal):?512?bytes?/?512?bytes
Disk?identifier:?0xa03faa82
Device?Boot??????Start?????????End??????Blocks???Id??System
/dev/sdb1???????????????1????????2610????20964793+??83??Linux
Command?(m?for?help):?w
The?partition?table?has?been?altered!
Calling?ioctl()?to?re-read?partition?table.
Syncing?disks.
2.格式化分區(qū)并掛載[root@localhost?~]#?mkfs.ext4?/dev/sdb1[root@localhost?~]#?mkdir?/data???##創(chuàng)建一個(gè)用戶共享使用的目錄
[root@localhost?~]#?mount?/dev/sdb1?/data/???##將分區(qū)掛載到共享目錄
[root@localhost?~]#?mount????##查看掛載情況
/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)
/dev/sda1?on?/boot?type?ext4?(rw)
none?on?/proc/sys/fs/binfmt_misc?type?binfmt_misc?(rw)
/dev/sdb1?on?/data?type?ext4?(rw)
寫入到開機(jī)掛載里面[root@localhost?~]#?vi?/etc/fstab
[root@localhost?~]#?tail?-1?/etc/fstab
/dev/sdb1???????????????/data???????????????????ext4????defaults????????0?0
3.重新掛載使文件目錄支持磁盤配額:[root@localhost?~]#?mount?-o?remount,usrquota,grpquota?/dev/sdb1[root@localhost?~]#?mount
/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)
/dev/sda1?on?/boot?type?ext4?(rw)
none?on?/proc/sys/fs/binfmt_misc?type?binfmt_misc?(rw)
/dev/sdb1?on?/data?type?ext4?(rw,usrquota,grpquota)???##再次查看分區(qū)掛載可以看到支持+磁盤配額
同樣使它開機(jī)掛載支持磁盤配額:[root@localhost?~]#?vi?/etc/fstab
[root@localhost?~]#?tail?-1?/etc/fstab
/dev/sdb1???????????????/data???????????????????ext4????defaults,usrquota,grpquota????????0?0
3。下載磁盤配額軟件:[root@localhost?~]#?yum?-y?install?quota
4.生成磁盤配額的數(shù)據(jù)庫(kù)文件:[root@localhost?~]#?quotacheck?-ugvc?/data/
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?[/data]?done
quotacheck:?Cannot?stat?old?user?quota?file?/data/aquota.user:?沒有那個(gè)文件或目錄.?Usage?will?not?be?substracted.
quotacheck:?Cannot?stat?old?group?quota?file?/data/aquota.group:?沒有那個(gè)文件或目錄.?Usage?will?not?be?substracted.
quotacheck:?Cannot?stat?old?user?quota?file?/data/aquota.user:?沒有那個(gè)文件或目錄.?Usage?will?not?be?substracted.
quotacheck:?Cannot?stat?old?group?quota?file?/data/aquota.group:?沒有那個(gè)文件或目錄.?Usage?will?not?be?substracted.
quotacheck:?Checked?2?directories?and?0?files
quotacheck:?Old?file?not?found.
quotacheck:?Old?file?not?found.
查看生成的磁盤配置數(shù)據(jù)庫(kù)文件[root@localhost?~]#?ls?/data/
aquota.group??aquota.user??lost+found
5.新建需要限制的用戶和組:[root@localhost?~]#?useradd?u01???##新建用戶
[root@localhost?~]#?useradd?u02
[root@localhost?~]#?echo?"123123"?|passwd?--stdin?u01
更改用戶?u01?的密碼?。
passwd:?所有的身份驗(yàn)證令牌已經(jīng)成功更新。
[root@localhost?~]#?echo?"123123"?|passwd?--stdin?u02
更改用戶?u02?的密碼?。
passwd:?所有的身份驗(yàn)證令牌已經(jīng)成功更新。
[root@localhost?~]#?groupadd?g01????##新建組
[root@localhost?~]#?usermod?-g?g01?u01???##將用戶加入組
[root@localhost?~]#?usermod?-g?g01?u02
[root@localhost?~]#?id?u01???##確認(rèn)用戶信息
uid=500(u01)?gid=502(g01)?組=502(g01)
[root@localhost?~]#?id?u02
uid=501(u02)?gid=502(g01)?組=502(g01)
6.對(duì)用戶進(jìn)行額度配置:
setauota ??-u?用戶 或(-g 組) ?大小軟限制 大小硬限制 ?數(shù)量軟限制 ?數(shù)量硬限制 ?對(duì)哪個(gè)目錄
##大小限制的單位是kb,軟限制是當(dāng)達(dá)到這個(gè)限制時(shí),再創(chuàng)建文件或?qū)霐?shù)據(jù),會(huì)出現(xiàn)提示信息,不過(guò)還可以再往里面新建。當(dāng)?shù)竭_(dá)硬限制時(shí),就真的無(wú)法創(chuàng)建了。[root@localhost?~]#?setquota?-u?u01?10000?15000?10?15?/data/
7.開啟磁盤配額: ? ?重啟系統(tǒng)也可以[root@localhost?~]#?quotaon?-a
給所有人可寫入權(quán)限即可,要在其他用戶新建文件測(cè)試[root@localhost?~]#?chmod?777?/data/[root@localhost?~]#?su?-?u01???##切換到u01
[u01@localhost?~]$?touch?/data/{1..20}.mp3?????##新建20個(gè)文件
sdb1:?warning,?user?file?quota?exceeded.?????##這個(gè)到達(dá)軟限制,有提醒
sdb1:?write?failed,?user?file?limit?reached.?????##這個(gè)到達(dá)硬限制,提示寫入錯(cuò)誤
touch:?無(wú)法創(chuàng)建"/data/16.mp3":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/17.mp3":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/18.mp3":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/19.mp3":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/20.mp3":?超出磁盤限額
最后查看目錄,發(fā)現(xiàn)創(chuàng)建了15個(gè)文件,這個(gè)15是硬限制的設(shè)置[u01@localhost?~]$?ls?/data/
10.mp3??12.mp3??14.mp3??1.mp3??3.mp3??5.mp3??7.mp3??9.mp3?????????aquota.user
11.mp3??13.mp3??15.mp3??2.mp3??4.mp3??6.mp3??8.mp3??aquota.group??lost+found
[u01@localhost?~]$?exit
logout
給組配置額度:[root@localhost?~]#?setquota?-g?g01?15000?20000?15?20?/data/
切換到u02測(cè)試:[root@localhost?~]#?su?-?u02
[u02@localhost?~]$?touch?/data/{1..10}.txt
sdb1:?write?failed,?group?file?limit?reached.
touch:?無(wú)法創(chuàng)建"/data/6.txt":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/7.txt":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/8.txt":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/9.txt":?超出磁盤限額
touch:?無(wú)法創(chuàng)建"/data/10.txt":?超出磁盤限額
發(fā)現(xiàn)只創(chuàng)建了5個(gè)文件,就不能再創(chuàng)建了。因?yàn)閯偛艑?duì)組進(jìn)行了限制20個(gè)數(shù)量的硬限制,而u01、u02都在g01組里面,u01的15個(gè)文件已經(jīng)存在了,所以u(píng)02只能創(chuàng)建五個(gè)了。[u02@localhost?~]$?ls?/data/
10.mp3??12.mp3??14.mp3??1.mp3??2.mp3??3.mp3??4.mp3??5.mp3??6.mp3??8.mp3??aquota.group??lost+found
11.mp3??13.mp3??15.mp3??1.txt??2.txt??3.txt??4.txt??5.txt??7.mp3??9.mp3??aquota.user
[u02@localhost?~]$?exit
logout
[root@localhost?~]#
總結(jié)
以上是生活随笔為你收集整理的linux 针对目录空间配额,linux磁盘配额quota的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 飞行棋 c语言,骑士飞行棋【纯c】
- 下一篇: 计算机用手机的网络,电脑做热点让手机上网