家装建材公司网站建设,初中做历史的网站,网站建设4000-262-263,oppo软件商店一、lvm----逻辑卷管理
1.lvm定义
LVM是 Logical Volume Manager#xff08;逻辑卷管理#xff09;的简写#xff0c;它是Linux环境下对磁盘分区进行管理的一种机制。
逻辑卷管理器(LogicalVolumeManager)本质上是一个虚拟设备驱动#xff0c;是在内核中块设备和物理设备…一、lvm----逻辑卷管理
1.lvm定义
LVM是 Logical Volume Manager逻辑卷管理的简写它是Linux环境下对磁盘分区进行管理的一种机制。
逻辑卷管理器(LogicalVolumeManager)本质上是一个虚拟设备驱动是在内核中块设备和物理设备之间添加的一个新的抽象层次如图所示。它可以将几块磁盘(物理卷PhysicalVolume)组合起来形成一个存储池或者卷组(VolumeGroup)。LVM可以每次从卷组中划分出不同大小的逻辑卷(LogicalVolume)创建新的逻辑设备。底层的原始的磁盘不再由内核直接控制而由LVM层来控制。对于上层应用来说卷组替代了磁盘块成为数据存储的基本单元。LVM管理着所有物理卷的物理盘区维持着逻辑盘区和物理盘区之间的映射。LVM逻辑设备向上层应用提供了和物理磁盘相同的功能如文件系统的创建和数据的访问等。但LVM逻辑设备不受物理约束的限制逻辑卷不必是连续的空间它可以跨越许多物理卷并且可以在任何时候任意的调整大小。相比物理磁盘来说更易于磁盘空间的管理。
pv 物理卷被处理过的物理分区pe物理扩展设定存储最小单元vg物理卷组捆绑pv到一个组中lv逻辑卷 分配最终的使用设备 2.实验素材
建立lvm分区新建目录建立监控
建立lvm分区
首先建立分区然后设置标签--8e 即lvm分区 建立成功后记得wq保存 以及同步分区表
实验建立监控查看watch -n 1 pvs;echo ;vgs;echo ;lvs;echo ;df -h /westosdir
新建目录 /westosdir/ 3. lvm设备建立
1创建pv---物理卷
# pvcreate /dev/vdb3
2创建vg---物理卷组
-s设定pe大小位2M
# vgcreate -s 2M westos_vg /dev/vdb3
3创建lv---逻辑卷
-L指定大小 -n指定名称
# lvcreate -L 100M -n westos_lv westos_vg
4格式化--创建文件系统
# mkfs.xfs /dev/westos_vg/westos_lv
5挂载设备至目录
# mount /dev/westos_vg/westos_lv /westosdir/ 监控界面如下 4. lvm拉伸
1vg容量充足
vg容量为1G.容量充足直接拉伸
# lvextend -L 200M /dev/westos_vg/westos_lv拉伸到200M
# xfs_growfs /dev/westos_vg/westos_lv拉伸文件系统否则无法使用 2vg容量不足 pvcreate /dev/vdb5创建新pvvgextend westos_vg /dev/vdb5扩展vg容量lvextend -L 1500M /dev/westos_vg/westos_lv 拉伸lvmxfs_growfs /dev/westos_vg/westos_lv格式化文件系统
想要拉伸lvm为1.5G发现容量不够 此时进入磁盘寻找lvm分区来创建新pv 扩展原来的vg容量然后进行lvm拉伸格式化文件系统 最后查看监控该设备容量拉伸成功 5.lvm缩减
卸载设备umount /westosdir扫描文件大小看看缩减大小是否合适e2fsck -f /dev/westos_vg/westos_lv缩减文件系统 resize2fs /dev/westos_vg/westos_lv 500M缩减lvmlvreduce -L 500M /dev/westos_vg/westos_lv重新挂载设备mount /dev/westos_vg/westos_lv /westosdir/
1前提
缩减lvm设备的前提是文件系统是ext或者ext4xfs文件系统不能缩减
由于之前实验我们使用的是xfs文件系统因此本节首先给lvm设备更换文件系统
# mkfs.ext4 /dev/westos_vg/westos_lv设定文件系统为ext4 2卸载设备扫描
扫描设备的文件大小防止lvm缩减太小不可用 3缩减文件系统lvm重新挂载设备 挂载成功后查看lvm设备已经成功缩减到500M 6. vg缩减
vgreduce westos_vg /dev/vdb3 把分区3从该vg中缩减pvmove /dev/vdb3 删除该pv
假如想缩减3首先将3的东西转移到5 pvmove /dev/vdb3 /dev/vdb5
然后直接将pv3从vg中减去
最后彻底删除pv3 7.lvm快照
LVM 机制还提供了对 LV 做快照的功能也就是说可以给⽂件系统做⼀个备份这也是设计 LVM 快照的主要⽬的。快照可以用于记录系统当前状态以便后续进行回滚操作回到此状态或将这些状态用于系统备份。这⽐传统的备份技术的效率要⾼很多。创建快照时不⽤停⽌服务就可以对数据进⾏备份。
创建快照快照名westos_lvbackup 原始/dev/westos_vg/westos_lv重新挂载即可生效 [rootwestosa ~]# lvcreate -L 50M -n westos_lvbackup -s /dev/westos_vg/westos_lv Logical volume westos_lvbackup created.
[rootwestosa ~]# mount /dev/westos_vg/westos_lvbackup /westosdir/实验
接上节建立的lvm设备挂载在/westosdir目录上
此时在目录中建立10个重要的文件由于设备挂载在该目录上因此该设备也有该数据 创建该设备的快照可记录下此时的系统状态便于备份
将快照挂载在该目录。
[rootwestosa ~]# umount /westosdir
[rootwestosa ~]# lvcreate -L 50M -n westos_lvbackup -s /dev/westos_vg/westos_lv Logical volume westos_lvbackup created.
[rootwestosa ~]# mount /dev/westos_vg/westos_lvbackup /westosdir/
[rootwestosa ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 391196 0 391196 0% /dev
tmpfs 419040 0 419040 0% /dev/shm
tmpfs 419040 6872 412168 2% /run
tmpfs 419040 0 419040 0% /sys/fs/cgroup
/dev/vda3 9450496 4344352 5106144 46% /
/dev/vda1 506528 218856 287672 44% /boot
tmpfs 83808 1180 82628 2% /run/user/42
tmpfs 83808 28 83780 1% /run/user/0
/dev/mapper/westos_vg-westos_lvbackup 96928 6068 90860 7% /westosdir
[rootwestosa ~]# ls /westosdir/
westosfile1 westosfile2 westosfile4 westosfile6 westosfile8
westosfile10 westosfile3 westosfile5 westosfile7 westosfile9如果不小心删除了10个重要的文件怎么办 因为有快照的存在可以恢复
首先卸载设备删除快照重新建立快照再次挂载至该目录
发现文件仍然存在
[rootwestosa ~]# umount /westosdir
[rootwestosa ~]# lvremove /dev/westos_vg/westos_lvbackup
Do you really want to remove active logical volume westos_vg/westos_lvbackup? [y/n]: yLogical volume westos_lvbackup successfully removed
[rootwestosa ~]# lvcreate -L 50M -n westos_lvbackup -s /dev/westos_vg/westos_lvLogical volume westos_lvbackup created.
[rootwestosa ~]# mount /dev/westos_vg/westos_lvbackup /westosdir/
[rootwestosa ~]# ls /westosdir/
westosfile1 westosfile2 westosfile4 westosfile6 westosfile8
westosfile10 westosfile3 westosfile5 westosfile7 westosfile98. lvm设备删除
卸载设备删除快照删除lv设备删除vg删除pv
[rootwestosa ~]# umount /westosdir
[rootwestosa ~]# lvremove /dev/westos_vg/westos_lvbackup
Do you really want to remove active logical volume westos_vg/westos_lvbackup? [y/n]: yLogical volume westos_lvbackup successfully removed
[rootwestosa ~]# lvremove /dev/westos_vg/westos_lv
Do you really want to remove active logical volume westos_vg/westos_lv? [y/n]: yLogical volume westos_lv successfully removed
[rootwestosa ~]# vgremove westos_vg Volume group westos_vg successfully removed
[rootwestosa ~]# pvremove /dev/vdb3 Labels on physical volume /dev/vdb3 successfully wiped.删除成功查看监控 二、vdoVirtual Data Optimize----虚拟数据优化器
VDO是一个内核模块目的是通过压缩和优化重复数据来节省磁盘空间从而降低数据中心的成本。原理主要是压缩和优化重复数据优化重复数据就是硬盘里拷贝来相同的数据以前要占多份空间现在只需要1份空间就可以了。
1. vdo的创建及使用 前提vdo必须要用没使用过的硬盘
ps:在创建新硬盘时空间不足在虚拟机管理界面把其他硬盘删除也不行
解决方法进入主机的硬盘存放地址,删除不用的硬盘
983 cd /var/lib/libvirt/images/984 ls985 rm -fr aa.qcow2 qq.qcow2 westosa-2.qcow2 westosa-4.qcow2 bb.qcow2 westosa-1.qcow2 westosa-3.qcow2 westosa-5.qcow2 westos.qcow2删除后添加新硬盘发现空间足够了 vdo的安装 vdo的创建: vdo create --namewestosvdo --device/dev/vdb
[rootwestosa ~]# dnf install vdo -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
AppStream 169 MB/s | 5.8 MB 00:00
BaseOS 144 MB/s | 2.3 MB 00:00
Package vdo-6.2.2.117-13.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[rootwestosa ~]# vdo create --namewestosvdo --device/dev/vdb
Creating VDO westosvdo
vdo: ERROR - Not enough available memory in system for index requirement of 256Mvdo的创建出现问题提示内存不足
只需要增加虚拟机的物理内存即可 增加后再次创建vdo成功
[rootwestosa ~]# dnf install vdo -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:05:08 ago on Sun 30 Jul 2023 02:56:24 PM CST.
Package vdo-6.2.2.117-13.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[rootwestosa ~]# vdo create --namewestosvdo --device/dev/vdb
Creating VDO westosvdoLogical blocks defaulted to 1569686 blocks.The VDO volume can address 6 GB in 3 data slabs, each 2 GB.It can grow to address at most 16 TB of physical storage in 8192 slabs.If a larger maximum size might be needed, use bigger slabs.
Starting VDO westosvdo
Starting compression on VDO westosvdo
VDO instance 0 volume is ready at /dev/mapper/westosvdo查看vdo的功能
数据压缩和重复检测功能均开启
[rootwestosa ~]# vdo status --namewestosvdo
VDO status:Date: 2023-07-30 15:06:0808:00Node: westosa.org
Kernel module:Loaded: trueName: kvdoVersion information:kvdo version: 6.2.2.117
Configuration:File: /etc/vdoconf.ymlLast modified: 2023-07-30 15:01:44
VDOs:westosvdo:Acknowledgement threads: 1Activate: enabledBio rotation interval: 64Bio submission threads: 4Block map cache size: 128MBlock map period: 16380Block size: 4096CPU-work threads: 2Compression: enabledConfigured write policy: autoDeduplication: enabledDevice mapper status: 0 12557488 vdo /dev/vdb normal - online online 1049638 2621440Emulate 512 byte: disabledHash zone threads: 1vdo格式化文件系统的建立挂载vdo设备可以使用拉
[rootwestosa ~]# mkfs.xfs /dev/mapper/westosvdo
meta-data/dev/mapper/westosvdo isize512 agcount4, agsize392422 blks sectsz4096 attr2, projid32bit1 crc1 finobt1, sparse1, rmapbt0 reflink1
data bsize4096 blocks1569686, imaxpct25 sunit0 swidth0 blks
naming version 2 bsize4096 ascii-ci0, ftype1
log internal log bsize4096 blocks2560, version2 sectsz4096 sunit1 blks, lazy-count1
realtime none extsz4096 blocks0, rtextents0
[rootwestosa ~]# mkdir /westosdir
[rootwestosa ~]# mount /dev/mapper/westosvdo /westosdir/
[rootwestosa ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 906060 0 906060 0% /dev
tmpfs 935132 0 935132 0% /dev/shm
tmpfs 935132 9784 925348 2% /run
tmpfs 935132 0 935132 0% /sys/fs/cgroup
/dev/mapper/rhel-root 8374272 4331900 4042372 52% /
/dev/vda1 1038336 234160 804176 23% /boot
tmpfs 187024 1180 185844 1% /run/user/42
tmpfs 187024 24 187000 1% /run/user/0
/dev/mapper/westosvdo 6268504 76808 6191696 2% /westosdir2.vdo的优化重复数据功能测试
建立监控查看测试结果
[rootwestosa ~]# vdostats --human-readable
Device Size Used Available Use% Space saving%
/dev/mapper/westosvdo 10.0G 4.0G 6.0G 40% 98%
[rootwestosa ~]# watch -n 1 vdostats --human-readable 监控界面如下 实验素材将主机大小为797M的截图发给虚拟机的/iso目录 重复数据检测将/iso的数据复制2次到/westsodir目录发现之占用了一份空间
因为此时vdo设备挂载在该目录上
[rootwestosa westosdir]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 906060 0 906060 0% /dev
tmpfs 935132 0 935132 0% /dev/shm
tmpfs 935132 9784 925348 2% /run
tmpfs 935132 0 935132 0% /sys/fs/cgroup
/dev/mapper/rhel-root 8374272 5149108 3225164 62% /
/dev/vda1 1038336 234160 804176 23% /boot
tmpfs 187024 1180 185844 1% /run/user/42
tmpfs 187024 24 187000 1% /run/user/0
/dev/mapper/westosvdo 6268504 76808 6191696 2% /westosdir
[rootwestosa westosdir]# cp -r /iso/ /westosdir/
[rootwestosa westosdir]# ls
iso
[rootwestosa westosdir]# cp -r /iso/ /westosdir/iso-1
[rootwestosa westosdir]# ls
iso iso-1
[rootwestosa westosdir]# du -h *
797M iso
797M iso-1查看监控两份内容一样的数据只占用了一份空间这就是vdo的重复数据优化功能!! 3. vdo设备开机自动挂载
编辑/etc/fstab文件注意需要添加x-systemd.requiresvdo.service 利用man vdo命令查看模板 重启虚拟机后该设备自动挂载 5. 删除vdo设备
卸载设备停止设备ps:停止后还可以打开删除设备
[rootwestosa ~]# umount /westosdir
[rootwestosa ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 906232 0 906232 0% /dev
tmpfs 935300 0 935300 0% /dev/shm
tmpfs 935300 9428 925872 2% /run
tmpfs 935300 0 935300 0% /sys/fs/cgroup
/dev/mapper/rhel-root 8374272 5149588 3224684 62% /
/dev/vda1 1038336 234460 803876 23% /boot
tmpfs 187060 1180 185880 1% /run/user/42
tmpfs 187060 4 187056 1% /run/user/0
[rootwestosa ~]# vdo stop --name westosvdo
Stopping VDO westosvdo
[rootwestosa ~]# vdo remove --name westosvdo
Removing VDO westosvdo
Stopping VDO westosvdo删除设备后该vdo设备删除成功 打开设备
[rootwestosa ~]# vdo stop --name westosvdo
Stopping VDO westosvdo
[rootwestosa ~]# vdo start --name westosvdo
Starting VDO westosvdo
Starting compression on VDO westosvdo
VDO instance 1 volume is ready at /dev/mapper/westosvdo
[rootwestosa ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 906232 0 906232 0% /dev
tmpfs 935300 0 935300 0% /dev/shm
tmpfs 935300 9432 925868 2% /run
tmpfs 935300 0 935300 0% /sys/fs/cgroup
/dev/mapper/rhel-root 8374272 5149608 3224664 62% /
/dev/vda1 1038336 234460 803876 23% /boot
tmpfs 187060 1180 185880 1% /run/user/42
tmpfs 187060 4 187056 1% /run/user/0
/dev/mapper/westosvdo 6268504 1711180 4557324 28% /westosdir注意打开设备后该设备自动挂载记得删除/etc/fstab里的自动挂载语句! 文章转载自: http://www.morning.rrqbm.cn.gov.cn.rrqbm.cn http://www.morning.rdnpg.cn.gov.cn.rdnpg.cn http://www.morning.qbzdj.cn.gov.cn.qbzdj.cn http://www.morning.dfbeer.com.gov.cn.dfbeer.com http://www.morning.grjh.cn.gov.cn.grjh.cn http://www.morning.bsplf.cn.gov.cn.bsplf.cn http://www.morning.ywtbk.cn.gov.cn.ywtbk.cn http://www.morning.pqqzd.cn.gov.cn.pqqzd.cn http://www.morning.ncrk.cn.gov.cn.ncrk.cn http://www.morning.npfrj.cn.gov.cn.npfrj.cn http://www.morning.lqynj.cn.gov.cn.lqynj.cn http://www.morning.rqxtb.cn.gov.cn.rqxtb.cn http://www.morning.hsxkq.cn.gov.cn.hsxkq.cn http://www.morning.rzcmn.cn.gov.cn.rzcmn.cn http://www.morning.tymwx.cn.gov.cn.tymwx.cn http://www.morning.lzsxp.cn.gov.cn.lzsxp.cn http://www.morning.wdqhg.cn.gov.cn.wdqhg.cn http://www.morning.ohmyjiu.com.gov.cn.ohmyjiu.com http://www.morning.krtcjc.cn.gov.cn.krtcjc.cn http://www.morning.qqbjt.cn.gov.cn.qqbjt.cn http://www.morning.yrdn.cn.gov.cn.yrdn.cn http://www.morning.dtfgr.cn.gov.cn.dtfgr.cn http://www.morning.qgjp.cn.gov.cn.qgjp.cn http://www.morning.wqwbj.cn.gov.cn.wqwbj.cn http://www.morning.ndxrm.cn.gov.cn.ndxrm.cn http://www.morning.chgmm.cn.gov.cn.chgmm.cn http://www.morning.hsrpr.cn.gov.cn.hsrpr.cn http://www.morning.ntgsg.cn.gov.cn.ntgsg.cn http://www.morning.rqlqd.cn.gov.cn.rqlqd.cn http://www.morning.wnhsw.cn.gov.cn.wnhsw.cn http://www.morning.tdxlj.cn.gov.cn.tdxlj.cn http://www.morning.ndfwh.cn.gov.cn.ndfwh.cn http://www.morning.yxyyp.cn.gov.cn.yxyyp.cn http://www.morning.ntwfr.cn.gov.cn.ntwfr.cn http://www.morning.ysdwq.cn.gov.cn.ysdwq.cn http://www.morning.pzrrq.cn.gov.cn.pzrrq.cn http://www.morning.rltw.cn.gov.cn.rltw.cn http://www.morning.yxwrr.cn.gov.cn.yxwrr.cn http://www.morning.rmrcc.cn.gov.cn.rmrcc.cn http://www.morning.swwpl.cn.gov.cn.swwpl.cn http://www.morning.pzrnf.cn.gov.cn.pzrnf.cn http://www.morning.mbbgk.com.gov.cn.mbbgk.com http://www.morning.jwncx.cn.gov.cn.jwncx.cn http://www.morning.jjmrx.cn.gov.cn.jjmrx.cn http://www.morning.nzzws.cn.gov.cn.nzzws.cn http://www.morning.zjcmr.cn.gov.cn.zjcmr.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.fgrcd.cn.gov.cn.fgrcd.cn http://www.morning.nmwgd.cn.gov.cn.nmwgd.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.nrjr.cn.gov.cn.nrjr.cn http://www.morning.nfzzf.cn.gov.cn.nfzzf.cn http://www.morning.rbktw.cn.gov.cn.rbktw.cn http://www.morning.rdmz.cn.gov.cn.rdmz.cn http://www.morning.ityi666.cn.gov.cn.ityi666.cn http://www.morning.rbtny.cn.gov.cn.rbtny.cn http://www.morning.yrjfb.cn.gov.cn.yrjfb.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.xxfxxf.cn.gov.cn.xxfxxf.cn http://www.morning.mzrqj.cn.gov.cn.mzrqj.cn http://www.morning.lmxrt.cn.gov.cn.lmxrt.cn http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn http://www.morning.yhsrp.cn.gov.cn.yhsrp.cn http://www.morning.xblrq.cn.gov.cn.xblrq.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn http://www.morning.xmxbm.cn.gov.cn.xmxbm.cn http://www.morning.mrnnb.cn.gov.cn.mrnnb.cn http://www.morning.ylph.cn.gov.cn.ylph.cn http://www.morning.nsrtvu.com.gov.cn.nsrtvu.com http://www.morning.lszjq.cn.gov.cn.lszjq.cn http://www.morning.rqjfm.cn.gov.cn.rqjfm.cn http://www.morning.kzpxc.cn.gov.cn.kzpxc.cn http://www.morning.cjnfb.cn.gov.cn.cjnfb.cn http://www.morning.lzph.cn.gov.cn.lzph.cn http://www.morning.ppgdp.cn.gov.cn.ppgdp.cn http://www.morning.jhzct.cn.gov.cn.jhzct.cn http://www.morning.jzgxp.cn.gov.cn.jzgxp.cn http://www.morning.fmkjx.cn.gov.cn.fmkjx.cn