Vsftpd完全攻略(六)利用quota对Vsftpd做磁盘配额

    关于vsftpd磁盘配额,这里强调一下,vsftpd本身不带这个功能,是系统本身自带的quota这个软件,quota字面上就是限额的意思.
quota磁盘配额比较常见的作用:
1.避免恶意ftp用户用垃圾数据塞满宝贵的硬盘.
2.虚拟空间不同用户的容量限制
3.邮局用户的容量限制
4.多人多任务使用同一个硬盘,妥善分配系统资源

 

1.分区并以支持配额功能的方式挂载文件系统

    除了内核和quota软件的支持以外,实施磁盘配额功能还有一个前提条件,即制定的分区必须已经挂载且支持磁盘配额功能。

[root@localhost ~]# fdisk -l    //检测确认新硬盘
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM

Disk /dev/sdb: 21.4 GB, 21474836480 bytes      //已经检测到第二块硬盘
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

 

         先把/dev/sdb划分为一个扩展分区,再新建一个逻辑分区,格式化为ext3分区,然后设置为重启自动加载。
[root@localhost ~]# fdisk /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.


The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n     //新建分区  
Command action
   e   extended
   p   primary partition (1-4)
e                  //选择创建为扩展分区
Partition number (1-4):
Value out of range.
Partition number (1-4): 1         //选择1做为扩展分区的编号
First cylinder (1-2610, default 1):       回收即可
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):    回收即可
Using default value 2610

Command (m for help): p     //查看分区情况

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+   5  Extended

Command (m for help): n 
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l                        //选择创建的逻辑分区
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):
Using default value 2610

Command (m for help): p 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+   5  Extended
/dev/sdb5               1        2610    20964762   83  Linux

Command (m for help): w          //保存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+   5  Extended
/dev/sdb5               1        2610    20964762   83  Linux

[root@localhost ~]# mkfs.ext3 /dev/sdb5     //格式化/dev/sdb5 为ext3文件系统
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5241190 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@localhost ~]# mount -o usrquota,grpquota /dev/sdb5 /var/ftproot/    //以支持配额功能的方式挂载文件系统     (使用带“-o usrquota,grpquota”选项的mount命令挂载,以便增加用户,组配额功能的支持。对于支持配额功能的文件系统,在mount信息中显示“usrquota,grpquota”)


[root@localhost ~]# mount | grep "quota"     
/dev/sdb5 on /var/ftproot type ext3 (rw,usrquota,grpquota)

 

    将“usrquota,grpquota”写入到“/etc/fstab”文件中,以便每次开机后自动支持配额功能的方式挂载该分区
[root@localhost ~]# vim /etc/fstab    //修改sdb5分区的挂载配置
/dev/sdb5               /var/ftproot            ext3    defaults        0 0

2.检测磁盘配额并生成配额文件

    使用quotacheck命令可以对文件系统进行磁盘配额检测,也可以用来建立配额文件,以便保存用户,组在该分区中的配额设置。若当前主机中没有支持的磁盘配额功能的文件系统,则执行quotacheck命令时讲会出现“quotacheck:Can't find filesystem to check or filesystem not mounted with quota option”的提示信息
[root@localhost ~]# quotacheck -augcv    //检查当前系统所有分区中的磁盘配额信息,并在可用的文件系统中建立配额文件。
quotacheck: Scanning /dev/sdb5 [/var/ftproot] quotacheck: Cannot stat old user quota file: 没有那个文件或目录
quotacheck: Cannot stat old group quota file: 没有那个文件或目录
quotacheck: Cannot stat old user quota file: 没有那个文件或目录
quotacheck: Cannot stat old group quota file: 没有那个文件或目录
done
quotacheck: Checked 3 directories and 2 files
quotacheck: Old file not found.
quotacheck: Old file not found.

注释

-a   :扫瞄所有在 /etc/mtab 里头已经 mount 的具有 quota 支持的磁盘
-u  :扫瞄使用者的档案与目录
-v  :显示扫瞄过程
-g  :扫瞄群组使用的档案与目录
-m :强制进行 quotacheck

[root@localhost ~]# ls -l /var/ftproot/    //确认文件系统中的用户配额文件,组配额文件。
-rw------- 1 root root  6144 01-20 11:35 aquota.group
-rw------- 1 root root  6144 01-20 11:35 aquota.user

3.编辑用户和租账户的配额设置

    配额设置是实现磁盘配额功能中最重要环节,使用edquota命令结合“-u”“-g”选项可用户编辑用户或租的配额设置。正确执行edquota命令后,讲进入到文本编辑界面(默认调用vi做为编辑程序),可以设置磁盘容量,文件大小的软,硬限制数值。
[root@localhost ~]# edquota -u lpc    //编辑lpc用户的配额设置
Disk quotas for user lpc (uid 500):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdb5                         0          0       1024          2        0       10
   //这里我为了测试把硬限制值设置为1024KB     文件数量设置成10个

4.启动文件系统的磁盘配额功能

    启动和关闭文件系统的磁盘功能分别使用quota ,quotaoff 命令进行,需要指定设备文件名或文件系统的挂载点目录作为命令参数,quotaon命令是哟个的选项与quotacheck 的选项类似

[root@localhost ~]# quotaon -ugv /var/ftproot/  //启用文件系统的用户,组磁盘配额功能,输出命令执行过程信息
/dev/sdb5 [/var/ftproot]: group quotas turned on
/dev/sdb5 [/var/ftproot]: user quotas turned on

 

5.查看用户或分区的配额使用情况

  尚未使用配额空间时,显示结果将提示“none”
[root@localhost ~]# quota -u lpc
Disk quotas for user lpc (uid 500): none
[root@localhost ~]# quotaon -ugv /var/ftproot/
/dev/sdb5 [/var/ftproot]: group quotas turned on
/dev/sdb5 [/var/ftproot]: user quotas turned on

磁盘配额的使用情况

 [root@localhost ~]# quota -u lpc
Disk quotas for user lpc (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb5       4       0    1024               1       0      10        
[

6.测试

使用lpc登录FTP ,上传文件,当用户的lpc 的文件数超过10个后上传失败。

 

测试当占用空间大于1024KB的时候上传失败。

你可能感兴趣的:(职场,休闲,挂载虚拟硬盘并格式化,为vsftp用户做磁盘配额)