当前位置:网站首页>LVM and disk quota

LVM and disk quota

2022-04-23 16:27:00 qjwthink

Catalog

One 、LVM summary

1、 Implementation process

2、LVM The basic concept of mechanism

Two 、LVM Management commands for

3、 ... and 、LVM Operation main command steps

Overall experimental process

Four 、 Disk quota overview

1、 Conditions for achieving disk quota

2、Linux Characteristics of disk quota

3、 Set disk quota

4、CentOS7 To set disk quotas in

summary


One 、LVM summary

Logical Volume Manager, Logical volume management

● In the Keep the existing data unchanged Under the circumstances Dynamically adjust disk capacity , So as to improve the efficiency of disk management flexibility

/boot Partitions are used to store boot files , Cannot be based on LVM establish

1、 Implementation process

1、 Put the device ( Hard disk , Hardware device ) Specify as physical volume

2、 Create a volume group with one or more physical volumes ,

3、 A physical volume is a fixed size physical area (Physical Extent,PE) To define the

4、 Logical volumes created on physical volumes , Is made up of physical areas (PE) form

5、 File systems can be created and mounted on logical volumes

2、LVM The basic concept of mechanism

PV ( Physical volume, Physical volume )

The physical volume is LVM The basic storage device of the mechanism , It usually corresponds to an ordinary partition or the whole hard disk . When creating a physical volume , It will be in the minute

Create a reserved block at the head of the area or hard disk , Used to record LVM Properties of , And divide the storage space into the default size of 4MB Of

Basic unit (Physical Extent,PE), To form a physical volume .

VG (volume Group, The volume group >

An entity consisting of one or more physical volumes , This is called a volume group ,I Physical volumes can be dynamically added or removed from a volume group

LV (Logical volume, Logic volume )

Logical volumes are built on top of volume groups , Not directly related to physical volumes . For logical volumes , Each volume group is a whole , from

In this whole " Cut out " A small space , As the basis for users to create file systems , This small space is called a logical volume . Use

mkfs And other tools to create file systems on logical volumes

Two 、LVM Management commands for

The main command

function

Physical volume management

Volume group management

Logical volume management

Scan scanning

Pvscan

Vgscan

lvscan

Create establish

Pvcreate

Vgcreate

lvcreate

Display Show

Pvdisplay

Vgdisplay

lvdisplay

Remove Delete

Pvremove

Vgremove

lvremove

Extend Expand

---

Vgextend

lvextend

Reduce Reduce

---

Vgreduce

lvreduce

3、 ... and 、LVM Operation main command steps

1. Shut down the engine , Add two new hard drives , Restart the host

or echo "- - - " > /sys/class/scsi_host/host0/scan scanning

2. First use fdisk Tools talk about disk devices /dev/sdb、/dev/sdc Divide the main partition sdb1、sdc1, And the partition type ID Change the tag number to “8e”

fdisk /dev/sdb

fdisk /dev/sdc

3. Create a physical volume

pvcreate /dev/sdb1 /dev/sdc1

Command word    Hardware device ( The device you are going to use as a logical volume can be a partition or a hard disk )

4. Create a volume group , The volume group name is ky15

vgcreate ky15 /dev/sdb1 /dev/sdc1

Command word     Volume group name Physical volume ( It can be more than one )

5. Create logical volumes , The logical volume name is ky1501, Capacity of 15GB, The production documents are /dev/ky15/ky1501

lvcreate -L 15G -n ky1501 ky15

Command word   -L It's a friendly way GMK  -n The name of the logical volume   Volume group name

 lvcreate -n Logical volume name   -L Specify size     Take space from the volume group

6. Format logical volumes , establish XFS file system , And mount it to /data Under the table of contents

mkfs -t xfs /dev/ky15/ky1501 or mkfs.xfs /dev/ky15/ky1501

mount /dev/ky15/ky1501 /data/

df -Th

7. And then expand

pvcreate  /dev/ sdc2

     

vgextend ky15 /dev/sdc2 

Command word    The name of the volume group to be expanded    Physical volume ( Unused physical volumes )

 

lvextend -L +10G /dev/ky15/ky1501

Command word    Specify friendly size       lv Logical volume location    

xfs_growfs /dev/ky15/ky1501       // Refresh xfs File system capacity

Refresh file system command    Logical volume name

resize2fs   /dev/vgname1/lvname1         // Refresh ext4 Type file system capacity

establish LVM technological process :

pvcreate establish pv -> vgcreate Create a volume group -> lvcreate Create logical volumes -> mkfs.xfs lv format -> mount mount

Delete LVM technological process :

umount uninstall -> lvremove lv Remove all logical volumes from the volume group -> vgremove vg Remove the volume group -> pvremove Removed from the pv

Overall experimental process

establish LVM technological process : 
pvcreate establish pv -> vgcreate Create a volume group -> lvcreate Create logical volumes -> mkfs.xfs lv format -> mount mount

Delete LVM technological process :
umount uninstall -> lvremove lv Remove all logical volumes from the volume group -> vgremove vg Remove the volume group -> pvremove Removed from the pv
 

Four 、 Disk quota overview

1、 Conditions for achieving disk quota

need Linux The kernel support

install xfsprogs And quota software package

2、Linux Characteristics of disk quota

Scope of action : For the specified file system ( Partition

Restricted objects : User account number 、 Group account

Type of restriction : Disk capacity 、 Number of documents

Limiting method : Soft limit 、 Hard limit

3、 Set disk quota

When Linux When the root partition runs out of disk space ,Linux The operating system will no longer be able to create new files , It is also possible that

There will be a service program crash 、 Failure of system startup .

In order to avoid the problem of insufficient disk space in the server , The disk quota function can be enabled , For users in

Specify the file system ( Partition ) Disk space used in 、 Limit the number of files , To prevent individual users from malicious or non malicious

It takes up a lot of disk space , So as to maintain the stability and sustainability of the system storage space Centos In the system ,

Different file systems use different disk quota configuration management tools . for example ,XFS writing Pieces of   The system goes through xfs_quota Use tools to carry out pipe

The reason is ;EXT3/4 File system pass quota Tools to manage .

4、CentOS7 To set disk quotas in

1、 Check that... Is installed xfsprogs and xfs_ quota software package

rpm -q xfsprogs quota        yum install -y xfsprogs quota

2、 Mount the file system in a way that supports quota function

umount / dev/ vgname1 / lvnamel

mount -o usrquota, grpquota /dev/vgname1/lvname1 /opt

# Add mount parameters "usrquota, grpquota" Used to add support to users 、 Support for group quota function

perhaps

vim /etc/ fstab

/dev/vgname1/ lvname1     /opt   xfs   defaults,usrquota,grpquota   0 0

mount -a  #-a Options , take /etc/ fstab All the content of is reloaded

3、 Edit quota settings for user and group accounts

useradd lisi

passwd lisi

4、xfs_quota -x -c 'limit -u bsoft=80M bhard=100M isoft=6 ihard=10 lisi' /data/

Command word    Expert model Call the command    limit Limit -u Designated user   Soft and hard restrictions       Users who need to be restricted   Mount point

-x: Indicates start expert mode , In the current mode, all management commands that allow modifications to the quota system are available .

-c: Means to directly call the management command .

-u: Specify the user account object

-g: Specify the group account object

bsoft: Set the soft limit value of disk capacity ( The default unit is KB).

bhard: Set the hard limit value of disk capacity ( The default unit is KB).

isoft: Set the soft limit value for the number of disk files .

ihard: Set the hard limit value for the number of disk files .

# Limit disk capacity only

xfs_ quota -x -c 'limit -u bsoft=80M bhard=100M lisi' /data/

# Limit the number of files only

xfs quota -x -c 'limit -u isoft=4 ihard=5 lisi' /data/

# see zhangsan disk : Capacity limit

xfs_ quota -c'quota -uv lisi' /data/

# see zhangsan File limit

xfs quota -c 'quota -i -uv lisi' /data/

4、 Verify the disk quota function

chmod 777 /opt

Su lisi

cd /opt

# Verify that the disk capacity exceeds the limit

dd if=/dev/zero of=/data/bigfile.img bs=100M count=2

# Verify that the number of disk files exceeds the limit

touch {aa,bb, cc,dd,ee, ff} .txt

dd The command is a device conversion and continuous copy command

“if=” Specify the input device ( Or document )

"of=" Specify the output device ( Or document )

"bs=" Specifies the size of the read data block

"count=” Specify the number of read data blocks

/dev/zero “ zero " Device file , You can provide empty characters indefinitely . Often used to generate - A file of a specific size .

5、 View quota usage

# View disk capacity quota usage for all available partitions

xfs_ quota - X -C ' report -abih'

View disk quota

report Common options :

-u: View for users

-g: View groups

-a: View quota usage reports for all available partitions

-b: Check disk capacity

-i: View the number of files

summary

Organize the experiment , Thus understand , master LVM And disk quota

版权声明
本文为[qjwthink]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231624474128.html