6 linux 高级存储管理

pv   ##物理卷  被处理的物理分区
pe   ##物理扩展  设定存储最小单元
vg   ##物理卷组  捆绑pv到一个组中
lv   ##逻辑卷    分配最终的使用设备

监控建立过程
watch -n 1 "pvs;echo =====;vgs;echo====;lvs;echo =====;df -h /zzz"

lvm设备建立
建立物理分区并设定分区type为lvm

pvcreate /dev/vdb1  ##创建pv
vgcreate westosvg -s 2M /dev/vdb1   ##创建vg -s 设定pe大小位2M
lvcreate -L 100M -n westoslv westosvg ##创建lvm -L 指定大小 -n指定名称
mkfs.xfs /dev/mapper/westossvg-westoslv ##格式化
mount /dev/westosvg/westoslv /zzz      ##挂载

Every 1.0s: pvs;echo ===;vg...  westoslinux.westos.org: Mon Aug  2 17:21:24 2021PV         VG  Fmt  Attr PSize    PFree/dev/vdb1  vg0 lvm2 a--  1022.00m 1000.00m/dev/vdb2      lvm2 ---     1.00g    1.00g
===VG  #PV #LV #SN Attr   VSize    VFreevg0   1   1   0 wz--n- 1022.00m 1000.00m
====LV   VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv0  vg0 -wi-ao---- 22.00m
=====
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv0   17M  1.4M   16M   8% /zzz##以上都是监控
[root@westoslinux ~]# fdisk /dev/vdb    ##创建 Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): p
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa5c2fbd9Command (m for help): n
Partition typep   primary (0 primary, 0 extended, 4 free)e   extended (container for logical partitions)
Select (default p): Using default response p.
Partition number (1-4, default 1): 
First sector (2048-10485759, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +1GCreated a new partition 1 of type 'Linux' and of size 1 GiB.Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e         ##更改模式
Changed type of partition 'Linux' to 'Linux LVM'.Command (m for help): n
Partition typep   primary (1 primary, 0 extended, 3 free)e   extended (container for logical partitions)
Select (default p): Using default response p.
Partition number (2-4, default 2): 
First sector (2099200-10485759, default 2099200): 
Last sector, +sectors or +size{K,M,G,T,P} (2099200-10485759, default 10485759): +1GCreated a new partition 2 of type 'Linux' and of size 1 GiB.
Partition #2 contains a LVM2_member signature.Do you want to remove the signature? [Y]es/[N]o: yThe signature will be removed by a write command.Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'.Command (m for help): p     ##查看
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa5c2fbd9Device     Boot   Start     End Sectors Size Id Type
/dev/vdb1          2048 2099199 2097152   1G 8e Linux LVM
/dev/vdb2       2099200 4196351 2097152   1G 8e Linux LVMFilesystem/RAID signature on partition 2 will be wiped.Command (m for help): wq    ##保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.[root@westoslinux ~]# pvcreate /dev/vdb1    ##创建pvPhysical volume "/dev/vdb1" successfully created.
[root@westoslinux ~]# pvcreate /dev/vdb2Physical volume "/dev/vdb2" successfully created.
[root@westoslinux ~]# vgcreate vg0 /dev/vdb1   ##创建vgVolume group "vg0" successfully created
[root@westoslinux ~]# vgdisplay     ##查看vg--- Volume group ---VG Name               vg0System ID             Format                lvm2Metadata Areas        1Metadata Sequence No  1VG Access             read/writeVG Status             resizableMAX LV                0Cur LV                0Open LV               0Max PV                0Cur PV                1Act PV                1VG Size               1020.00 MiBPE Size               4.00 MiBTotal PE              255Alloc PE / Size       0 / 0   Free  PE / Size       255 / 1020.00 MiBVG UUID               xXqN43-Igc1-BcIV-X9FL-Necs-fv2Q-NscIwK[root@westoslinux ~]# vgcreate -s 2M vg0 /dev/vdb1   ## 指定位置大小位2MVolume group "vg0" successfully created
[root@westoslinux ~]# vgdisplay --- Volume group ---VG Name               vg0System ID             Format                lvm2Metadata Areas        1Metadata Sequence No  1VG Access             read/writeVG Status             resizableMAX LV                0Cur LV                0Open LV               0Max PV                0Cur PV                1Act PV                1VG Size               1022.00 MiBPE Size               2.00 MiBTotal PE              511Alloc PE / Size       0 / 0   Free  PE / Size       511 / 1022.00 MiBVG UUID               9Ds8dJ-nrLG-HXur-VWGt-Xm1Y-ef5j-6hM0m8[root@westoslinux ~]# lvcreate -L 22M -n lv0 vg0    ##创建 lv -L指定大小  -n指定名称
WARNING: xfs signature detected on /dev/vg0/lv0 at offset 0. Wipe it? [y/n]: yWiping xfs signature on /dev/vg0/lv0.
WARNING: xfs_external_log signature detected on /dev/vg0/lv0 at offset 24576. Wipe it? [y/n]: yWiping xfs_external_log signature on /dev/vg0/lv0.
WARNING: xfs_external_log signature detected on /dev/vg0/lv0 at offset 25600. Wipe it? [y/n]: yWiping xfs_external_log signature on /dev/vg0/lv0.
WARNING: xfs_external_log signature detected on /dev/vg0/lv0 at offset 26624. Wipe it? [y/n]: yWiping xfs_external_log signature on /dev/vg0/lv0.Logical volume "lv0" created.[root@westoslinux ~]# mkfs.xfs /dev/vg0/lv0     ##以mkfs.xfs  进行vg0 lv0 格式化meta-data=/dev/vg0/lv0           isize=512    agcount=1, agsize=5632 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=1, sparse=1, rmapbt=0=                       reflink=1
data     =                       bsize=4096   blocks=5632, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=1368, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0[root@westoslinux ~]# df     ##查看挂载
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          403524       0    403524   0% /dev
tmpfs             419124       0    419124   0% /dev/shm
tmpfs             419124    6696    412428   2% /run
tmpfs             419124       0    419124   0% /sys/fs/cgroup
/dev/vda3       17814528 3326640  14487888  19% /
/dev/vda1        1038336  173172    865164  17% /boot
tmpfs              83824    1184     82640   2% /run/user/42
tmpfs              83824      40     83784   1% /run/user/0
[root@westoslinux ~]# mkdir /zzz/
[root@westoslinux ~]# mount /dev/vg0/lv0 /zzz/   ##挂载到/zzz/目录
[root@westoslinux ~]# df
Filesystem          1K-blocks    Used Available Use% Mounted on
devtmpfs               403524       0    403524   0% /dev
tmpfs                  419124       0    419124   0% /dev/shm
tmpfs                  419124    6684    412440   2% /run
tmpfs                  419124       0    419124   0% /sys/fs/cgroup
/dev/vda3            17814528 3325056  14489472  19% /
/dev/vda1             1038336  173172    865164  17% /boot
tmpfs                   83824    1184     82640   2% /run/user/42
tmpfs                   83824      40     83784   1% /run/user/0
/dev/mapper/vg0-lv0     17056    1336     15720   8% /zzz

lvm拉伸
1.当vg中的容量充足
lvextend -L 200M /dev/mapper/westosvg-westoslv   ##拉伸设备
xfs_growfs   /zzz  ##拉伸文件系统,在rhel7中可以用设备或挂载点

Every 1.0s: pvs;echo ===;vg...  westoslinux.westos.org: Mon Aug  2 17:41:32 2021PV         VG  Fmt  Attr PSize    PFree/dev/vdb1  vg0 lvm2 a--  1022.00m      0/dev/vdb2  vg0 lvm2 a--  1022.00m 544.00m
===VG  #PV #LV #SN Attr   VSize  VFreevg0   2   1   0 wz--n- <2.00g 544.00m
====LV   VG  Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv0  vg0 -wi-ao---- 1.46g
=====
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv0  1.5G   16M  1.5G   2% /zzz
[root@westoslinux ~]# vgextend vg0 /dev/vdb2   ##拉伸vg 物理组Volume group "vg0" successfully extended
[root@westoslinux ~]# lvextend -L 1500 /dev/vg0/lv0   ##拉伸设备逻辑卷Size of logical volume vg0/lv0 changed from 22.00 MiB (11 extents) to 1.46 GiB (750 extents).Logical volume vg0/lv0 successfully resized.
[root@westoslinux ~]# lvextend -L 1500M /dev/vg0/lv0 New size (750 extents) matches existing size (750 extents).[root@westoslinux ~]# xfs_growfs /dev/vg0/lv0    ##拉伸文件系统
meta-data=/dev/mapper/vg0-lv0    isize=512    agcount=1, agsize=5632 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=1, sparse=1, rmapbt=0=                       reflink=1
data     =                       bsize=4096   blocks=5632, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=1368, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5632 to 384000

缩减步骤:

[root@westoslinux ~]# umount /zzz   ##卸载
[root@westoslinux ~]# resize2fs  -f /dev/vg0/lv0 500M    
resize2fs 1.45.4 (23-Sep-2019)
Resizing the filesystem on /dev/vg0/lv0 to 128000 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 128000 (4k) blocks long.[root@westoslinux ~]# lvreduce -L 500M /dev/vg0/lv0 WARNING: Reducing active logical volume to 500.00 MiB.THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg0/lv0? [y/n]: ySize of logical volume vg0/lv0 changed from 1.95 GiB (1000 extents) to 500.00 MiB (250 extents).Logical volume vg0/lv0 successfully resized.
[root@westoslinux ~]# mount /dev/vg0/lv0 /zzz
[root@westoslinux ~]# vgextend vg0 /dev/vdb2Volume group "vg0" successfully extended
[root@westoslinux ~]# pvmove /dev/vdb1 /dev/vdb2   ##转换/dev/vdb1: Moved: 2.80%/dev/vdb1: Moved: 100.00%
[root@westoslinux ~]# vgreduce vg0 /dev/vdb1Removed "/dev/vdb1" from volume group "vg0"
[root@westoslinux ~]# pvremove /dev/vdb1Labels on physical volume "/dev/vdb1" successfully wiped.

 

lvm删除:

 [root@westoslinux ~]# umount /zzz   ##卸载掉进行删除
[root@westoslinux ~]# lvremove /dev/vg0/lv0 
Do you really want to remove active logical volume vg0/lv0? [y/n]: yLogical volume "lv0" successfully removed
[root@westoslinux ~]# vgremove vg0Volume group "vg0" successfully removed
[root@westoslinux ~]# pvremove /dev/vdb2Labels on physical volume "/dev/vdb2" successfully wiped.

#vdo建立#

把之前的删除全部删除进行vdo实验

nf install vdo -y
vdo create --name=westos_vdo1 --device=/dev/sdb
vdo status --name=westos_vdo1 | less

Deduplication: enabled      ##vdo检测并删除重复数据的功能时开启的
Compression:  enabled     ##vdo数据压缩功能开启

#使用vdo设备#
mkfs.xfs -K /dev/mapper/westos_vdo1

mkdir  /zzz

mount /dev/mapper/westos_vdo1 /zzz

#测试vdo性能#
watch -n 1     vdostats --human-readable    开启监控

Every 1.0s: vdostats --huma...  westoslinux.westos.org: Mon Aug  2 23:04:45 2021Device                    Size      Used Available Use% Space saving%
/dev/mapper/westos_vdo1      5.0G      3.0G	 2.0G  60%           98%
[westos@westos_student70 Desktop]$ df
Filesystem     1K-blocks     Used Available Use% Mounted on
devtmpfs         3929044        0   3929044   0% /dev
tmpfs            3957384    52356   3905028   2% /dev/shm
tmpfs            3957384    43120   3914264   2% /run
tmpfs            3957384        0   3957384   0% /sys/fs/cgroup
/dev/nvme0n1p8  93095516 32804524  60290992  36% /
/dev/nvme0n1p6   1038336   226948    811388  22% /boot
/dev/nvme0n1p1    262144    35944    226200  14% /boot/efi
tmpfs             791476       20    791456   1% /run/user/42
tmpfs             791476       92    791384   1% /run/user/1000
/dev/sda1       30703568   368016  30335552   2% /run/media/westos/E83D-C1A6
/dev/loop0       8238560  8238560         0 100% /var/www/html/westos  ##找一个500m左右的大小文件[root@westos_student70 ~]# cd /var/www/html/westos[root@westos_student70 westos]#  ls
AppStream  EULA              images      RPM-GPG-KEY-redhat-beta
BaseOS     extra_files.json  isolinux    RPM-GPG-KEY-redhat-release
EFI        GPL               media.repo  TRANS.TBL
[root@westos_student70 westos]# cd images
[root@westos_student70 images]# ls
efiboot.img  install.img  pxeboot  TRANS.TBL
[root@westos_student70 images]# du -sh install.img
532M	install.img[root@westoslinux ~]# cd /zzz
[root@westoslinux zzz]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
devtmpfs                   919800       0    919800   0% /dev
tmpfs                      935404       0    935404   0% /dev/shm
tmpfs                      935404    9636    925768   2% /run
tmpfs                      935404       0    935404   0% /sys/fs/cgroup
/dev/vda3                17814528 3334920  14479608  19% /
/dev/vda1                 1038336  173172    865164  17% /boot
tmpfs                      187080    1180    185900   1% /run/user/42
tmpfs                      187080      24    187056   1% /run/user/0
/dev/mapper/westos_vdo1   2082192   47612   2034580   3% /zzz
[root@westoslinux zzz]# wget http://172.25.254.70/westos/images/install.img
--2021-08-02 23:11:56--  http://172.25.254.70/westos/images/install.img
Connecting to 172.25.254.70:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 557301760 (531M) [application/octet-stream]
Saving to: ‘install.img’install.img         100%[===================>] 531.48M   182MB/s    in 2.9s    2021-08-02 23:11:59 (182 MB/s) - ‘install.img’ saved [557301760/557301760]

##查看监控

Every 1.0s: vdostats --huma...  westoslinux.westos.org: Mon Aug  2 23:12:32 2021Device                    Size      Used Available Use% Space saving%
/dev/mapper/westos_vdo1      5.0G      3.5G	 1.5G  70%            1%##大小变化

vim /etc/fstab  ##永久挂载

/dev/mapper/vdodevice /westos xfs defaults,x-systemd.requires=vdo.service 0 0

#vdo设备的删除#
vdo remove --name=westos_vdo1

本文链接:https://my.lmcjl.com/post/7132.html

展开阅读全文

4 评论

留下您的评论.