您的位置:首页 > 其它

LVM逻辑卷(PV.VG.LV)/扩容/缩容/快照

2014-04-22 10:10 471 查看
逻辑卷LVM
1. 在线(on-line)扩容,离线(off-line)缩小
2. 快照snapshot
参考文档:
========================================================
创建          扫描      显示详细        显示      扩展              缩小              删除                  更改
pvcreate    pvscan  pvdisplay       pvs                                             pvremove
vgcreate    vgscan  vgdisplay       vgs         vgextend                        vgremove        vgchange
lvcreate    lvscan  lvdisplay       lvs     lvextend        lvreduce        lvremove        lvchange
========================================================
一、创建逻辑卷
1. 创建物理卷PV(整个硬盘,不需要分区)
[root@dns ~]# pvcreate /dev/sdc
2. 创建卷组VG
[root@dns ~]# vgcreate vg02 /dev/sdc
3. 创建逻辑卷LV
[root@dns ~]# lvcreate -L 400M -n lv02 vg02
[root@dns ~]# lvcreate -l 200 -n lv03 vg02
[root@dns ~]# lvscan
ACTIVE            '/dev/vg02/lv02' [400.00 MB] inherit
4. 创建文件系统并挂载
[root@dns ~]# mkfs.ext4 /dev/vg02/lv02
[root@dns ~]# vim /etc/fstab
/dev/vg02/lv02          /mnt/lv02               ext4    defaults        0 0
[root@dns ~]# mkdir /mnt/lv02 /mnt/lv03
[root@dns ~]# mount -a
[root@dns ~]# df
文件系统               1K-块        已用     可用 已用% 挂载点
/dev/mapper/vg02-lv02
396672     10544    365648   3% /mnt/lv02
/dev/mapper/vg02-lv03
806288     17216    748112   3% /mnt/lv03
二、扩展逻辑卷
第一种情况:lv所在的卷组还有足够用于扩展的空间
[root@dns ~]# lvs
LV      VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
lv02    vg02 -wi-ao 400.00M
lv03    vg02 -wi-ao 800.00M
[root@dns ~]# vgs
VG   #PV #LV #SN Attr   VSize   VFree
vg02   1   2   0 wz--n- 100.00G 98.82G
[root@dns ~]# lvextend -L 1G /dev/vg02/lv02         //扩展逻辑卷
[root@dns ~]# lvscan
ACTIVE            '/dev/vg02/lv02' [1.00 GB] inherit
ACTIVE            '/dev/vg02/lv03' [800.00 MB] inherit
[root@dns ~]# resize2fs /dev/vg02/lv02              //扩文件系统
[root@dns ~]# df -h
第二种情况:lv所在的卷组没有足够的空间
[root@dns ~]# vgs
VG   #PV #LV #SN Attr   VSize   VFree
vg01   1   4   0 wz--n-   9.97G     0
vg02   1   2   0 wz--n- 100.00G 98.21G
[root@dns ~]# pvcreate /dev/sdd
[root@dns ~]# vgextend vg02 /dev/sdd
[root@dns ~]# lvextend -L 100T /dev/vg02/lv02   //扩展逻辑卷
[root@dns ~]# resize2fs /dev/vg02/lv02              //扩文件系统
========================================================
扩展知识:
PV也可以是一个分区:
[root@dns ~]# fdisk -cul /dev/sdd
[root@dns ~]# partx -a /dev/sdd
[root@dns ~]# pvcreate /dev/sdd1
[root@dns ~]# vgextend vg02 /dev/sdd1
[root@dns ~]# vgs
VG   #PV #LV #SN Attr   VSize   VFree
vg01   1   4   0 wz--n-   9.97G      0
vg02   2   2   0 wz--n- 101.82G 100.04G

PE:创建VG时,指定PE的size(默认为4M)
[root@dns ~]# pvcreate /dev/sdc
[root@dns ~]# vgcreate -s 128M datastorage /dev/sdc
[root@dns ~]# vgdisplay datastorage
PE Size                   128.00 MB
Total PE                  799
Alloc PE / Size           0 / 0
Free  PE / Size           799 / 99.88 GB
[root@dns ~]# lvcreate -l 799 -n database datastorage
[root@dns ~]# mkfs.ext4 /dev/datastorage/database
[root@dns ~]# mkdir /mnt/lv
[root@dns ~]# vim /etc/fstab
/dev/datastorage/database /mnt/lv               ext3    defaults 0 0
[root@dns ~]# mount -a
[root@dns ~]# df
删除LV,VG:
1. 停止应用程序对该相应文件系统的访问
2. 卸载文件系统,包括/etc/fstab
3. lvremove
4. vgremove
5. pvremove
激活VG/LV:
[root@dns ~]# lvchange -an /dev/vg01/lv01
[root@dns ~]# lvscan
inactive          '/dev/vg01/lv01' [128.00 MiB] inherit
ACTIVE            '/dev/vg01/lv02' [128.00 MiB] inherit
ACTIVE            '/dev/vg01/lv03' [128.00 MiB] inherit
[root@dns ~]# vgchange -an vg01
0 logical volume(s) in volume group "vg01" now active
[root@dns ~]# lvscan
inactive          '/dev/vg01/lv01' [128.00 MiB] inherit
inactive          '/dev/vg01/lv02' [128.00 MiB] inherit
inactive          '/dev/vg01/lv03' [128.00 MiB] inherit
[root@dns ~]# vgchange -ay vg01
[root@dns ~]# lvscan
ACTIVE            '/dev/vg01/lv01' [128.00 MiB] inherit
ACTIVE            '/dev/vg01/lv02' [128.00 MiB] inherit
ACTIVE            '/dev/vg01/lv03' [128.00 MiB] inherit

缩小逻辑卷: off-line
1. 停止应用
2. 备份数据
3. 卸载文件系统
4. 检查文件系统e2fsck
5. 缩小文件系统
6. 缩小逻辑卷
[root@dns ~]# umount /mnt/lv04/
[root@dns ~]# e2fsck -f /dev/vg01/lv04
[root@dns ~]# resize2fs /dev/vg01/lv04 1000M
[root@dns ~]# lvreduce /dev/vg01/lv04 -L 1000M
[root@dns ~]# mount -a
========================================================
三、逻辑卷快照snapshot
作用:
1. 利用快照实现一致性备份
实现快照
[root@dns ~]# lvscan
ACTIVE            '/dev/vg01/lv06' [20.00 GiB] inherit
[root@dns ~]# lvs
LV     VG   Attr               LSize    Pool Origin Data%  Move Log Cpy%Sync Convert
lv06   vg01 -wi-ao---   20.00g
# df -ThP /mnt/lv06
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv06 ext4   20G  287M   19G   2% /mnt/lv06
[root@dns ~]# lvcreate -L 50M -s -n lv06-snap /dev/vg01/lv06
[root@dns ~]# lvs
LV                VG          Attr            LSize       Pool Origin Data%  Move Log Cpy%Sync Convert
lv06              vg01    owi-aos--       20.00g
lv06-snap     vg01    swi-a-s--       52.00m              lv06    0.02
[root@dns ~]# mkdir /mnt/lv06-snap
[root@dns ~]# mount /dev/vg01/lv06-snap /mnt/lv06-snap
[root@dns ~]# ls /mnt/lv06
etc1  etc2  etc3  lost+found
[root@dns ~]# ls /mnt/lv06-snap/
etc1  etc2  etc3  lost+found
[root@dns ~]# rm -rf /mnt/lv06/etc1
[root@dns ~]# ls /mnt/lv06
etc2  etc3  lost+found
[root@dns ~]# ls /mnt/lv06-snap/
etc1  etc2  etc3  lost+found
快照的自动增长:
[root@dns ~]# vim /etc/lvm/lvm.conf
snapshot_autoextend_threshold = 70
snapshot_autoextend_percent = 50
[root@dns ~]# /etc/init.d/lvm2-monitor start
[root@dns ~]# chkconfig lvm2-monitor on


本文出自 “linux” 博客,请务必保留此出处http://jpkingofkings.blog.51cto.com/4342950/1400097
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: