• Linux磁盘配额


    作用

    限制用户或组对磁盘空间的使用,例如文件服务器,邮件服务器.web服务器......

    配置磁盘配额

    lv的创建

    • 首先创建一个pv
    [root@localhost /]# pvcreate /dev/sdb
      Physical volume "/dev/sdb" successfully created.
    
    • 创建一个vg1
    [root@localhost /]# vgcreate vg1 /dev/sdb
      Volume group "vg1" successfully created
    
    • 创建一个lv并赋额1000M
    [root@localhost /]# lvcreate -L 1000M -n lv1 vg1
      Logical volume "lv1" created.
    

    格式化lv1

    [root@localhost /]# mkfs.ext4 /dev/vg1/lv1
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    64000 inodes, 256000 blocks
    12800 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=262144000
    8 block groups
    32768 blocks per group, 32768 fragments per group
    8000 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    

    挂载分区,测试分区是否正常

    [root@localhost /]# mkdir /lv1 && mount /dev/vg1/lv1 /lv1
    [root@localhost /]# cd lv1/
    [root@localhost lv1]# ls
    lost+found    //证明已经成功挂载
    

    开启磁盘配额

    • 执行下面的命令开启quota功能
    [root@localhost ~]# mount /dev/vg1/lv1 /lv1
    [root@localhost ~]# mount -o remount,usrquota,grpquota /dev/vg1/lv1
    
    • 查看quota是否正常开启
    [root@localhost ~]# mount| grep quota|grep lv
    /dev/mapper/vg1-lv1 on /lv1 type ext4 (rw,relatime,quota,usrquota,grpquota,data=ordered)
    

    创建用户和组

    [root@localhost ~]# useradd u1 && groupadd z1
    [root@localhost ~]# gpasswd -a u1 z1
    Adding user u1 to group z1
    

    生成quota配置文件

    • 关闭SeLinux
    [root@localhost ~]# setenforce 0
    setenforce: SELinux is disabled
    
    • 生成配置文件
    [root@localhost /]# cd lv1 && quotacheck -acug
    [root@localhost lv1]# ls
    aquota.group  aquota.user  lost+found
    

    启动quota功能

    [root@localhost lv1]# quotaon /dev/vg1/lv1
    

    修改quota配置文件

    [root@localhost lv1]# edquota -u u1
    Disk quotas for user u1 (uid 1000):
      Filesystem                   blocks       soft       hard     inodes     soft     hard
      /dev/mapper/vg1-lv1               0          0          0          0        0        0
    
    • 通过修改softhard的值,限制其写入文件的大小
    [root@localhost lv1]# edquota -u u1
    Disk quotas for user u1 (uid 1000):
      Filesystem                   blocks       soft       hard     inodes     soft     hard
      /dev/mapper/vg1-lv1               0       1000       1200          0        0        0
    

    切换成u1用户后,进行写文件测试

    [u1@localhost test]$ ll
    total 0
    -rw-rw-r-- 1 u1 u1 0 Apr  7 16:19 1
    [u1@localhost test]$  dd if=/dev/zero of=./1 bs=1M
    dm-2: warning, user block quota exceeded.
    dm-2: write failed, user block limit reached.
    dd: error writing ‘./1’: Disk quota exceeded
    2+0 records in
    1+0 records out
    1331200 bytes (1.3 MB) copied, 0.00222401 s, 599 MB/s
    [u1@localhost test]$ ll
    total 1300
    -rw-rw-r-- 1 u1 u1 1331200 Apr  7 16:19 1
    [u1@localhost test]$  dd if=/dev/zero of=./1 bs=2M
    dm-2: warning, user block quota exceeded.
    dm-2: write failed, user block limit reached.
    dd: error writing ‘./1’: Disk quota exceeded
    1+0 records in
    0+0 records out
    1331200 bytes (1.3 MB) copied, 0.0649324 s, 20.5 MB/s
    [u1@localhost test]$ ll
    total 1300
    -rw-rw-r-- 1 u1 u1 1331200 Apr  7 16:20 1
    

    出现明显的超出磁盘配额信息,则针对u1的磁盘配额生效.

  • 相关阅读:
    视频上云解决方案EasyCVR支持接入海康SDK吗?
    视频上云网关EasyCVR程序数据库内数据会丢失吗?
    视频上云解决方案EasyCVR打包软件在linux下解压后台无法运行问题排查
    视频上云解决方案EasyCVR发布linux版本
    视频流媒体平台EasyNVR使用Vue.js开发报[Vue warn]错误问题解决方案
    监控现场无固定IP及公有云服务器如何通过手机查看视频直播?
    幼儿园EasyNVR能力层安防监控平台调用视频直播流报404错误解决方案
    海康NVR的RTSP视频流能否在EasyNVR流媒体平台中正常播放?
    视频云端流媒体平台EasyNVR存储的录像为什么呈现每小时一段录像?
    如何查看EasyNTS智能云组网硬件终端内的资源使用情况?
  • 原文地址:https://www.cnblogs.com/quail2333/p/12653846.html
Copyright © 2020-2023  润新知