• Logical Volume Manager,逻辑卷管理

  • 动态调整磁盘容量,从而提高磁盘管理的灵活性

  • 需要注意:/boot 分区用于存放引导文件,不能基于 LVM 创建

  • 图形界面管理工具

  • system-config-lvm

  • LVM 机制的基本概念

  • PV(物理卷)相当于sdb、sdc

  • VG(卷组)相当于sdb1、sdc1合起来

  • LV(逻辑卷)相当于在pv两个中在创建

  • 第一种方法:

  • 先安装  需安装yum仓库

  • yum install lvm2

  • 举例:添加2块硬盘

  • ll /dev/sd*

  • /dev/sd* 
brw-rw 
8, 16 
bru- rw 
[root@k8s-node2 
brw-rw- - 1 
root 
root 
root 
brw-rw• - 1 
root 
1 root 
disk 
disk 
disk 
disk 
disk 
8, 
8, 
8, 
8, 
1 
2 
32 
24 
24 
24 
24 
24 
15. 
• 52 
15. 
52 
15. 
•52 
15. 
52 
15. 
•52 
'dev / s da 
/dev/sdal 
/dev/sda2 
/dev/sdb 
/dev/sdc

  • 创建pv

  • pvcreate /dev/sdb

  • pvcreate /dev/sdc

  • 创建vg

  • vgcreate vg0 /dev/sdb

  • vgextend vg0 /dev/sdc

  • 创建lv  -n指定名字  -L指定分区大小

  • lvcreate -n lv01 -L 100M vg0

  • mkfs.xfs /dev/vg0/lv01

  • mkdir /lv01

  • mount /dev/vg0/lv01 /lv01/

  • ----------------------------------------------------------------------------

  • 第二种方法:添加两块硬盘

  • yum install lvm2

  • ll /dev/sd*

  • /dev/sd* 
brw-rw 
8, 16 
bru- rw 
[root@k8s-node2 
brw-rw- - 1 
root 
root 
root 
brw-rw• - 1 
root 
1 root 
disk 
disk 
disk 
disk 
disk 
8, 
8, 
8, 
8, 
1 
2 
32 
24 
24 
24 
24 
24 
15. 
• 52 
15. 
52 
15. 
•52 
15. 
52 
15. 
•52 
'dev / s da 
/dev/sdal 
/dev/sda2 
/dev/sdb 
/dev/sdc

  • 创建pv

  • pvcreate /dev/sd[bc]

  • troot@k8s-node2 pvcreate /dev/sd(bcl 
Physical volume "[dev/sdb" successfully created. 
Physical volume "/dev/sdc" successfully created.

  • 创建vg

  • V gcreate vg0 /dev/sd[bc]

  • vqcreate v D /dev/sd[bc] 
v 
• lume roup "v D successfully created 
[root@k8s-node2

  • 创建lv 

  • lvcreate -n lv01 -L 100M vg0

  • (root@k8s-node2 Ivcreate -n tv01 -L 100M vgO 
Logical volume "Iv01" created.

  • 格式化

  • [root@k8s-node2 mkfs .xfs 
vgO/ 
vga_arbiter 
[root@k8s-node2 mkfs .xfs 
rneta - data=/ dev/vgO/1v01 
data 
naming =version 2 
—internal log 
realtime —none 
! root@kgs-node2 
/dev/vg 
/dewvgo/lvol 
isize=512 
sectsz=512 
c rc=1 
bsize=4096 
sunit=O 
bsize=4096 
bsize=4096 
sectsz=512 
extsz=4096 
agcount=4, agsize=6400 btks 
attr=2, proj id32bit=1 
finobt=O, sparse—O 
blocks—25600, imaxpct=25 
swidth=O blks 
ascii-ci=o ftype=l 
blocks=855, version—2 
sunit=O b!" , lazy-count=l 
blocks—O. • rtextents=O

  • 创建挂载点

  • [root@k8s-node2 mkdir /lv01 
[root@k8s-node2 mount /dev/vgO/Iv01 /IVOI/ 
[root@k8s-node2

  • 第三种方法:

  • 添加两块硬盘  在两块硬盘中添加两个分区

  • 格式化分区

  • mkfs.xfs /dev/sdb1

  • mkfs.xfs /dev/sdc1

  • mkfs.xfs /dev/sdbl 
sdcl 
[ rootBlocalhost # 
[ root910calhost - I pvcreate /dev/sdl bcl I 
Physical volume %ldev/ sdbl 
successfully created. 
Physical volume '/dev/sdcl successfully created. 
rootslocalhost # 
[ rootBlocalhost # vqcreate vgO /dev/sd[ bcl 1 
Volume group "vgon successfully created 
rootslocalhost - # 
Volume group "vgO" successfully created 
[ rootstocalhost -l # Ivcreate -n IVI -L 100M vgO 
Logical volume •Ivl" created. 
rootalocalhost - # 
xfstßit 
[ rootalocalhost # 
[ rootBlocalhost - I 
meta. data—/dev/vgo 
data 
naming *lersion 2 
—internal log 
realtime -«)ne 
rootalocalhost -l # 
Isize—ä12 
sectsz=512 
crc* 
bsize=aog6 
suni 
bsize—4096 
bsize=ß096 
sectsz=512 
extsæ;og6 
aqcount-a, agsize=6400 blks 
attr=2, proj id32bit=i 
finobt=o, sparse-o 
blocks-25600, imaxpct=25 
swidth4:l blks 
ascii. ci=O ftype* 
blocks=a55, version—2 
sunit=o bus, lazy- count* 
blocks-a, rtextents=O

  •  mkfs.xfs -f /dev/vg0/lv1

  •  df -h

  • mkdir /lv1

  •  mount /dev/vg0/lv1 /lv1/

  • vim /etc/fstab

  • /dev/mapper/centos- swap 
dev/ vgO/IvI 
I root8toca1host -l # 
swap 
/'lvl 
xfs 
defaults 
swap 
defaults, us r quota, grpquota O

  • umount -a

  • mount -a

  • yum install quota -y

  • quotaon -p /lv1/

  • df -h

  • df -HT

  • ------------------------------------------------------------------------------

  • 扩展磁盘:

  • yum install lvm2

  • ll /dev/sd*

  • 创建pv  物理卷

  • pvcreate /dev/sdb

  • pvcreate /dev/sdc

  • 创建vg  卷组

  • vgcreate vg0 /dev/sdb

  • vgextend vg0 /dev/sdc

  • 创建lv  逻辑卷  -n指定名字  -L指定分区大小

  • lvcreate -n lv01 -L 100M vg0

  • 扩展

  • lvcreate -n lv02 -L 100M vg0

  • mkfs.xfs /dev/vg0/lv01

  • 扩展

  • mkfs.ext4 /dev/vg0/lv02

  • 扩展

  • mkdir /lv01

  • mkdir /lv02

  • 扩展

  • mount /dev/vg0/lv01 /lv01

  • mount /dev/vg0/lv02 /lv02

  • 扩展

  • lvextend -L +100M /dev/vg0/lv01

  • lvextend -L +100M /dev/vg0/lv02

  • lvscan

  • xfs_growfs /dev/vg0/lv01刷新xfs格式

  • resize2fs /dev/vg0/lv02刷新ext4格式

  • 添加磁盘重启

  • pvcreate /dev/sdd  创建物理卷

  • vgextend vg0 /dev/sdd  加入到vg0卷组

  • vgdisplay 查看

  • rootßlocalhost # 
Volume group 
VG Name 
System ID 
Fo rmat 
Metadata Areas 
Metadata Sequence 
VG Access 
VG Status 
MAX LV 
cur LV 
Open LV 
max Pv 
cur PV 
Act PV 
VG size 
PE size 
Total PE 
Alloc PE / 
Free PE / 
VG UUID 
Vol ume 
Size 
Size 
group - 
vgdisplay 
No 
read/write 
resizable 
s-sg.gg 
4.00 
15357 
100 / 400.00 Mia 
1S2S7 / 69.60 GiB 
KIDvbV. d08f. zmmr. OLzv. msjk- ccnw AZ2v5z

  • 用户配额   组配额

  • 磁盘和文件系统二_数据

  • 安装软件

  • yum install quota -y

  • umount -a

  • mount -a

  • root@k8s-node2 quotaon -p 
grou quota on /tv01 (/dev/mapper/vgO• tv01) is on 
uota on / IVOI (/dev/rnapper/vg0-1v01) is on 
use 
[root@k8s-node2

  • 添加用户

  • useradd xiaoming

  • 配置密码

  • passwd xiaoming

  • 创建目录

  • mkdir /lv01/xiaomingtest

  • cd /lv01/xiaomingtest/

  • cd .. /

  • df -h

  • ll

  • chown xiaoming xiaomingtest/

  • 在root目录下

  • edquota -u xiaoming

  • Disk quotas for user Xiaoming 
Filesystem 
/dev/mapper/vgo- I VOI 
(uid 1001): 
blocks 
soft 
10480 
hard 
20480 
inodes 
soft 
hard

  • 切换到xiaoming

  • root610caIhost # 
I root810ca1host -l # 
I xiaomingßlocalhost 
Iv01/ Iv02/ 
I xiaomingdloca I host 
edquota - u xiaoming 
su xraomlng 
root] 3 cd / IVO 
rootl S cd /lv01 /xiaomingtest/

  • 测试能创建文件夹

  • I xiaomingatocalhost 
I xiaoming810caIhost 
I xiaomingalocalhost 
I xiaomingötocathost 
I xiaomingBlocalhost 
I XiaomingBlocalhost 
touch: X 
I xiaomingelocalhost 
xiaomingtestl 
xiaomingtestl 
xiaomingtestl 
xiaomingtestl 
xlaomingtestl 
Xiaomingtestl 
xiaomingtestl 
touch 
touch 
touch 
touch 
touch 
touch

  • rm -rf *

  • dd if=/dev/zero of=x01 bs=1M count=5

  • dd if=/dev/zero of=x02 bs=10M count=5

  • du -sh *

  • 磁盘和文件系统二_上传下载_02
























  • Of



    名字



    Bs



    大小



    Count



    数量




  • 磁盘和文件系统二_数据_03

  • -------------------------------------------------------------------------

  • 组配额

  • 创建lvm

  • 配置永久挂载

  • 磁盘和文件系统二_上传下载_04

  • umount -a

  • mount -a

  • useradd aa

  • groupadd a1

  • gpasswd -a aa a1

  • mkdir /lv01/azu

  • cd /lv01/

  • chown aa:a1 azu

  • ll

  • id aa

  • 切换到root目录下

  • edquota -g a1

  • Disk quotas for group al 
Filesystem 
/dev/mapper/vgO- I VOI 
( gid 
1004): 
blocks 
soft 
40480 
hard 
60480 
inodes 
soft 
hard

  • usermod -g a1 aa 改变用户所属组

  • su aa

  • cd /lv01/azu/

  • 创建6个文件夹  测试后删除

  • i aaBlocalhost 
[ aaßlocalhost 
I aaBIocalh05t 
[ aaßlocalhost 
I aaßlocalhost 
[ aaB10cathost 
azul 
azul E 
azul 
azul 
azul 
azul t 
touch: 
aaBlocalhost azul 
touch 
touch 
touch 
touch 
touch 
touch 
rm - rf

  • 测试

  • dd if=/dev/zero of=x01 bs=1M count=5

  • dd if=/dev/zero of=x02 bs=10M count=5

  • dd if=/dev/zero of=x03 bs=10M count=5

  • 磁盘和文件系统二_逻辑卷_05

  • 测试用户配额

  • [ aaatocalhost tv011t exit 
exit 
I rootelocalhost cd /

  • cd /lv01/

  • useradd hh

  • ll

  • chown hh azu/

  • chmod 777 azu/

  • cd

  • edquota -u hh

  • su hh

  • cd /lv01/azu/

  • ll查看 下面有内容就删除

  •  dd if=/dev/zero of=x01 bs=1M count=5

  •  dd if=/dev/zero of=x02 bs=10M count=5

  •  dd if=/dev/zero of=x03 bs=10M count=5

  •  du -sh *

  • 实验--------------------------------------------------------------------------------------------------------------------------

  • 公司准备在Internet中搭建FTP服务器(CentOS 7.3平台),面向全国各地的员工及部分VIP客户提供资料上传下载的空间。考虑动态扩容的需要,计划增加两块SCSI硬盘并构建LVM逻辑卷(挂载到/date目录下)专门用于存放邮件数据,并通过磁盘配额的方式限制用户的邮箱空间


1.添加两个硬盘为sdb、sdc

2.配置pv vg lv

[root@localhost
~]# pvcreate /dev/sd[bc]

  Physical volume "/dev/sdb"
successfully created.

  Physical volume "/dev/sdc"
successfully created.

[root@localhost
~]# vgcreate vg0 /dev/sd[bc]

  Volume group "vg0" successfully
created

[root@localhost
~]# lvcreate -L 100M -n lv01 vg0

  Logical volume "lv01" created.

[root@localhost
~]# mkdir /lv01

[root@localhost ~]# mkfs.xfs /dev/vg0/lv01

配置永久挂载

/dev/vgO/lv01 /lv01 xfs defaults, usrquota O O 
root@localhost


在挂载点下创建test

[ root@localhost -1 # cd / IVOI/ 
[ root@localhost Il 
drwxrwxrwx. 2 Lisi root 28 12B 
[ root@localhost IVOII # 
20 17: 51 test


修改用户的属主 权限

[ root@localhost mkdir test 
[ root@localhost 
[ root@localhost chmod 777 test/ 
[ root@localhost usradd lisi 
bash: usradd: $ + 
[ root@localhost useradd Lisi 
[ root@localhost chown I isi test/


配置用户配额

@isk quotas for user Lisi 
Filesystem 
/dev/mapper/vgo- IVOI 
( uid 
1001) : 
blocks 
9216 
soft 
ha rd 
10240 
i nodes 
3 
soft 
ha rd

切换用户进行配置

[ root@localhost su 
[ lisi@localhost Ivol]$ Il 
d rwxrwxrwx. 2 lisi root 28 
I Isi 
12B 20 17: 51 
[ lisi@localhost Iv01]$ cd test/ 
[ lisi@localhost test] $ Il 
9216 
1 1 isi I isi 5242880 12B 
1 1 isi I isi 4194304 12B 
lisi@localhost test] $ 
20 17: 51 XOI 
20 17: 51 X02


查看

du 
5. OM 
4. OM 
[ lisi@localhost 
XOI 
X02 
[ lisi@localhost 
test] $ 
test] $