Use Quota to create a disk Quota for Vsftpd

Source: Internet
Author: User

Use Quota to create a disk Quota for Vsftpd

1. Add a 2 GB hard disk
Open VMware and click VM --- settings-add-Hard Disk ---- Create a new virtual disk-SCSI-disk size (GB) 2.0 ---- restart the VM System
2. Verify the hard disk:
[Root @ viong ~] # Fdisk-l
1234 # added 2 GB/dev/sdb
Disk/dev/sdb: 2147 MB, 2147483648 bytes ----------- à indicates that the Disk has taken effect.
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

3. Divide/dev/sdb into an extended partition, create a new logical partition, format it as an ext3 partition, and set it to restart auto load.
[Root @ viong ~] # Fdisk/dev/sdb
# Partition/dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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)
Command (m for help): n # Add a partition
Command action
E extended
P primary partition (1-4)
# E add extended partitions
Partition number (1-4): 1
First cylinder (1-261, default 1): Press ENTER
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-261, default 261): Press ENTER
Using default value 261
Command (m for help): w # Save and exit
The partition table has been altered!
Calling ioctl () to re-read partition table.
Syncing disks.
[Root @ viong ~] # Fdisk/dev/sdb
Command (m for help): n
Command action
L logical (5 or over)
P primary partition (1-4)
# L add logical partitions
First cylinder (1-261, default 1): Press ENTER
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-261, default 261): Press ENTER
Using default value 261
Command (m for help): w
The partition table has been altered!
Calling ioctl () to re-read partition table.
Syncing disks.

4. Verify the partition status of/dev/sdb.
Disk/dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sdb1 1 261 2096451 5 Extended
/Dev/sdb5 1 261 2096419 + 83 Linux

5 format/dev/sdb5
[Root @ viong ~] # Mkfs. ext3/dev/sdb5 format sdb5
Mke2fs 1.39 (29-may-2006)
Filesystem label =
OS type: Linux
Block size = 4096 (log = 2)
Fragment size = 4096 (log = 2)
262144 inodes, 524104 blocks
26205 blocks (5.00%) reserved for the super user
First data block = 0
Maximum filesystem blocks = 536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768,983 04, 163840,229 376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.

6. Create a directory to mount sdb5
[Root @ viong ~] # Mkdir/mnt/ftp
[Root @ viong ~] # Mount/dev/sdb5/mnt/ftp/
Mount sdb5 to/mnt/ftp/
[Root @ viong ~] # Vi/etc/fstab
Add the last message to enable automatic mounting upon restart.
/Dev/sdb5/mnt/ftp ext3 defaults 0 0

7 # mount-a check whether the system is automatically mounted after the system is restarted.
8. Create an ftp user for testing
[Root @ red-hat-5 ~] # Useradd-d/mnt/ftp/hom-s/sbin/nologin hom
[Root @ red-hat-5 ~] # Passwd hom
Changing password for user hom.
New UNIX password:
Retype new UNIX password:
Passwd: all authentication tokens updated successfully.
[Root @ red-hat-5 ~] # Ll/mnt/ftp/
Total 20
Drwx ------ 2 hom 4096 01-10 17:15 hom
Drwx ------ 2 root 16384 01-10 16:53 lost + found

[Root @ red-hat-5 ~] # Service vsftpd start
Start vsftpd For vsftpd: [OK]

9. Create disk quotas for ftp users
The hom user created just now is in the/dev/sdb5 partition. If we want to set the disk quota for the hom user, we need to modify the records of the root partition in/etc/fstab, change the 4th fields in the/dev/sdb5 partition to ults and usrquota, as shown below:

/Dev/sdb5/mnt/ftp ext3 defaults, usrquota 0 0

In order not to take effect after system restart, use the following command to take effect directly
# Mount-o remount/dev/sdb5

10. If you want to apply a magnetic quota to a group, you need to add the parameter "maid", as shown below:
/Dev/sdb5/mnt/ftp ext3 defaults, usrquota, kgquota 0 0

11 generate the current disk usage table for each file system with the quota enabled
[Root @ viong/] # quotacheck-avug
Quotacheck: Scanning/dev/sdb5 [/mnt/ftp] quotacheck: Cannot stat old user quota file: no such file or directory
Quotacheck: Old group file not found. Usage will not be substracted.
Done
Quotacheck: Checked 4 directories and 6 files
Quotacheck: Old file not found.

Note:
-A: scans all disks with quota support mounted in the/etc/mtab.
-U: scanning users' archives and directories
-V: displays the scanning process.
-G: the files and directories used by the scanning group
-M: Force quotacheck.

12. Set the quota capacity
[Root @ viong/] # edquota-u hom (set the quota)

Set Disk Quota for user hom
The system automatically uses
Open the quota file in VI text as follows:
Disk quotas for user hom (uid 501 ):
Filesystem blocks soft hard inodes soft hard
/Dev/sdb5 160 1024 4 0 0

Here, I set the hard block size to kb for testing.

Note:
Filesystem is the name of the file system with quota enabled
Blocks displays the number of blocks currently used by the user, in KB.
Soft is used to set the soft block limit on the file system. the user can exceed soft capacity within the grace period, but the disk capacity must be reduced to soft capacity within the grace period
Hard is used to set the hard block limit of the user on the file system, which cannot exceed the capacity
Inodes displays the number of I nodes currently used by the user.
The last two columns are used to set the soft and hard I node limits on the file system. The difference is that the soft limits can be exceeded within a period of time. The capacity between soft and hard is actually the capacity of the wide limit! It can serve as a warning to users! This period is called grace period, which defaults to seven days. The transition period can be expressed in seconds, minutes, hours, days, weeks, or months.
If any of the above values is set to 0, that limit will not be set.
Note:
-U: edit the user's quota
-G: edit the group's quota
-T: edit the grace period (that is, after the quota value is exceeded, the hard disk's grace period can also be used)
-P: copy template (to create a user or group) to another user (or group)

13 open the disk quota monitoring process
[Root @ viong/] # quotaon-avu

U is the user g is the group, and I have not set the g parameter here
/Dev/sdb5 [/mnt/ftp]: user quotas turned on

Note:
-A: all quota settings are enabled (/etc/mtab settings are automatically searched)
-U: User's quota startup
-G: the quota settings of the group are enabled.
-V: displays a message.

14 check whether the user's quota is set
[Root @ viong/] # quota-uvs hom
Filesystem blocks quota limit grace files quota limit grace
/Dev/sdb5 160 1024 4 0 0

Note:
-G: displays group groups.
-U: displays the user
-V: displays the quota value.
-S: Select inod or hard disk space to display

15. Set grace period (grace period) for soft restrictions only
[Root @ viong/] # edquota-t
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/sdb5 7 days 7 days

16 view User quota
1234567 *** Report for user quotas on device/dev/sdb5
Block grace time: 7 days; Inode grace time: 7 days
Block limits File limits
User used soft hard grace
----------------------------------------------------------------------
Root -- 35880 0 0 5 0 0
Hom -- 16 0 1024 4 0 0

Note:
-A is listed in the/etc/fstab file, which contains the usage of the partitions added to the quota settings and the users and groups.
-G: list the disk space limits of all groups.
-U: List disk space restrictions for all users
-V: Display All space limits of the user or group

Test whether the user quota takes effect

Next, we will use flashxp for testing and upload the original scenery to the original site. It will fail to be transmitted to 1 MB. This indicates that it has taken effect.

[Root @ viong/] # quotaoff-vug/dev/sdb5

Disable/mnt/ftp partition Disk Quota
/Dev/sdb5 [/mnt/ftp]: user quotas turned off

Note:
-A: all quota settings are disabled (/etc/mtab settings are automatically searched)

Finally, delete the part for setting the quota in/etc/fstab.

To sum up, you must master the following principles when setting disk quotas for users:
A. Because the limit on the number of files is not very practical for users, the disk quota usually only limits the disk capacity occupied by users.
B. neither soft limit nor hard limit is set for the user. This value is smaller than the disk capacity or file quantity occupied by the user. Otherwise, the user may not be able to log on to and use the system normally.
C. Set the number of hard limits to be greater than the soft limit. Otherwise, there is no practical significance.
D././boot/./proc./mnt/cdrom, etc. Do not use the quota
E. in practice, quota restricts the entire partition. For example, if your/dev/sdb5 is mounted under/mnt/ftp, all directories under/mnt/ftp will be restricted!

Four Advanced configurations of vsftpd Server:

VsFTPd configuration Tutorial:

Install and configure the FTP server in CentOS 7

Simple and practical Ubuntu FTP setup

Set up FTP server and Apache server on Ubuntu

Install the LAMP \ vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Simple case of anonymous uploading of SeLinux and vsftpd on the RHEL6 Platform

Install vsftpd source code in Linux

Install and configure the FTP server vsftpd in openSUSE 13.2/13.1

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.