ติดตั้ง quota บน ubuntu
- ทดสอบกับ ubuntu 10.04
- เพื่อจัดการโควต้าดิสก์
- ติดตั้งโปรแกรมโควต้าดิสค์ด้วยคำสั่ง sudo apt-get install quota
- แก้ไขแฟ้ม /etc/fstab ในส่วนของ disk partition ที่ต้องการควบคุมโควต้า
จากเดิมสมมติตัวอย่างเป็นประมาณว่า
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=c97aad4f-fee7-40b4-9cba-aab7188169f4 / ext3 errors=remount-ro 0 1
/dev/hda1 / ext3 defaults,errors=remount-ro 0 1
ให้แก้ไขแทรกเพิ่มข้อความว่า usrquota,grpquota, เข้าไป กลายเป็น
UUID=c97aad4f-fee7-40b4-9cba-aab7188169f4 / ext3 usrquota,grpquota,errors=remount-ro 0 1
- สร้างแฟ้มสำหรับเก็บข้อมูลโควต้า ด้วยคำสั่งดังนี้
sudo touch /aquota.user /aquota.group
sudo chmod 600 /aquota.user /aquota.group
- จัดการ mount พื้นที่ / ใหม่ ด้วยคำสั่ง sudo mount -o remount /
ตรวจสอบความพร้อมของระบบ ด้วยคำสั่ง sudo quotacheck -agmuv
แล้วเริ่มระบบโควต้าด้วยคำสัง sudo quotaon -a
- ทดสอบดูผลด้วยคำสั่ง sudo repquota -a ได้ผลดังประมาณตัวอย่าง
*** Report for user quotas on device /dev/hda2
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 2573608 0 0 150844 0 0
daemon -- 8 0 0 3 0 0
lp -- 12 0 0 3 0 0
- กำหนดค่าโควต้าดิสก์ของผู้ใช้แต่ละคนด้วยคำสั่ง sudo setquota
ตัวอย่างเช่นต้องการจำกัดผู้ใช้ชื่อ myuser
มีพื้นที่ไม่เกิน 200000 blocks(200 Mbytes) และ/หรือ 1000 inodes(แฟ้ม)
โดยเริ่มเตือนที่ 160000 blocks(160 Mbytes) และ/หรือ 800 inodes ด้วยตัวอย่างคำสั่ง
sudo setquota -u myuser 160000 200000 800 1000 -a
- ตรวจสอบข้อมูลโควต้าของผู้ใช้ชื่อ myuser ด้วยตัวอย่างคำสั่ง sudo quota -v myuser
Disk quotas for user myuser (uid 14533):
Filesystem blocks quota limit grace files quota limit grace
/dev/hda2 4 160000 200000 1 800 1000
ความหมายของค่าต่างๆตามคอลัมน์คือ
blocks=ขนาดพื้นที่ดิสก์ที่ใช้ไป, quota=ขนาดดิสก์ที่เริ่มเตือน, limit=ขนาดดิสก์ที่จำกัด
files=จำนวนแฟ้มที่ใช้ไป, quota=จำนวนแฟ้มที่เริ่มเตือน, limit=จำนวนแฟ้มที่จำกัด
- เนื่องจากระบบไม่ได้ตรวจสอบโควต้าตลอดเวลาทุกครั้งที่มีผู้ใช้งานแฟ้มข้อมูล
จึงต้องตั้งค่าให้มีการตรวจสอบทุกวันโดยสร้างแฟ้มข้อมูลชื่อ
/etc/cron.daily/quota-check มีข้อมูลดังนี้
#!/bin/bash
/sbin/quotaoff -a
/sbin/quotacheck -agumv
/sbin/quotaon -a
และตั้งค่าให้มีการตรวจสอบโควต้าดิสก์ทุกครั้งที่บูทเครื่อง
โดยใส่เพิ่มบรรทัดข้อความคำสั่งเข้าไปไว้ในแฟ้ม /etc/rc.local ดังนี้
sh /etc/cron.daily/quota-check