两台主机dg1 和 dg2 其中/dev/sdc 是他们共同认到的一块盘,在dg1节点创建pv,vg,lv 然后格式化,挂载到/mnt,存个小文件进去,卸载,导出vg,在另外节点导入,仍然能看到这个文件。
上次用到类似这种功能是Oracle数据迁移碰见的。由于两个库数据比较大,两个节点共同连接同一个存储,创建大vg,老库备份数据到vg上。然后卸载vg挂载到新机器上恢复。
下面通过Linux来模拟这个场景:
1 查看共享磁盘
[[email protected] ~]# fdisk
-l
Disk /dev/sda: 21.4
GB, 21474836480 bytes
255 heads, 63
sectors/track, 2610 cylinders
Units = cylinders of
16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
Disk /dev/sdb: 21.4
GB, 21474836480 bytes
255 heads, 63
sectors/track, 2610 cylinders
Units = cylinders of
16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
Disk /dev/sdc: 1073
MB, 1073741824 bytes
255 heads, 63
sectors/track, 130 cylinders
Units = cylinders of
16065 * 512 = 8225280 bytes
Disk /dev/sdc
doesn‘t contain a valid partition table
[[email protected] ~]# fdisk
-l
Disk /dev/sda: 21.4
GB, 21474836480 bytes
255 heads, 63
sectors/track, 2610 cylinders
Units = cylinders of
16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
Disk /dev/sdb: 21.4
GB, 21474836480 bytes
255 heads, 63
sectors/track, 2610 cylinders
Units = cylinders of
16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
Disk /dev/sdc: 1073
MB, 1073741824 bytes
255 heads, 63
sectors/track, 130 cylinders
Units = cylinders of
16065 * 512 = 8225280 bytes
Disk /dev/sdc
doesn‘t contain a valid partition table
2 在节点1创建pv,vg,lv,并且格式化
[[email protected] ~]# pvcreate
/dev/sdc
Writing physical volume data to disk
"/dev/sdc"
Physical volume "/dev/sdc"
successfully created
[[email protected] ~]# vgcreate
-s 16M vg01 /dev/sdc
Volume group "vg01"
successfully created
[[email protected] ~]# lvcreate
-n lvtest -l 10 vg02
Logical volume "lvtest"
created
[[email protected] ~]# mkfs.ext3
/dev/vg02/lvtest
mke2fs 1.39
(29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024
(log=0)
Fragment size=1024
(log=0)
40960 inodes, 163840
blocks
8192 blocks (5.00%)
reserved for the super user
First data block=1
Maximum filesystem
blocks=67371008
20 block groups
8192 blocks per
group, 8192 fragments per group
2048 inodes per
group
Superblock backups stored
on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode
tables: done
Creating journal
(4096 blocks): done
Writing superblocks
and filesystem accounting information: done
This filesystem will
be automatically checked every 33 mounts or
180 days, whichever
comes first. Use tune2fs -c or -i
to override.
3 挂载存入小文件,卸载,导出vg
[[email protected] ~]# mount
/dev/vg02/lvtest /mnt
[[email protected] ~]# cp
/etc/services /mnt
[[email protected] ~]# umount
/mnt
[[email protected] ~]# vgchange
-an /dev/vg02
0 logical volume(s) in volume group
"vg02" now active
[[email protected] ~]# vgexport
/dev/vg02
Volume group "vg02"
successfully exported
4 导入vg,挂载lv,查看文件
[[email protected] ~]# vgimport
/dev/vg02
Volume group "vg02"
successfully imported
[[email protected] ~]# vgchange
-aly vg02
1 logical volume(s) in volume group
"vg02" now active
[[email protected] ~]# mount
/dev/vg02/lvtest /mnt
[[email protected] ~]# ls
/mnt
lost+found services