Linux高级存储管理(LVM、VDO)

1.逻辑卷(LVM)

逻辑卷

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

lvm设备建立

开启监控
[root@d ~]# watch -n 1 "pvs;echo ====;vgs;echo =====;lvs;echo =====;df -H /westos"

[root@d ~]# fdisk /dev/vdb #管理分区 +1G t 8e
[root@d ~]# udevadm settle #同步分区表
[root@d ~]# blkid ##设备管理方式及设备id
[root@d ~]# pvcreate /dev/vdb1  ##创建pv
[root@d ~]# vgcreate westosvg /dev/vdb1  (-s 2M /dev/vdb1)  ##创建vg -s设定pe大小位2M
[root@d ~]# lvcreate -L 100M -n westoslv westosvg   ##创建lvm -L指定大小 -n指定名称
[root@d ~]# mkfs.xfs /dev/mapper/westosvg-westoslv ##格式化
[root@d ~]# mount /dev/westosvg/westoslv /westos ##挂载

lvm拉伸

当vg中的容量充足

[root@d ~]# lvextend -L 500M /dev/westosvg/westoslv ##拉伸设备
[root@d ~]# xfs_growfs /dev/westosvg/westoslv  ##拉伸文件系统,在rhel7中可以用设备或挂载点##在rhel8中只能用挂载点

resize2fs  /dev/mapper/westosvg-westoslv		##当文件系统为ext时使用此命令

当vg中的容量不足

[root@d ~]# fdisk /dev/vdb #管理分区 +1G t 8e
[root@d ~]# pvcreate /dev/vdb2
[root@d ~]# vgextend westosvg /dev/vdb2
[root@d ~]# lvextend -L 1500M /dev/westosvg/westoslv
[root@d ~]# xfs_growfs /dev/westosvg/westoslv

lvm缩减

xfs文件系统不支持缩减ext文件系统可以
mkfs.ext4	/dev/westosvg/westoslv
ext4文件系统拉伸:
resize2fs  /dev/mapper/westosvg-westoslv

[root@d ~]# umount /westos
[root@d ~]# mkfs.ext4 /dev/westosvg/westoslv
[root@d ~]# udevadm settle
[root@d ~]# mount /dev/westosvg/westoslv /westos
[root@d ~]# lvextend -L 1800M /dev/westosvg/westoslv 
[root@d ~]# umount /westos
[root@d ~]# e2fsck -f /dev/westosvg/westoslv 
[root@d ~]# resize2fs /dev/westosvg/westoslv 500M
[root@d ~]# mount /dev/westosvg/westoslv /westos
[root@d ~]# lvreduce -L 500M /dev/westosvg/westoslv

vg缩减

[root@d ~]# vgreduce westosvg /dev/vdb2
[root@d ~]# vgextend westosvg /dev/vdb2
[root@d ~]# pvmove  /dev/vdb1 /dev/vdb2
[root@d ~]# vgreduce westosvg /dev/vdb1
[root@d ~]# pvremove /dev/vdb1

lvm删除

[root@d ~]# umount /westos
[root@d ~]# lvremove /dev/westosvg/westoslv-bak 
[root@d ~]# lvremove /dev/westosvg/westoslv 
[root@d ~]# vgremove westosvg
[root@d ~]# pvremove /dev/vdb2 

建立lvm的快照

[root@d ~]# cd /westos
[root@d westos]# ls
lost+found
[root@d westos]# touch file{1..3}
[root@d westos]# cd
[root@d ~]# umount /westos 
[root@d ~]# cd /westos
[root@d westos]# ls
[root@d ~]# lvcreate -L 50M -n westoslv-bak -s /dev/westosvg/westoslv
[root@d ~]# mount /dev/westosvg/westoslv /westos
[root@d ~]# cd /westos
[root@d westos]# ls
file1  file2  file3  lost+found
[root@d westos]# rm -rf *
[root@d westos]# cd
[root@d ~]# umount /westos 
[root@d ~]# lvremove /dev/westosvg/westoslv-bak 
[root@d ~]# lvcreate -L 50M -n westoslv-bak -s /dev/westosvg/westoslv
[root@d ~]# mount /dev/westosvg/westoslv-bak /westos
[root@d ~]# cd /westos
[root@d westos]# ls

2.VDO(虚拟数据优化器)

vdo设备的建立

dnf install vdo -y
vdo create --name=westos_vdo --device=/dev/vdb
vdo status --name=westos_vdo | less
Deduplication:	enabled		##vdo检测并删除重复数据的功能时开启的
Compression:    enabled		##vdo数据压缩功能开启

[root@d ~]# mkfs.xfs -K /dev/mapper/westos_vdo -f
[root@d ~]# blkid
[root@d ~]# mkdir /westos_vdo
[root@d ~]# mount /dev/mapper/westos_vdo /westos_vdo
[root@d ~]# vdostats --human-readable 
Device                    Size      Used Available Use% Space saving%
/dev/mapper/westos_vdo     10.0G      4.0G      6.0G  40%           98%
[root@d ~]# find / -size +100M
[root@d ~]# cp /usr/lib64/firefox/libxul.so /westos_vdo/file1
[root@d ~]# vdostats --human-readable 
Device                    Size      Used Available Use% Space saving%
/dev/mapper/westos_vdo     10.0G      4.0G      6.0G  40%           26%
[root@d ~]# cp /usr/lib64/firefox/libxul.so /westos_vdo/file2
[root@d ~]# vdostats --human-readable 
Device                    Size      Used Available Use% Space saving%
/dev/mapper/westos_vdo     10.0G      4.1G      5.9G  41%           72%

vdo设备的删除

# man vdo
x-systemd.requires=vdo.service 0 0
# vim /etc/fstab
/dev/mapper/westos_vdo1       /westos      xfs     defaults,x-systemd.requires=vdo.service 0 0 ##开机自动挂载

[root@d ~]# vdo remove --name=westos_vdo

猜你喜欢

转载自blog.csdn.net/qq_45090453/article/details/109704294