Let's take a look at what is LVM and disk quotas

LVM overview

  • LVM (Logical Volume Manager)
    • LVM has elastic scaling function
    • LVM can dynamically adjust the disk capacity while keeping the existing data unchanged, thereby improving the flexibility of disk management
    • Because the /boot partition is used to store boot files, the /boot partition cannot be created based on LVM
    • LVM is composed of multiple disk partitions
name Description
PV (Physical Volume, physical volume) The physical volume is the basic storage device of the LVM mechanism, and usually corresponds to an ordinary partition or the entire hard disk. When creating a physical volume, a reserved block is created at the head of the partition or hard disk to record the attributes of LVM, and the storage space is divided into basic units (PE) with a default size of 4MB to form a physical volume.
(Physical volume is a disk partition created by fdisk)
ON PE is the basic unit of a physical volume with a size of 4M. Determined by the size of the logical volume and volume group
VG (volume Group, volume group) One or more physical volumes form a whole, which is called a volume group, in which physical volumes can be dynamically added or removed
LV Logical volume, logical volume) A piece of space divided from the volume group forms a logical volume. Use tools such as mkfs to create a file system on the logical volume

Insert picture description here

LVM management commands and operating steps

LVM management commands

Features PV management VG management LV management
Scan pvscan vgscan lvscan
Creata build pvcreata vgcreata lvcreata
Display pvdisplay vgdisplay lvdisplay
Remove pvremove vgremove lvremove
Extend —— vgextend lvextend
Reduce —— vgreduce lvreduce

The main operation steps of LVM

  • 1. Shut down the host, add two new hard disks, and restart the host
  • 2. First use the fdisk tool to divide the disk devices /dev/sdb and /dev/sdc into primary partitions sdb1 and sdcl, and change the ID mark number of the partition type to "8e". The
    partition created with fdisk is created directly without formatting Physical volume
    • fdisk /dev/sdb
      fdisk /dev/sdc
  • 3. Create a physical volume
    • pvcreate /dev/sdb1 /dev/sdc1
  • 4. Create a volume group, the volume group is named vgnamel
    • vgcreate vgname1 / dev/sdb1/ dev/sdb2
  • 5. Create a logical volume, the logical volume is named lvname1, the capacity is 15GB, and the generated file path is /dev/vgname1/lvname1
    • lvcreate -L 15G -n lvname1 vgname1
  • 6. Format the logical volume, create an XFS file system, and mount it to /opt
    • mkfs -t xfs / dev/vgname1/lvname1
    • mount /dev/vgname1/lvname1 /opt
  • 7. Further expansion
    • vgextend vgname1 / dev / sdc2
    • lvextend -L +5G /dev/ vgname1/ lvname1
      If there is no "+" in front of 5G, it means that the disk space is at most 5G
    • xfs_growfs /dev/vgnamel/lvname1
      refresh file system capacity (xfs)
    • resize2fs /dev/vgnamel/lvname1
      refresh the file system capacity (ext4)

Disk quota

Overview of Disk Quota

  • Function: Limit the space used by the disk for the specified user or group, or limit the number of files created
  • Conditions for achieving disk quota
    • Need Linux kernel support
    • Install xfsprogs and quota packages
  • Features of Linux Disk Quota
    • Scope: for the specified file system (partition)
    • Restricted object: user account, group account
    • Restriction type: disk capacity, number of files
    • Limitation method: soft limit, hard limit
  • Why use the disk quota function?
    • Because when the disk space of the Linux root partition is exhausted, the Linux operating system will no longer be able to create new files, and at the same time, failures such as service program crashes and system failures may occur. Therefore, in order to avoid problems like insufficient disk space in the server, the disk quota function can be enabled to limit the disk space and the number of files used by the user in the specified file system (partition) to prevent individual users from maliciously or unintentionally occupying a large amount. Disk space to maintain the stability and continuous availability of system storage space.

      In the CentOS system, different file systems use different disk quota configuration management tools. For example, the XFS file system is managed by the xfs quota tool; the EXT3 and EXT4 file systems are managed by the quota tool.

Disk quota operation steps (CentOS7)

以支持配合功能的方式挂载文件系统
编辑用户和组账号的配额设置
验证磁盘配额功能
查看磁盘配额使用情况
  • 1. Check whether the xfsprogs and xfs_quota packages have been installed
    • View: rpm -q xfsprogs quota
    • If not: yum install -y xfsprogs quota
  • 2. Mount the file system in a way that supports the quota function
    • umount / dev / vgname1 / lvname1
      unmount
    • mount -o usrquota,grpquota /dev / vgname1/ lvname1 /opt
      Add mount parameters "usrquota, grpquota" to increase support for user and group quota functions
    • Because of the temporary mounting, the mounting of the mount will be invalid after the restart,
      so use the following editing /etc/fstab to mount to prevent the restart from failing
    • vim /etc/fstab
    • /dev/vgname1/lvname1/ opt xfs defaults,usrquota, grpquota 0 0
    • mount -a
      -a选项,将/etc/fstab的所有内容重新加载
  • 3.编辑用户和组账号的配额设置
    • useradd qianzhan
    • passwd qianzhan
    • xfs_quota -x -c ‘limit -u bsoft=80M bhard=100M isoft=40 ihard=50 qianzhan’ /opt/
    • -x:表示启动专家模式,在当前模式下允许对配额系统进行修改的所有管理命令可用
      -c:表示直接调用管理命令
      -g:指定组账号对象
      -u:指定用户账号对象

      bsoft:设置磁盘容量的软限制数值(默认单位为KB)
      bhard:设置磁盘容量的硬限制数值(默认单位为KB)
      isoft:设置磁盘文件数的软限制数值
      ihard:设置磁盘文件数的硬限制数值
    • xfs_quota -x -c ‘limit -u bsoft=80M bhard=100M qianzhan’ /opt/
      仅限制磁盘容量
    • xfs_quota -x -c 'limit -u isoft=4 ihard=5 qianzhan '/opt/
      仅限制文件数
    • xfs_quota -c ‘quota -uv qianzhan’ /opt/
      查看qianzhan磁盘容量限制
    • xfs_quota -c ‘quota -i -uv qianzhan’ /opt/
      查看qianzhan文件数限制
  • 4.验证磁盘配额功能
    • chmod 777 /opt
      给目录权限
    • su qianzhan
    • cd /opt
    • dd if=/dev/zero of=/opt/ddtest.txt bs=10M count=12
      验证磁盘容量超限

      dd命令是一个设备转换和连续复制命令
      if=指定输入设备(或文件)
      of=指定输出设备((或文件)
      bs=指定读取数据块的大小
      count=指定读取数据块的数量
      /dev/zero "零"设备文件,可以无限的提供空字符。常用来生成一个特定大小的文件
    • touch {aa,bb,cc,dd, ee,ff}.txt
      验证磁盘文件数超限
  • 5.查看配额使用情况
    • xfs_quota -x -c 'report -a’
      查看所有可用分区的磁盘容量配额使用情况
    • xfs_quota -x -c ’ report -abih"
      查看磁盘容量和文件数的报告

磁盘配额操作步骤(ext4)

  • 1.基本磁盘管理 (柱面)
    • 分区
      • fdisk /dev/sdb(磁盘设备)
      • n:创建分区
        e:扩展分区
        p:主分区
      • 序列号 1
      • 柱面序列 回车
      • 分区大小 +5G
      • 分区类型
        83 ext4 类型(默认)
        82 swap类型
        b fat类型
      • p:查看
        w:保存退出
        q:放弃退出
  • 格式化
    • ext4类型
      mkfs -t ext4 /dev/sdb1(设备)
    • swap类型
      mkswap /dev/sdb5(设备)
      swapon /dev/sdb5 (添加虚拟内存)
      swapoff /dev/sdb5 (关闭虚拟内存)(不可变更原有swap大小)
    • fat类型
      mkfs.vfat -F 32 /dev/sdb6(设备)
  • 2.动态卷轴管理
    • 物理卷(分区类型 8e)
      pvcreate /dev/sdc1(设备1) /dev/sdd1(设备2)
    • 卷组
      vgcreate yu(卷组名称) /dev/sdc1(设备1) /dev/sdd1(设备2)
    • 逻辑卷
      lvcreate -L 50G(大小) -n yu01(逻辑卷名称) yu(卷组名称)
    • 格式化
      mkfs -t ext4 /dev/yu/yu01
    • 挂载
      mkdir /yu01 (创建挂载点)

      mount /dev/yu/yu01 /yu01
  • 2.磁盘配额管理quota
    • vim /etc/fstab
      /dev/yu/yu01 /yu01 ext4 defaults,usrquota,grpquota 0 0
      mount -a
    • 关闭安全功能
      setenforce 0
    • 创建配额配置文件
      quotacheck -cvug /dev/yu/yu01

      -u、-g:检测用户、组配额
      -c:创建配额数据文件
      -v:显示执行过程信息
    • cd /yu01
    • ls mount point to check
      whether aquota.group aquota.user exists
    • Set quota for the specified user zhangsan
      edquota -u zhangsan
    • Turn on the quota function. If you turn off the quota function, use quotaoff
      quotaon -ugv /yu01
      chmod 777 /yu01
      su zhangsan
    • Verify
      dd if=/dev/zero of=yun.txt bs=10k (specify the size of the read data block each time) count=6 (specify the number of read data blocks)

      touch {1,2,3,4,5 }.TXT
    • View quota usage
      quota -u username
      quota -g group name

      requota /yun01

Guess you like

Origin blog.csdn.net/TaKe___Easy/article/details/113532195