Linux高级存储管理

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

 实验过程:首先分出一块磁盘,大小为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)

虚拟数据优化器: 通过压缩或删除设备上的数据来优化存储空间
kvdo ## 压缩数据
uds ## 优化重复数据

 #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

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

[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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值