Linux Disk Management Series - disk quota management

First, the concept of Disk Management

  Linux system is a multi-user multitasking operating system when using the system, there will be multi-user share a disk, the user if a few of them take up a lot of disk space, the other is bound to compressed disk space and user permissions. Therefore, the system administrator should open the appropriate permissions to the disk to the user to the proper allocation of system resources.

Second, what is disk quota

  Disk quota management mechanism for disk space, the system administrator to monitor and restrict the use of a user or group of disk tools.

  Disk quota limit can be in two ways:

    1, can have user or group limit the number of the inode (i.e., number of files)

    The number 2, limit assigned to a user or group of disk blocks

  A disk quotas on a per user, per file system basis, if the user can create files on more than one file, you must set separately on each file system. Disk quotas for the partition only, not for directories or files.

Third, the disk quota limit premise

  Check whether the kernel supports (default installation, support qutoa)

    

  RPM to see whether the system is installed qutoa of (Red Hat / CentOS installed by default), if not installed install their own quota

    

  Check whether the startup script to open the quota (RHEL / CentOS default is already open) when the system starts

Third, the disk quota of step

  1, the hard disk partition, format, enable the quota function mount, the new test user

    Hard disk partition, format, mount: https: //www.cnblogs.com/qiuyu666/p/11843634.html

    The hard disk partition, format, enable the quota function mount

    Temporary Mount enabled:

    

    When you use mount to mount temporary data storage file / etc / mtab:

    

    

     Enable permanent mount need to modify the configuration file / etc / fstab:

    

    Create three test user user1, user2, user3, user group gg

    

  2, the main configuration file generated quota quotacheck

   quotacheck command : for scanning mounted file system and set the disk space limit  

    Parameters: -a scan all partitions

       -b backup  

       -d 调试模式  

       -c 重新创建文件  

       -f 强迫检查  

       -i 交互模式  

       -v 运行时显示详细的处理信息  

       -g 显示群组所占的目录文件数  

       -u 显示每个用户所占的目录数

       -M :『强制』进行quotacheck的扫描。

   

  3、用edquota给用户设置quota配额方案

  edquota(edit quota) 功能说明:编辑用户或群组的quota。

    语  法:edquota [-p <源用户名称>][-ug][用户或群组名称...] 或 edquota [-ug] -t

    补充说明:edquota预设会使用vi来编辑使用者或群组的quota设置。

    参  数:  -u   设置用户的quota,这是预设的参数。 

           -g   设置群组的quota。 

           -p<源用户名称>   将源用户的quota设置套用至其他用户或群组。

           -t   设置宽限期限。

   

   edquota user1  给用户user1配置磁盘配额,进入编辑页面(如上图)

  解析:blocks: 用户在该分区下 “已经使用” 的空间 “K” 为单位。
       soft:磁盘空间的软限制:用户使用的空间达到该值的时候,会报警。
       hard:磁盘空间的硬限制:最大能使用的空间。
       inodes:用户 “已经创建的” 文件数量。
       soft:用户创建的文件数量,达到该值的时候,报警。(一般不进行限制,或者限制值很大)
       hard:用户最多只能创建多少个文件。

  quota 命令:显示磁盘已使用的空间与限制。

  语  法:quota [-quvV][用户名称...] 或 quota [-gqvV][群组名称...]

  补充说明:执行quota指令,可查询磁盘空间的限制,并得知已使用多少空间

  参  数: -g   列出群组的磁盘空间限制。 

        -q   简明列表,只列出超过限制的部分。 

        -u   列出用户的磁盘空间限制。 

        -s   选择 inod或者硬盘空间来显示。 

        -v   显示该用户或群组,在所有挂入系统的存储设备的空间限制。

        -V   显示版本信息。

  

  非交互式命令 setquota:

  setquota是一个命令行配额编辑器,可以采用命令行的方式直接设置用户或用户组的配额限制。

  若想禁用配额限制,可以把相应参数设置为0。如果多个文件系统需要修改配额设置,每个文件系统需要调用一次setquota命令。

  语法格式:setquota [参数]

  常用参数:-a:编辑启用配额限制的所有文件系统

       -b:从标准输入读取配额设置信息

       -u:设置命令行参数name指定用户的配额

       -t:设置用户数据块与信息节点的宽限时间周期

  

  4、启动用户的配额 

  quotaon 命令:用来开启用户的磁盘空间的限制

  参数:-a 开启所有的磁盘配额限制    

     -g 组磁盘配额限制    

     -p 列出状态    

     -u 用户配额限制    

     -v 运行时显示详细的处理信息    

     --help 显示帮助信息

     --version 显示版本信息

  

  5、用账号登录,创建文件进行配额测试

   使用quota命令查看user1用户的磁盘已使用的磁盘与限制:

   

    登入user1用户进行测试

   

  user1用户在新建第5个文件的时候已经发出警告,但是文件新建成功:

   

   在新建帝个文件时,提示新建失败:

  

  6、关闭用户的磁盘空间的限制

  quotaoff 命令:用来关闭用户的磁盘空间的限制
  参数:-a 关闭所有的磁盘配额限制
     -g 组磁盘配额限制
     -p 列出状态
     -u 用户配额限制
     -v 运行时显示详细的处理信息
     --help 显示帮助信息
     --version 显示版本信息

  

 

 

  dd - 转换和拷贝文件

  当进行非强制的转换的时候,使用指定的输入和输出块大小拷贝文件 (默认是从标准输入到标准输出。)
  它每次从输入读取指定大小的一个块(默认是512字节)。 如果使用 bs=bytes 选项,并且没有转换,除了指定 sync, noerror, 或 notrunc 之外, 那么dd将把全部读到的数据(可以比请求读的少) 写到独立的输出块去。 这个输出块的长度和读到的数据 完全一样,除非指定使用 sync(同步) 转换,那样的话,数据结尾处将追加NUL字符(或空格,见下)。
其他情况下,输入的时候每次读一个块,然后处理,并将 输出结果收集起来,最后写到指定大小的数据块中去。最 终的输出块可能会比指定的大小短一些。
  数字值选项(以字节或块为单位)后面可以跟一个乘数: k=1024,b=512,w=2,c=1(w和c是GNU扩展语法。最好别 使用w,因为在system V中,它表示2,在4.2 BSD中,它 表示4)。两个或更多的数值表达式可以通过lqxrq乘起来。 GEU fileutils 4.0并且允许在数据块大小的叙述中使用 下列乘法后缀(用bs=,cbs=,obs=):M=1048576,G=1073741824, 同理可得T,P,E,Z,Y。D后缀表示数值是以 十进制表示的:kD=1000 MD=1000000 GD=1000000000等等。 (注意,在ls、df、du命令中,M等标记的大小是由环境 变量确定的,而在DD中,它的值是固定的。)
  if=file     从 file 中读而不是标准输入。
  of=file    写到 file 里去而不是标准输出。除非指定 conv=notrunc ,否则, dd 将把 file 截为O字节(或由 seek= 选项指定的大小)
  ibs=bytes    一次读 bytes 字节。默认是512。
  obs=bytes    一次写 bytes 字节。默认是512。
  bs=bytes    一次读和写 bytes 字节。这将覆盖 ibs 和 obs 设定的值(并且,设定 bs 不等于同时将 ibs 和 obs 设为同一个值,至少在 只使用 sync, noerror 或 notrunc 转换时是这样的。因为bs规定,每个输入块都应作为单独 的数据块拷贝到输出,而不把较短的块组合到一起)。
  cbs=bytes    为 block 转换和 unblock 转换指定转换块的大小。
  skip=blocks    在拷贝之前,跳过输入文件的前 blocks 块,每块大小为 ibs-byte 字节。
  seek=blocks    在拷贝之前,跳过输出文件的前 blocks 块,每块大小为 obs-byte 字节。
  count=blocks    只拷贝输入文件的前 blocks 块(每块的大小为 ibs-byte 字节),而不是全部内容,直到文件末尾。
  conv=转换[,转换]...    将文件按 转换 参数指定的方式转换(在lq,rq两边没有空格)。
转换方式包括:
        ascii               将EBCDIC转换成ascii。
        ebcdic            将ascii转换成ebcdic。
        ibm                将ascii转换成alternative ebcdic。
        block              每一行输入,无论长短,输出都是 cbs 字节,并且其中的lq换行rq(NEWLINE,即c中的')用 空格替换。如有必要,行尾会填充空格。
        unblock          用lq换行rq替换每个输入块( cbs 字节大小)末尾的空格。
        lcase              将大写字母转换成小写。
        ucase             将小写字母转换成大写。
        swab              交换每对输入字节。如果读入的字节数是奇数,最后 一个字节只是简单的复制到输出(因为没有能跟它交换的 字节了)(POSIX 1003.26,PASC翻译1003.2 3号和4号)。
        noerror           发生读错误时,继续进行。
        notrunc          不截断输出文件。
        sync               用0填充到每个输入块的末尾,使其大小为 ibs 字节。

   

 

   

Guess you like

Origin www.cnblogs.com/qiuyu666/p/11896799.html