LVM were created and associated disk quota system under Liunx - actual articles

Liunx basic overview of the operating system, LVM logical volumes in this blog will explain in detail and targeted experimental operation, and will also explain the knowledge of disk quotas. I hope that friends do not miss!


table of Contents:

  • LVM Logical Volume Summary and related commands
  • LVM practical example of the operation
  • Disk quotas overview
  • Disk quota management related to the practical operation

    A, LVM logical volumes and related commands Overview

    LVM is a Logical Volume Manager (LVM) shorthand, it is a mechanism to manage disk partitions under Linux, ordinary disk partition management can not change its size after a good logical partitioning, when a logical partition when storing less than a file, the file because the upper limit by the file system can not span multiple partitions to store, so it can not be put on another disk.
    With the emergence of Linux logical volume management capabilities, these problems are solved, the user can easily adjust the size of each partition without the need for downtime.

    1, LVM basic components

    LVM consists of four parts: respectively, PE (basic units consisting disk), PV (physical volume, typically, is constituted by a plurality of PE for the entire disk or its part), VG of (volume group, composed of a plurality of PV), LV (logical Volume, LVM is its management tools, you can connect multiple disks).
    LVM whole situation presents a ring set a ring. VG volume group comprises a plurality of physical volumes PV and each physical volume also contains a plurality of PE, LV last logical link can be the same PE VG plurality of different PV.
    It is not about to faint? No harm, directly on the map, the most convenient and understand:
    LVM were created and associated disk quota system under Liunx - actual articles

    2, LVM-related commands

    Commonly used in LVM on major aspects: To create LVM Scan when scanning, Create establishment, Display shows the need to use Remove to delete the maintenance of LVM, Extend extension, Reduce reduced. As detailed in the following table:
    LVM were created and associated disk quota system under Liunx - actual articles
    daily work commonly used commands in the following format:
    LVM were created and associated disk quota system under Liunx - actual articles

    Two, LVM practical example of the operation

    Theory after all just theory, practical command will eventually have to knock them out to be useful. Describes these, let's be real LVM edit it by example.
    "A company in preparation for our company to establish a storage space per employee." Due to the large number of users, data storage requires a lot of space, the first increase in two pre-SCSI hard disk for the server, and build LVM logical volume (specific mount under "/ mnt" directory) designed to store employee data.
    Experimental requirements has been formulated, let's get started ~ ~ ~

    1, pre-construction work environments

    That is, increase the disk and follow the partition, pave the way for the following work.
    Because of this experiment is to establish full LVM in a virtual machine environment, the first increase in two hard disk (step 1) is not boot server, the boot server remotely Xshell connection (step 2), then jump to the / dev directory under the new view of the hard disk installed (step 3)
    LVM were created and associated disk quota system under Liunx - actual articles
    LVM were created and associated disk quota system under Liunx - actual articles
    LVM were created and associated disk quota system under Liunx - actual articles
    use "fdisk" command, "fdisk / dev / sdb" , "fdisk / dev / sdc" enter hard disk management tool (step 1), are two hard disk partition ( for convenience, simplicity each divided into only one area), press the "n" be the new partition (because only one sub-district, all the way to the default) in the interface, remember to use "W" to save exit, complete the creation enter "fdisk -l" check - step 2
    LVM were created and associated disk quota system under Liunx - actual articles
    LVM were created and associated disk quota system under Liunx - actual articles
    LVM were created and associated disk quota system under Liunx - actual articles
    but!
    If you want to create an LVM logical volume ID in accordance with the type of figure is not enough, so we need to return to management tools, according to the "t" for file type changes, the "83" was changed to "8e" (step 1) using the "w "save
    LVM were created and associated disk quota system under Liunx - actual articles

2, the establishment of LVM Logical Volume

After completion of the partition prior to the concept of FIG, first create a physical volume, and then create a volume group, logical volume created finalize.
(1) Create a physical volume
used "pvcreate" command, enter "pvcreate / dev / sdb1 / dev / sdc1" ( or "pvcreate /dev/sd{b..c}1" also) to complete the creation of the physical volume (step 1), then use the pvscan command to view the situation created (step 2)
LVM were created and associated disk quota system under Liunx - actual articles

(2)创建卷组
由上面的图可看出,现在仅仅只是建好了物理卷,所有的磁盘都是独立存在的,所以接下来就要创建卷组来把磁盘组合起来。
输入“vgcreate box /dev/sd{b..c}1”(第一个路径为卷组名,后面的所有的路径都为物理卷地址)——步骤1,完成创建后通过“pvscan”命令(步骤2)或者“vgdisplay”命令(步骤3)进行创建后的确认。
LVM were created and associated disk quota system under Liunx - actual articles
LVM were created and associated disk quota system under Liunx - actual articles
(3)创建逻辑卷
上面创建完卷组后,就来到了最后一步“创建逻辑卷”
输入“lvcreate -L 19G -n xxbox box”其中“-L”后面的数字为逻辑卷大小,其容量不可超过卷组大小,“-n”后面为逻辑卷名称,最后的“box”为建立逻辑卷的卷组名(步骤1)。使用“lvdisplay”查看逻辑卷详情(步骤2)。
LVM were created and associated disk quota system under Liunx - actual articles
LVM were created and associated disk quota system under Liunx - actual articles

3、对逻辑卷进行格式化并挂载

完成逻辑卷的创建后,想要能够正常使用,就必须对逻辑卷进行格式化(步骤1)。结束格式化后,因为已知不存在/mnt目录需要使用“mkdir”进行新建(步骤2)。
之后的步骤就跟正常挂载新磁盘分区一样进行挂载,不过由于本次的逻辑卷需要一直存在,因此不能使用“mount”目录临时挂载,而是修改配置文件进行自动挂载——“vim /etc/fstab”(步骤3)。
LVM were created and associated disk quota system under Liunx - actual articles
LVM were created and associated disk quota system under Liunx - actual articles

LVM were created and associated disk quota system under Liunx - actual articles

4、验证挂载是否成功

使用“mount -a”对挂载进行刷新,接着使用“df -h”查看刷新后的挂载表
LVM were created and associated disk quota system under Liunx - actual articles

以上就完成LVM的配置,公司员工就可以通过访问/mnt目录进行数据存储。但是!!
如果LVM逻辑卷被人恶意占用,使用大量空目录占用磁盘节点怎么办?这个时候就是磁盘配额出场大显神威的时候了。

三、磁盘配额概述

什么是磁盘配额?

磁盘配额可以限制指定账户能够使用的磁盘空间,这样可以避免因某个用户的过度使用磁盘空间造成其他用户无法正常工作甚至影响系统运行,在服务器管理中此功能非常重要。
实现磁盘配额的条件:
需要Liunx内核支持
需要安装xfsprogs(事先需要查询该rpm软件包是否安装,若没有安装则需要进行安装否则无法进行磁盘配额)和xfsprogs软件中自带的quota软件包
LVM were created and associated disk quota system under Liunx - actual articles
进行磁盘配额的具体步骤(文字容易描述不清,还是图来的实在):
LVM were created and associated disk quota system under Liunx - actual articles

四、磁盘配额相关管理实操

还是接上面LVM的例子,针对给公司员工进行数据存储的逻辑卷,开展磁盘配额的操作。
首先,关闭增强性安全功能(setenforce=0)——在Centos6中属于必须需要关闭的选项,而在Centos7则可关可不关(步骤1)。
接下来,因为逻辑卷本身属于永久挂载,所以我们的磁盘限额也需要是永久性,即通过修改/etc/fstab进行自动挂载(步骤2)
LVM were created and associated disk quota system under Liunx - actual articles
LVM were created and associated disk quota system under Liunx - actual articles
但是在完成配置文件的修改后,quota是不会马上生效的,这时候查看mount挂载表,逻辑卷显示的依旧是noquota(步骤1),这时候需要进行就是解挂“umount”并重新进行挂载(步骤2、3)
LVM were created and associated disk quota system under Liunx - actual articles
LVM were created and associated disk quota system under Liunx - actual articles
LVM were created and associated disk quota system under Liunx - actual articles
完成quota挂载参数的设置后,就是正式的对逻辑卷进行磁盘配额,使用“xfs_quota”命令,具体编辑配额的格式为:
LVM were created and associated disk quota system under Liunx - actual articles
其中x为启用专家模式
c为使用命令指令执行
limit为限制内容
u为指定用户进行限额
bsoft后为容量软限制(可超出,有时效性,通常七天)
bhard后为容量硬限制
isoft后为数量的软限制
ihard后为数量的硬限制
用户名处填写进行限额的用户
具体实验步骤,如下图:
LVM were created and associated disk quota system under Liunx - actual articles
最后收尾的就是修改挂载目录的权限,在root用户下使用chmod命令将/mnt目录权限更改为所有人均可读、可写、可执行
LVM were created and associated disk quota system under Liunx - actual articles
这样,磁盘配额就全部设置完成了。接下来需要做的就是验证磁盘配额是否正常运行。
磁盘配额中有一条铁律:只要容量、数量有一条达到限额,另一条就无法继续执行。

(1)文件节点只有一个但容量达到限额

Use "dd" verification replication, copying files full capacity 10M from / dev / zero file
Step:
1, using the "su" command to switch to the next zhy user
2, using "dd if = / dev / zero of = / mnt / test1.txt bs = 1M count = 10 "copy / dev / zero files to /mnt/tset1.txt, a single copy 1M, copied 10 times
3, use the" touch "command to create a new empty folder (should not be created)
LVM were created and associated disk quota system under Liunx - actual articles

(2) file node 10 is filled to capacity empty folder

Using the "touch" command batch create an empty folder
Step:
1, at zhy user, using the "touch" command 10 batch empty folder creation
2, "dd" command, copy 10K from / dev / zero in the size of the file (should not be created)
LVM were created and associated disk quota system under Liunx - actual articles


These are all about content creation, and LVM disk quotas under LVM logical volume, you can follow to operate together, thank you! !

Guess you like

Origin blog.51cto.com/14484404/2431267