linux下lvm逻辑卷配置

但使书种多,会有岁稔时。这篇文章主要讲述linux下lvm逻辑卷配置相关的知识,希望能为你提供帮助。

linux下lvm逻辑卷配置

文章图片

演示环境:
阿里ecs服务器或者物理服务器对新挂载硬盘设备进行逻辑卷分区和挂载
系统是CentOS Linux release 7.6.1810 (Core) x86_64位最小化安装
1、安装虚拟化命令:
yum -y install lvm2

【linux下lvm逻辑卷配置】2、新挂载的物理硬盘分区/dev/vdc初始化为物理卷,以便LVM使用:
pv-s
[root@testdb ~]# pvcreate /dev/vdc Physical volume "/dev/vde" successfully created.

3、创建LVM卷组vg_data,并将sdb放进卷组vg_data中:vg-s
[root@testdb ~]# vgcreate /dev/vg_data /dev/vdc Volume group "vg_data" successfully created [root@testdb ~]# [root@testdb ~]#

4、vgdisplay 显示LVM卷组的信息:
[root@testdb ~]# vgdisplay --- Volume group --- VG Namevg_data System ID Formatlvm2 Metadata Areas1 Metadata Sequence No1 VG Accessread/write VG Statusresizable MAX LV0 Cur LV0 Open LV0 Max PV0 Cur PV1 Act PV1 VG Size< 100.00 GiB PE Size4.00 MiB Total PE25599 Alloc PE / Size0 / 0 FreePE / Size25599 / < 100.00 GiB VG UUIDFi0gw1-3Dx4-e2ad-bC4f-ps2H-yrsS-SXeSpB

[root@testdb ~]# lvcreate -n /dev/vg_data/lv_data -l 25599 Logical volume "lv_data" created. [root@testdb ~]#

特别说明:
逻辑卷是创建在卷组之上的。逻辑卷对应的设备文件保存在卷组目录下,例如:在卷组" vg_data" 上创建一个逻辑卷" lv_data" ,则此逻辑卷对应的设备文件为" /dev/vg_data/lv_data" 。
" -l" 参数是为了指定逻辑卷的大小(逻辑卷的数量)。" -n" 是指定逻辑卷名称。
5、创建文件系统:
mkfs.xfs /dev/mapper/vg_data-lv_data或者 mkfs.ext4/dev/mapper/vg_data-lv_data

[root@testdb ~]# mkfs.xfs /dev/mapper/vg_data-lv_data meta-data=https://www.songbingjia.com/dev/mapper/vg_data-lv_data isize=512agcount=4, agsize=6553344 blks =sectsz=512attr=2, projid32bit=1 =crc=1finobt=0, sparse=0 data=bsize=4096blocks=26213376, imaxpct=25 =sunit=0swidth=0 blks naming=version 2bsize=4096ascii-ci=0 ftype=1 log=internal logbsize=4096blocks=12799, version=2 =sectsz=512sunit=0 blks, lazy-count=1 realtime =noneextsz=4096blocks=0, rtextents=0 [root@testdb ~]#

6、挂载文件:m-v-s
[root@testdb ~]# mount /dev/mapper/vg_data-lv_data /data2 [root@testdb ~]# df -h FilesystemSizeUsed Avail Use% Mounted on /dev/vda140G28G11G73% / devtmpfs3.9G03.9G0% /dev tmpfs3.9G03.9G0% /dev/shm tmpfs3.9G616K3.9G1% /run tmpfs3.9G03.9G0% /sys/fs/cgroup /dev/vdb1500G131G370G27% /data1 tmpfs783M0783M0% /run/user/0 ossfs256T0256T0% /aliyun_oss /dev/mapper/vg_data-lv_data100G33M100G1% /data2 [root@testdb ~]#

7、写入/etc/fstab文件进行开机重启自动挂载设备
[root@testdb vg_data]# cat /etc/fstab |grep data2 /dev/mapper/vg_data-lv_data/data2 xfs defaults 0 0

手动执行命令进行挂载:
执行如下命令,将/dev/mapper/vg_data-lv_data 挂载到/data2目录下 mount /dev/mapper/vg_data-lv_data /data2

提示:
挂载文件信息一定要填写对,否则服务器重启失败,导致登陆不了服务器,物理服务器需要单用户进行操作删除填写错误的/etc/fstab文件。阿里云ECS的话 只能是提交工单处理了
8、添加新硬盘/dev/vdd扩充已经存在的逻辑卷分区lv_data的存储空间 a、查看现有的物理卷信息:
[root@testdb ~]#pvdisplay --- Physical volume --- PV Name/dev/vdc VG Namevg_data PV Size100.00 GiB / not usable 4.00 MiB Allocatableyes (but full) PE Size4.00 MiB Total PE25599 Free PE0 Allocated PE25599 PV UUIDn6HJ5u-E9Ld-4WGc-1RRq-uyL9-Vr1i-dIP6Ai

b、创建物理卷和查看当前物理卷:
[root@testdb data2]# pvcreate /dev/vdd [root@testdb data2]# pvdisplay

c、扩展卷组
现有卷组:
[root@testdb data2]# lvdisplay --- Logical volume --- LV Path/dev/vg_data/lv_data LV Namelv_data VG Namevg_data LV UUID3zjVzF-JvDH-FuAY-nABr-LWW3-n4eu-k6nWr8 LV Write Accessread/write LV Creation host, time testdb, 2022-03-23 12:05:49 +0800 LV Statusavailable # open1 LV Size< 100.00 GiB Current LE25599 Segments1 Allocationinherit Read ahead sectorsauto - currently set to8192 Block device252:0

执行扩展卷组命令把新设备/dev/vdd加入到vg_data卷组:
[root@testdb data2]# vgextendvg_data /dev/vdd Volume group "vg_data" successfully extended [root@testdb data2]#

再次查看物理卷组信息:
[root@testdb ~]#pvdisplay --- Physical volume --- PV Name/dev/vdc VG Namevg_data PV Size100.00 GiB / not usable 4.00 MiB Allocatableyes (but full) PE Size4.00 MiB Total PE25599 Free PE0 Allocated PE25599 PV UUIDn6HJ5u-E9Ld-4WGc-1RRq-uyL9-Vr1i-dIP6Ai--- Physical volume --- PV Name/dev/vdd VG Namevg_data PV Size50.00 GiB / not usable 4.00 MiB Allocatableyes (but full) PE Size4.00 MiB Total PE12799 Free PE0 Allocated PE12799 PV UUIDFu3oyF-lGDw-Mo4b-OJFH-YZle-0H84-kZ3UEa

扩展/dev/vg_data/lv_data 卷(/lv_data分区):
[root@testdb data2]# lvextend -l +100%FREE/dev/vg_data/lv_data Size of logical volume vg_data/lv_data changed from < 100.00 GiB (25599 extents) to 149.99 GiB (38398 extents). Logical volume vg_data/lv_data successfully resized. [root@testdb data2]# lvdisplay --- Logical volume --- LV Path/dev/vg_data/lv_data LV Namelv_data VG Namevg_data LV UUID3zjVzF-JvDH-FuAY-nABr-LWW3-n4eu-k6nWr8 LV Write Accessread/write LV Creation host, time testdb, 2022-03-23 12:05:49 +0800 LV Statusavailable # open1 LV Size149.99 GiB Current LE38398 Segments2 Allocationinherit Read ahead sectorsauto - currently set to8192 Block device252:0

d、采用xfs_growfs进行扩展逻辑卷组分区
[root@testdb data2]# xfs_growfs /dev/vg_data/lv_data meta-data=https://www.songbingjia.com/dev/mapper/vg_data-lv_data isize=512agcount=4, agsize=6553344 blks =sectsz=512attr=2, projid32bit=1 =crc=1finobt=0 spinodes=0 data=bsize=4096blocks=26213376, imaxpct=25 =sunit=0swidth=0 blks naming=version 2bsize=4096ascii-ci=0 ftype=1 log=internalbsize=4096blocks=12799, version=2 =sectsz=512sunit=0 blks, lazy-count=1 realtime =noneextsz=4096blocks=0, rtextents=0 data blocks changed from 26213376 to 39319552 [root@testdb data2]# [root@testdb data2]# df -hT FilesystemTypeSizeUsed Avail Use% Mounted on /dev/vda1ext440G28G11G74% / devtmpfsdevtmpfs3.9G03.9G0% /dev tmpfstmpfs3.9G03.9G0% /dev/shm tmpfstmpfs3.9G584K3.9G1% /run tmpfstmpfs3.9G03.9G0% /sys/fs/cgroup /dev/vdb1xfs500G131G370G27% /data1 tmpfstmpfs783M0783M0% /run/user/996 tmpfstmpfs783M0783M0% /run/user/0 /dev/mapper/vg_data-lv_data xfs150G33M150G1% /data2 [root@testdb data2]# cat test 2344

注意:
xfs文件系统使用 xfs_growfs,ext文件系统使用 resize2fs;xfs文件系统只支持增大不支持缩小

    推荐阅读