本文主要是介绍Linux下的lvm镜像与快照,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
lvm镜像(mirror)
(1)划分三个PV,其中2个PV大小要一模一样
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd33473f7Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux ----5G
/dev/sdb2 655 1308 5253255 83 Linux ----5G
/dev/sdb3 1309 1373 522112+ 83 Linux ----日志 500M
(2)把三个PV做成一个VG组
pvcreate /dev/sdb{1,2,3}Physical volume "/dev/sdb1" successfully createdPhysical volume "/dev/sdb2" successfully createdPhysical volume "/dev/sdb3" successfully createdpvsPV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 a-- 5.01g 5.01g/dev/sdb2 lvm2 a-- 5.01g 5.01g/dev/sdb3 lvm2 a-- 509.88m 509.88vgcreate mvg /dev/sdb1 /dev/sdb2 /dev/sdb3Volume group "mvg" successfully created
(3)新建一个mirror lv卷
lvcreate -m1 -L 5G -n mlv mvgLogical volume "mlv" createdlvs -a --发现当前的这个LV是由三个PV组成的LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convertmlv mvg mwi-a-m--- 5.00g mlv_mlog 55.62 [mlv_mimage_0] mvg Iwi-aom--- 5.00g [mlv_mimage_1] mvg Iwi-aom--- 5.00g [mlv_mlog] mvg lwi-aom--- 4.00m
(4)测试当前mirror lv是否有镜像功能
mkfs.ext4 /dev/mvg/mlv
mount /dev/mvg/mlv /mntrpm -q sysstat --如果没有安装就安装下面的包
yum -y install sysstat
iostat -x 1 /dev/sda5 /dev/sda6
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda5 143.00 0.00 33.00 0.00 22528.00 0.00 682.67 0.11 3.48 2.94 9.70
sda6 0.00 154.00 0.00 22.00 0.00 22528.00 1024.00 0.25 11.09 11.23 24.70avg-cpu: %user %nice %system %iowait %steal %idle57.07 0.00 30.81 6.06 0.00 6.06Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda5 144.00 0.00 32.00 0.00 22528.00 0.00 704.00 0.12 3.84 3.16 10.10
sda6 0.00 154.00 0.00 22.00 0.00 22528.00 1024.00 0.25 11.14 11.18 24.60
(5)测试镜像卷中单个PV失效
dd if=/dev/zero of=/dev/sdb1 count=1 bs=10MpvsCouldn't find device with uuid 41RfAr-mPfM-Voj0-qEfP-CCO5-AXfF-epScKO.PV VG Fmt Attr PSize PFree /dev/sda2 vol0 lvm2 a-- 7.78g 448.00m/dev/sda6 mvg lvm2 a-- 5.01g 3.01g/dev/sda7 mvg lvm2 a-- 108.00m 104.00munknown device mvg lvm2 a-m 5.00g 3.00gvgsCouldn't find device with uuid 41RfAr-mPfM-Voj0-qEfP-CCO5-AXfF-epScKO.VG #PV #LV #SN Attr VSize VFree mvg 3 1 0 wz-pn- 10.11g 6.11gvol0 1 2 0 wz--n- 7.78g 448.00mlvs -aCouldn't find device with uuid 41RfAr-mPfM-Voj0-qEfP-CCO5-AXfF-epScKO.LV VG Attr LSize Pool Origin Data% Move Log Copy% Convertmlv mvg mwi-a-m- 2.00g mlv_mlog 100.00 [mlv_mimage_0] mvg iwi-aom- 2.00g [mlv_mimage_1] mvg iwi-aom- 2.00g [mlv_mlog] mvg lwi-aom- 4.00m home vol0 -wi-ao-- 512.00m root vol0 -wi-ao-- 6.84g
剔除失效PV
vgreduce mvg --removemissing --forcepvsPV VG Fmt Attr PSize PFree /dev/sda2 vol0 lvm2 a-- 7.78g 448.00m/dev/sda6 mvg lvm2 a-- 5.01g 3.01g/dev/sda7 mvg lvm2 a-- 108.00m 108.00mvgsVG #PV #LV #SN Attr VSize VFree mvg 2 1 0 wz--n- 5.11g 3.11gvol0 1 2 0 wz--n- 7.78g 448.00mlvs -aLV VG Attr LSize Pool Origin Data% Move Log Copy% Convertmlv mvg -wi-a--- 2.00g home vol0 -wi-ao-- 512.00m root vol0 -wi-ao-- 6.84g
恢复后尝试重新挂载原始LV
mount /dev/mvg/mlv /mnt[root@zhou ~]# ls /mnt
file lost+found
[root@zhou ~]# du -sh /mnt <----数据依然存在
501M /mnt
(6)彻底恢复带镜像功能的LV
重新新建一个PV
pvcreate /dev/sdb4vgextend mvg /dev/sda4lvconvert -m1 /dev/mvg/mlv lvs -aLV VG Attr LSize Pool Origin Data% Move Log Copy% Convertmlv mvg mwi-aom- 5.00g mlv_mlog 100.00 [mlv_mimage_0] mvg iwi-aom- 5.00g [mlv_mimage_1] mvg iwi-aom- 5.00g [mlv_mlog] mvg lwi-aom- 4.00m
LVM快照
1、确认卷组是否有足够的空闲空间
vgs
VG #PV #LV #SN Attr VSize VFree vg 2 0 0 wz--n- 10.02g 10.02glvs --原始LVlv vg -wi-a----- 8.00g
mount /dev/mapper/vg-lv /mnt
2、锁定应用保证原始LV没有数据更新,然后再新建快照
lvcreate -n lv_snap -L 100M -s /dev/vg/lv <--100M的意思就是创建快照后,在/dev/mapper/vg-lv_snap-cow对应的设备文件(等于这里的/mnt)只能写入100M的数据,如果在没备份完之前超过100M就会导致快照失效,然而旧数据备份也就失败,只能
3、先解锁应用,然后挂载快照并且做数据备份
mount /dev/mapper/lv_snap /media
cd /media && tar cjvf /backup/test.tar.bz2 ./
4、删除快照
lvremove /dev/GLSvg/lv_snap
5、快照对应的三个设备文件
/dev/mapper/vg-lv_snap --用于备份LV的原始数据,等于复制创建快照的时间点前的LV数据,可挂载后备份/dev/mapper/vg-lv-real --用于对应旧数据/dev/mapper/vg-lv_snap-cow --用于存放新写入和修改过的数据,相当于代替了原来的挂载点/mnt接收数据
这篇关于Linux下的lvm镜像与快照的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!