LVM的镜像功能,有点儿类似于Raid1,即多块儿磁盘互相同步,确保资料不会丢失。
1、在此添加4块物理硬盘,每块2G空间
2、将sdb、sdc、sdd、sde 创建物理卷,将sdb、sdc、sdd 添加卷组到vmTest
[root@node4 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
[root@node4 ~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
[root@node4 ~]# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created
[root@node4 ~]# pvcreate /dev/sde
Physical volume "/dev/sde" successfully created
[root@node4 ~]# vgcreate vgTest /dev/sdb /dev/sdc /dev/sdd
Volume group "vgTest" successfully created
[root@node4 ~]#
3、创建逻辑卷
[root@node4 ~]# lvcreate -L 1G -m1 -n lvTest vgTest /dev/sdb /dev/sdc /dev/sdd
Logical volume "lvTest" created
查看lvs信息
[root@node4 ~]# lvs -a -o +devices
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert Devices
lv_root VolGroup -wi-ao---- 8.54g /dev/sda2(0)
lv_swap VolGroup -wi-ao---- 992.00m /dev/sda2(2186)
lvTest vgTest mwi-a-m--- 1.00g lvTest_mlog 100.00 lvTest_mimage_0(0),lvTest_mimage_1(0)
[lvTest_mimage_0] vgTest iwi-aom--- 1.00g /dev/sdb(0)
[lvTest_mimage_1] vgTest iwi-aom--- 1.00g /dev/sdc(0)
[lvTest_mlog] vgTest lwi-aom--- 4.00m /dev/sdd(0)
LVM镜像需要用到-m1参数,从上面可以看出,/dev/sdb和/dev/sdc互为镜像,而/dev/sdd作为日志存储使用
4、格式化分区,在逻辑卷上创建一个文件。对/dev/sdc进行破坏。
[root@node4 ~]# mkfs.ext4 /dev/vgTest/lvTest
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@node4 ~]# dd if=/dev/zero of=/dev/sdc count=10 bs=20M
记录了10+0 的读入
记录了10+0 的写出
209715200字节(210 MB)已复制,2.08666 秒,101 MB/秒
[root@node4 ~]# lvs -a -o +devices
Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert Devices
lv_root VolGroup -wi-ao---- 8.54g /dev/sda2(0)
lv_swap VolGroup -wi-ao---- 992.00m /dev/sda2(2186)
lvTest vgTest mwi-a-m-p- 1.00g lvTest_mlog 100.00 lvTest_mimage_0(0),lvTest_mimage_1(0)
[lvTest_mimage_0] vgTest iwi-aom--- 1.00g /dev/sdb(0)
[lvTest_mimage_1] vgTest iwi-aom-p- 1.00g unknown device(0)
[lvTest_mlog] vgTest lwi-aom--- 4.00m /dev/sdd(0)
[root@node4 ~]# lvscan
Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.
ACTIVE '/dev/vgTest/lvTest' [1.00 GiB] inherit
ACTIVE '/dev/VolGroup/lv_root' [8.54 GiB] inherit
ACTIVE '/dev/VolGroup/lv_swap' [992.00 MiB] inherit
[root@node4 ~]#
重新挂载逻辑卷,确认文件可以正常读取