lvm与raid的配置使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lvm与raid的配置使用相关的知识,希望对你有一定的参考价值。

  • lvs
  • raid

lvm: logical volumes manager,从物理设备创建虚拟块设备,将一个或多个底层块设备组织成一个逻辑设备的模块,能够更好的管理磁盘,通过对底层的封装,对磁盘进行动态管理。
技术分享图片
基本概念:
pv :physical volume物理卷处于最底层
vg :volume group卷组,建立在物理卷之上,最小单位为pe
lv :logical volume 逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间

管理使用:

pv管理工具 vg管理工具 lv管理工具
pvs:简要显示PV信息 vgs :显示vg简要信息 lvs :显示lv简要信息
pvdisplay:显示详细信息 vgdisplay 显示详细信息 lvdisplay 显示详细信息
pvcreate /dev/device... :创建PV vgcreate [-s #[kKmMgGtTpPeE]] VG_Name /dev/device...]#创建vg,-s指明pe大小,默认4m lvcreate -L #[mMgGtT] -n NAME VolumeGroup #-l 指明pe多少个 ,-L lv大小
pvremove /dev/device...删除PV vgextend VG_Name /dev/device... #扩容vg lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME: lv扩容后还需要修改逻辑大小:resizefs /dev/VG_NAME/LV_NAME
pvmove /dev/device /dev/device:数据迁移 vgreduce VG_Name /dev/device... #缩容 缩减逻辑卷看缩减步骤
vgremove vg_name删除卷组 :注收缩需先迁移数据 lvremove /dev/VG_NAME/LV_NAME #删除逻辑卷

lv缩减步骤:

# umount /dev/VG_NAME/LV_NAME#先卸载,xfs可以不用卸载
# e2fsck -f /dev/VG_NAME/LV_NAME #强制检测文件系统
# resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT] #执行缩减操作
# lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME #缩减lv
# mount

简单实践:

[[email protected] ~]# pvcreate /dev/sdb{1,2}
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdb2" successfully created.
[[email protected] ~]# pvs
  PV         VG Fmt  Attr PSize PFree
  /dev/sdb1     lvm2 ---  1.00g 1.00g
  /dev/sdb2     lvm2 ---  1.00g 1.00g
[[email protected] ~]# pvdisplay 
  "/dev/sdb2" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               3XTOcT-uIc3-73Hc-alkn-EKWJ-yyqv-CZYDsR

  "/dev/sdb1" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               KZ6Mwf-GPQc-xGQf-xWwS-FCnS-yLtn-XqJofh
= ================================================== 
[[email protected] ~]# vgcreate myvg /dev/sdb1
  Volume group "myvg" successfully created
[[email protected] ~]# vgs
  VG   #PV #LV #SN Attr   VSize    VFree   
  myvg   1   0   0 wz--n- 1020.00m 1020.00m
[[email protected] ~]# vgextend myvg /dev/sdb2
  Volume group "myvg" successfully extended
[roo[email protected] ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   2   0   0 wz--n- 1.99g 1.99g
[[email protected] ~]# vgdisplay 
  --- Volume group ---
  VG Name               myvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               1.99 GiB
  PE Size               4.00 MiB
  Total PE              510
  Alloc PE / Size       0 / 0   
  Free  PE / Size       510 / 1.99 GiB
  VG UUID               b5t7N7-xMBg-5O8w-xS5m-2OTV-IpBd-98mR5w
===================================================
[[email protected] ~]# lvcreate -L 200m --name mylv myvg 
  Logical volume "mylv" created.
[[email protected] ~]# lvs
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a----- 200.00m                                                    
[[email protected] ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                PelWrs-D13Q-8btE-q0RV-tFsA-6miC-FTqwns
  LV Write Access        read/write
  LV Creation host, time xt.com, 2019-01-11 22:24:56 +0800
  LV Status              available
  # open                 0
  LV Size                200.00 MiB
  Current LE             50
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
=================================================
[[email protected] ~]# mkfs.ext4 /dev/myvg/mylv 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

[[email protected] ~]# mount /dev/myvg/mylv /mnt
[[email protected] ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/sda1               10G  4.0G  6.1G  40% /
devtmpfs               984M     0  984M   0% /dev
tmpfs                  993M     0  993M   0% /dev/shm
tmpfs                  993M  8.7M  985M   1% /run
tmpfs                  993M     0  993M   0% /sys/fs/cgroup
/dev/sda3              256M   83M  173M  33% /boot
tmpfs                  199M     0  199M   0% /run/user/0
/dev/mapper/myvg-mylv  190M  1.6M  175M   1% /mnt
==========================================
模拟数据迁移:需要同一个vg
[[email protected] mnt]# mount /dev/myvg/mylv /mnt
[[email protected] mnt]# cp -r /tmp/ /mnt/
[[email protected] tmp]# pvs
  PV         VG   Fmt  Attr PSize    PFree    
  /dev/sdb1  myvg lvm2 a--  1020.00m  820.00m #数据主要在sdb1,迁移到目标的容量要比现有大
  /dev/sdb2  myvg lvm2 a--  1020.00m 1020.00m
[[email protected] tmp]# pvmove /dev/sdb1 /dev/sdb2
  /dev/sdb1: Moved: 4.00%
  /dev/sdb1: Moved: 100.00%
[[email protected] tmp]# pvs
  PV         VG   Fmt  Attr PSize    PFree   
  /dev/sdb1  myvg lvm2 a--  1020.00m 1020.00m
  /dev/sdb2  myvg lvm2 a--  1020.00m  820.00m
[[email protected] tmp]# vgreduce myvg  /dev/sdb1
  Removed "/dev/sdb1" from volume group "myvg"
[[email protected] tmp]# pvs
  PV         VG   Fmt  Attr PSize    PFree  
  /dev/sdb1       lvm2 ---     1.00g   1.00g
  /dev/sdb2  myvg lvm2 a--  1020.00m 820.00m
[[email protected] tmp]# vgs
  VG   #PV #LV #SN Attr   VSize    VFree  
  myvg   1   1   0 wz--n- 1020.00m 820.00m

以上是关于lvm与raid的配置使用的主要内容,如果未能解决你的问题,请参考以下文章

Linux下配置RAID5 LVM逻辑卷及磁盘配额的实验

linux 简单记录7--使用 RAID 与 LVM 磁盘阵列技术(使用LVM扩展磁盘空间)

第7章 使用RAID与LVM磁盘阵列技术

三、RAID与LVM

RHCE 第10节课 使用RAID与LVM磁盘阵列技术

RAID与LVM管理