实验过程:首先分出一块磁盘,大小为5G,在创建两快分区,两块都设定+1G大小.
[root@westoslinux ~]# fdisk /dev/vdb
添加两个大小为1G 的lvm分区
Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 2099199 2097152 1G 8e Linux LVM
/dev/vdb2 2099200 4196351 2097152 1G 8e Linux LVM
监控建立:
[root@westoslinux ~]# mkdir /weixindata
[root@westoslinux ~]# pvs;echo ====;vgs;echo ====;lvs;echo ====;df -h /weixindata
[root@westoslinux ~]# watch -n 1 "pvs;echo ====;vgs;echo ====;lvs;echo ====;df -h /weixindata" 监控
lvm设备建立
[root@westoslinux ~]# pvcreate /dev/vdb1 创建pv
[root@westoslinux ~]# vgcreate -s 2M westosvg /dev/vdb1 创建vg -s设定pe大小为2M
[root@westoslinux ~]# lvcreate -L 200M -n westoslv1 westosvg 创建lvm -L指定大小 -n指定名称
[root@westoslinux ~]# mkfs.xfs /dev/westosvg/westoslv1 格式化
[root@westoslinux ~]# mount /dev/westosvg/westoslv1 /weixindata/ 挂载
lvm拉伸
[root@westoslinux ~]# lvextend -L 500M /dev/westosvg/westoslv1 当vg中的容量充足
[root@westoslinux ~]# xfs_growfs /dev/westosvg/westoslv1
[root@westoslinux ~]# pvcreate /dev/vdb2
[root@westoslinux ~]# vgextend westosvg /dev/vdb2
[root@westoslinux ~]# lvextend -L 1500M /dev/westosvg/westoslv1 当vg中的容量不足时重新添加pv
[root@westoslinux ~]# xfs_growfs /dev/westosvg/westoslv1
lvm缩减
[root@westoslinux ~]# umount /weixindata
[root@westoslinux ~]# mkfs.ext4 /dev/westosvg/westoslv1 ext4文件格式化
[root@westoslinux ~]# mount /dev/westosvg/westoslv1 /weixindata/
[root@westoslinux ~]# mount -a
[root@westoslinux ~]# mount 查看是否是ext4文件格式
[root@westoslinux ~]# lvextend -L 1800M /dev/westosvg/westoslv1
[root@westoslinux ~]# resize2fs /dev/westosvg/westoslv1 ext4文件系统拉伸
[root@westoslinux ~]# umount /weixindata
[root@westoslinux ~]# e2fsck -f /dev/westosvg/westoslv1 扫描文件大小
[root@westoslinux ~]# resize2fs /dev/westosvg/westoslv1 300M 先缩减文件系统大小为300M
[root@westoslinux ~]# mount /dev/westosvg/westoslv1 /weixindata/
[root@westoslinux ~]# lvreduce -L 300M /dev/westosvg/westoslv1
pv删除
[root@westoslinux ~]# pvmove /dev/vdb1 /dev/vdb2 把vdb1的pv移动到vdb2上
[root@westoslinux ~]# vgreduce westosvg /dev/vdb1
[root@westoslinux ~]# pvremove /dev/vdb1
lvm快照
[root@westoslinux ~]# touch /weixindata/westosfile{1..3}
[root@westoslinux ~]# ls /weixindata/
lost+found westosfile1 westosfile2 westosfile3
[root@westoslinux ~]# umount /weixindata
[root@westoslinux ~]# ls /weixindata/
[root@westoslinux ~]# lvcreate -L 50M -n westoslv1-backup -s /dev/westosvg/westoslv1 创建大小为50M的lv快照
[root@westoslinux ~]# mount /dev/westosvg/westoslv1-backup /weixindata/
[root@westoslinux ~]# ls /weixindata/
lost+found westosfile1 westosfile2 westosfile3
[root@westoslinux ~]# rm -fr /weixindata/*
[root@westoslinux ~]# ls /weixindata/
[root@westoslinux ~]# umount /weixindata
[root@westoslinux ~]# lvremove /dev/westosvg/westoslv1-backup
[root@westoslinux ~]# lvcreate -L 50M -n westoslv1-backup -s /dev/westosvg/westoslv1
[root@westoslinux ~]# mount /dev/westosvg/westoslv1-backup /weixindata/
[root@westoslinux ~]# ls /weixindata/
lost+found westosfile1 westosfile2 westosfile3
lvm删除
[root@westoslinux ~]# umount /weixindata 先卸载
[root@westoslinux ~]# lvremove /dev/westosvg/westoslv1-backup 删除快照
[root@westoslinux ~]# lvremove /dev/westosvg/westoslv1 删除lvm
[root@westoslinux ~]# vgremove westosvg
[root@westoslinux ~]# pvremove /dev/vdb2
2.vdo(Virtual Data Optimize)
#vdo建立#
实验环境
dd if=/dev/zero of=/dev/vdb bs=1M count=1 清空系统/dev/vdb/的mbr数据
添加一个20G的磁盘
如果本机电脑上没有vdo需要下载 yum install vdo kmod-kvdo -y
[root@westoslinux ~]# watch -n 1 vdostats --human-readable vdo监控
[root@westoslinux ~]# vdo create --name westos_vdo1 --device /dev/vdb vdo建立
[root@westoslinux ~]# vdo status --name westos_vdo1 | less
[root@westoslinux ~]# mkfs.xfs -K /dev/mapper/westos_vdo1 -k选项可防止立即丢弃文件系统中未使用的快,从而使命令返回更快
[root@westoslinux ~]# mount /dev/mapper/westos_vdo1 /weixindata/
测试vdo性能
[root@westoslinux ~]# cd /mnt/
[root@westoslinux mnt]# wget http://172.25.254.250/rhel8.2/images/install.img
[root@westoslinux mnt]# cp /mnt/install.img /weixindata/test1
[root@westoslinux mnt]# cp /mnt/install.img /weixindata/test2
[root@westoslinux mnt]# ls /weixindata/
test1 test2
[root@westoslinux mnt]# du -sh /weixindata/test1
532M /weixindata/test1
[root@westoslinux mnt]# du -sh /weixindata/test2
532M /weixindata/test2
会发现上传相同的文件,但是空间不会变化
[root@westoslinux mnt]# rm -fr /weixindata/test1
[root@westoslinux mnt]# rm -fr /weixindata/test2
[root@westoslinux mnt]# cd /weixindata/
[root@westoslinux weixindata]# ls
[root@westoslinux weixindata]# cp /mnt/install.img /weixindata/test3
[root@westoslinux weixindata]# vim /etc/fstab 永久挂载
[root@westoslinux weixindata]# mount -a
[root@westoslinux weixindata]# reboot
删除vdo
[root@westoslinux ~]# vim /etc/fstab 先删除永久挂载
[root@westoslinux ~]# mount -a
[root@westoslinux ~]# umount /weixindata
[root@westoslinux ~]# vdo stop --name westos_vdo1
Stopping VDO westos_vdo1
[root@westoslinux ~]# vdo remove --name westos_vdo1