Linux基础学习之从入门到精通Day7-2
LVM管理
在线扩容 online
数据迁移 online
创建LVM LVM叫逻辑卷管理
VG扩展/缩小
LV扩容
文件系统扩容 在线扩容及在生产中 300G+900G硬盘 做单盘RAID0
基本分区(MBR|GPT) ----> Filesystem ----> mount
逻辑卷LVM ----> Filesystem ----> mount
VG叫做卷组
extents 叫做扩展块
PE: Physical extent 物理扩展 4M 8M 16M 32M 64M 创建VG时指定 -s 8M
LE: Logical extent 逻辑扩展
一、创建LVM
0. 准备物理磁盘
可以是: /dev/sdb /dev/sdc1
[root@server0 ~]# ll /dev/vd{c,d,e}
brw-rw----. 1 root disk 253, 32 Jun 6 17:38 /dev/vdc
brw-rw----. 1 root disk 253, 48 Jun 6 17:38 /dev/vdd
brw-rw----. 1 root disk 253, 64 Jun 6 17:38 /dev/vde
1. pv
[root@server0 ~]# pvcreate /dev/vdd
Physical volume "/dev/vdd" successfully created
[root@server0 ~]# pvscan
PV /dev/vdd lvm2 [2.00 GiB]
Total: 1 [2.00 GiB] / in use: 0 [0 ] / in no VG: 1 [2.00 GiB]
[root@server0 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdd lvm2 a-- 2.00g 2.00g
2. vg
[root@server0 ~]# vgcreate vg1 /dev/vdd
Volume group "vg1" successfully created
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 0 0 wz--n- 2.00g 2.00g
[root@server0 ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg1" using metadata type lvm2
[root@server0 ~]# vgdisplay vgdisplay datevg
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 2.00 GiB
PE Size 4.00 MiB
Total PE 511
Alloc PE / Size 0 / 0
Free PE / Size 511 / 2.00 GiB
VG UUID 7E4tlj-l0a2-ph52-OytH-eaq7-58K6-2S4n8V
3. lv
[root@server0 ~]# lvcreate -l 10 -n lv1 vg1
[root@server0 ~]# lvcreate -L 200M -n lv2 vg1
[root@server0 ~]# lvscan
ACTIVE '/dev/vg1/lv1' [640.00 MiB] inherit
ACTIVE '/dev/vg1/lv2' [256.00 MiB] inherit
4. 创建文件系统并挂载
[root@server0 ~]# mkfs.xfs /dev/vg1/lv1
[root@server0 ~]# mkfs.ext4 /dev/vg1/lv2
[root@server0 ~]# mkdir /mnt/lv1 /mnt/lv2
[root@server0 ~]# vim /etc/fstab
/dev/vg1/lv1 /mnt/lv1 xfs defaults 0 0
/dev/vg1/lv2 /mnt/lv2 ext4 defaults 0 0
[root@server0 ~]# mount -a
[root@server0 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg1-lv1 651948 32928 619020 6% /mnt/lv1
/dev/mapper/vg1-lv2 245671 2062 226406 1% /mnt/lv2
二、VG管理
扩大VG vgextend
1. pv
[root@server0 ~]# pvcreate /dev/vde
2. vgextend
[root@server0 ~]# vgextend vg1 /dev/vde
Volume group "vg1" successfully extended
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 2 0 wz--n- 3.99g 3.76g
减小VG vgreduce
通常先做数据的迁移
1.查看当前的VG中PV的使用情况
[root@server0 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdd vg1 lvm2 a-- 2.00g 1.76g
/dev/vde vg1 lvm2 a-- 2.00g 2.00g
2. pvmove数据到其它PV
[root@server0 ~]# pvmove /dev/vdd
/dev/vdd: Moved: 16.7%
/dev/vdd: Moved: 100.0%
[root@server0 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdd vg1 lvm2 a-- 2.00g 2.00g
/dev/vde vg1 lvm2 a-- 2.00g 1.76g
3.vgreduce VG
[root@server0 ~]# vgreduce vg1 /dev/vdd
Removed "/dev/vdd" from volume group "vg1"
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 2 0 wz--n- 2.00g 1.76g
三、LV扩容
1. lv扩容
[root@server0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 2 0 wz--n- 1.88g 1.00g
[root@server0 ~]# lvextend -L 800M /dev/vg1/lv1
[root@server0 ~]# lvextend -L +800M /dev/vg1/lv1
[root@server0 ~]# lvextend -l 15 /dev/vg1/lv1
[root@server0 ~]# lvextend -l +15 /dev/vg1/lv1
=======================================
+50%FREE
[root@server0 ~]# lvscan
ACTIVE '/dev/vg1/lv1' [768.00 MiB] inherit
ACTIVE '/dev/vg1/lv2' [512.00 MiB] inherit
2. FS扩容
[root@server0 ~]# df -Th
/dev/mapper/vg1-lv1 xfs 637M 67M 570M 11% /mnt/lv1
/dev/mapper/vg1-lv2 ext4 240M 32M 192M 15% /mnt/lv2
a. xfs
[root@server0 ~]# xfs_growfs /dev/vg1/lv1
b. ext2/3/4
[root@server0 ~]# resize2fs /dev/vg1/lv2
[root@server0 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg1-lv1 xfs 765M 67M 698M 9% /mnt/lv1
/dev/mapper/vg1-lv2 ext4 488M 32M 429M 7% /mnt/lv2
1.创建pv
[root@localhost ~]# pvcreate /dev/sda5 /dev/sda6
[root@localhost ~]# pvdisplay
[root@localhost ~]# pvs
2.创建vg
[root@localhost ~]# vgcreate vg0 /dev/sda5 /dev/sda6
[root@localhost ~]# vgdisplay
[root@localhost ~]# vgs
3.创建lv
[root@localhost ~]# lvcreate -L 250M -n /dev/vg0/lv0 vg0
[root@localhost ~]# lvdisplay
[root@localhost ~]# lvs
注意:
pv不能跨越vg
lv不能跨越vg
系统中可以创建多个vg
vg中可以创建多个lv
删除lvm
1.umount /dev/vg0/lv0
2.[root@localhost ~]# lvremove /dev/vg0/lv0
3.[root@localhost ~]# vgremove vg0
4.[root@localhost ~]# pvremove /dev/sda{5,6,8}