扩展所有可以vg空间给lv lvextend -l +100%free /dev/vg01/lv01
[root@node2 ~]# lvcreate -L 300M -s -n lv01_snap /dev/vg01/lv01
[root@node2 ~]# lvscan
ACTIVE Original '/dev/vg01/lv01' [6.00 GB] inherit
ACTIVE Snapshot '/dev/vg01/lv01_snap' [300.00 MB] inherit
[root@node2 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv01 vg01 owi-ao 6.00G
lv01_snap vg01 swi-a- 300.00M lv01 0.00
[root@node2 ~]# lvdisplay
--- Logical volume ---
LV Name /dev/vg01/lv01
VG Name vg01
LV UUID 4tpV09-QXVs-Cw1K-wVh2-GREZ-gPfN-Xxnrsj
LV Write Access read/write
LV snapshot status source of
/dev/vg01/lv01_snap [active]
LV Status available
# open 1
LV Size 6.00 GB
Current LE 1536
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/vg01/lv01_snap
VG Name vg01
LV UUID sZUMpU-o2Bi-euaO-yUBm-cNRT-X13f-SchR61
LV Write Access read/write
LV snapshot status active destination for /dev/vg01/lv01
LV Status available
# open 0
LV Size 6.00 GB
Current LE 1536
COW-table size 300.00 MB
COW-table LE 75
Allocated to snapshot 0.00%
Snapshot chunk size 4.00 KB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@node2 ~]#
[root@node2 ~]# mkdir /mnt/lv01_snap
[root@node2 ~]# mount /dev/vg01/lv01_snap /mnt/lv01_snap/
[root@node2 ~]# ls /mnt/lv01
etc etc2 log lost+found
[root@node2 ~]#
[root@node2 ~]# ls /mnt/lv01_snap/
etc etc2 log lost+found
测试一:修改原始卷:适合使用快照备份
===建议快照卷不要挂载
[root@node2 ~]# umount /mnt/lv01_snap/
[root@node2 ~]# rm -rf /mnt/lv01/etc
[root@node2 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv01 vg01 owi-ao 6.00G
lv01_snap vg01 swi-a- 300.00M lv01 0.23
[root@node2 ~]#
[root@node2 ~]# lvdisplay vg01/lv01_snap
--- Logical volume ---
LV Name /dev/vg01/lv01_snap
VG Name vg01
LV UUID sZUMpU-o2Bi-euaO-yUBm-cNRT-X13f-SchR61
LV Write Access read/write
LV snapshot status active destination for /dev/vg01/lv01
LV Status available
# open 0
LV Size 6.00 GB
Current LE 1536
COW-table size 300.00 MB
COW-table LE 75
Allocated to snapshot 0.23%
Snapshot chunk size 4.00 KB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@node2 ~]# cp -rf /etc/ /mnt/lv01/etc3
示例:脚本
1. 创建快照
2. 建议以只读的方式挂载快照卷
3. 备份软件读取快照卷的挂载点备份,例如需要30分钟
4. 备份结束后
卸载快照卷
删除快照卷
===手工指定快照卷的大小:快照卷的大小要根据原卷的数据增长情况而定
测试二:修改快照卷:适合快速建立虚拟机,测试场景
===建议原卷不要挂载
[root@node2 ~]# umount /mnt/lv01
[root@node2 ~]# lvcreate -L 100M -s -n lv01_snap1 /dev/vg01/lv01
Logical volume "lv01_snap1" created
[root@node2 ~]# lvcreate -L 100M -s -n lv01_snap2 /dev/vg01/lv01
Logical volume "lv01_snap2" created
[root@node2 ~]# lvcreate -L 100M -s -n lv01_snap3 /dev/vg01/lv01
Logical volume "lv01_snap3" created
[root@node2 ~]# mkdir /mnt/lv01_snap1
[root@node2 ~]# mkdir /mnt/lv01_snap2
[root@node2 ~]# mkdir /mnt/lv01_snap3
[root@node2 ~]# mount /dev/vg01/lv01_snap1 /mnt/lv01_snap1/
[root@node2 ~]# mount /dev/vg01/lv01_snap2 /mnt/lv01_snap2
[root@node2 ~]# mount /dev/vg01/lv01_snap3 /mnt/lv01_snap3
[root@node2 ~]# rm -rf /mnt/lv01_snap1/etc
[root@node2 ~]# rm -rf /mnt/lv01_snap2/etc2/
[root@node2 ~]# rm -rf /mnt/lv01_snap3/etc3/
[root@node2 ~]# umount /mnt/lv01_snap1
[root@node2 ~]# umount /mnt/lv01_snap2
[root@node2 ~]# umount /mnt/lv01_snap3
[root@node2 ~]# lvremove /dev/vg01/lv01_snap1
Do you really want to remove active logical volume lv01_snap1? [y/n]: y
Logical volume "lv01_snap1" successfully removed
[root@node2 ~]# lvremove /dev/vg01/lv01_snap2
Do you really want to remove active logical volume lv01_snap2? [y/n]: y
Logical volume "lv01_snap2" successfully removed
[root@node2 ~]# lvremove /dev/vg01/lv01_snap3
Do you really want to remove active logical volume lv01_snap3? [y/n]: y
Logical volume "lv01_snap3" successfully removed
利用快照卷快速建立虚拟机
===虚拟机必须安装在lv上
[root@zzy ~]# virsh list --all
Id 名称 状态
----------------------------------
0 Domain-0 running
1 rhel5_8-1 闲置
2 rhel5_8-2 闲置
- rhel5_8 关闭安装在逻辑卷,母机(不要使用,保留最原始)
- rhel5_8-3 关闭
- rhel5_8-4 关闭
[root@zzy ~]# grep '^disk' /etc/xen/rhel5_8
disk = [ "phy:/dev/myvg/rhel5_8,xvda,w" ]
生成新虚拟机步骤:
1. 快照(生成虚拟机的磁盘文件)
[root@zzy ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
rhel5_8 myvg owi-a- 19.53G
[root@zzy ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 1 5 4 wz--n- 46.57G 19.23G
[root@zzy ~]# lvcreate -L 2G -s -n rhel5_8_snap10 /dev/myvg/rhel5_8
Logical volume "rhel5_8_snap10" created
2。生成新虚拟机的配置文件
[root@zzy ~]# cd /etc/xen/
[root@zzy xen]# ls
auto rhel5_8-2 xend-config.sxp xmexample2
qemu-ifup rhel5_8-3 xend-pci-permissive.sxp xmexample.hvm
rhel5_8 rhel5_8-4 xend-pci-quirks.sxp xmexample.vti
rhel5_8-1 scripts xmexample1
[root@zzy xen]# cp rhel5_8 rhel5_8_10
[root@zzy xen]# vim rhel5_8_10
name = "rhel5_8_10"<==修改
uuid = "2e99da65-8298-482a-8c09-3f6a9b3eb5bd"<==修改 uuidgen
maxmem = 512
memory = 512
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
vfb = [ "type=vnc,vncunused=1,keymap=en-us" ]
disk = [ "phy:/dev/myvg/rhel5_8_snap10,xvda,w" ]<==修改成快照卷
vif = [ "mac=00:16:3e:0e:d1:7f,bridge=virbr0,script=vif-bridge" ]<==修改MAC (16进制 0-9,a-f)
[root@zzy xen]# virsh list --all
Id 名称 状态
----------------------------------
0 Domain-0 running
1 rhel5_8-1 没有状态
2 rhel5_8-2 没有状态
- rhel5_8 关闭
- rhel5_8-3 关闭
- rhel5_8-4 关闭
- rhel5_8_10 关闭
[root@zzy xen]#
[root@zzy xen]# virsh start rhel5_8_10
域 rhel5_8_10 已开始
[root@zzy xen]# virsh destroy rhel5_8_10
域 rhel5_8_10 被删除
[root@zzy xen]# virsh undefine rhel5_8_10
域 rhel5_8_10 已经被取消定义
[root@zzy xen]# lvremove /dev/myvg/rhel5_8_snap10
Do you really want to remove active logical volume rhel5_8_snap10? [y/n]: y
Logical volume "rhel5_8_snap10" successfully removed
==snapshot自动增长==
[root@node2 ~]# vim /etc/lvm/lvm.conf
snapshot_autoextend_threshold = 70
snapshot_autoextend_percent = 50
[root@node2 ~]# /etc/init.d/lvm2-monitor restart
Stopping monitoring for VG vg01: 1 logical volume(s) in volume group "vg01" unmonitored
[确定]
Starting monitoring for VG vg01: 1 logical volume(s) in volume group "vg01" monitored
[确定]
[root@node2 ~]# lvcreate -L 100M -s -n lv01_snap /dev/vg01/lv01
Logical volume "lv01_snap" created
[root@node2 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv01 vg01 owi-ao 6.00G
lv01_snap vg01 swi-a- 100.00M lv01 0.01