码迷,mamicode.com
首页 > 其他好文 > 详细

lvm与raid的配置使用

时间:2019-01-12 19:58:37      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:信息   remove   cto   run   lvcreate   sha   resize   虚拟   ica   

  • lvs
  • raid

  • lvm: logical volumes manager,从物理设备创建虚拟块设备,将一个或多个底层块设备组织成一个逻辑设备的模块,能够更好的管理磁盘,通过对底层的封装,对磁盘进行动态管理。
    技术分享图片
    基本概念:
    pv :physical volume物理卷处于最底层
    vg :volume group卷组,建立在物理卷之上,最小单位为pe
    lv :logical volume 逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间

    管理使用:

    pv管理工具 vg管理工具 lv管理工具
    pvs:简要显示PV信息 vgs :显示vg简要信息 lvs :显示lv简要信息
    pvdisplay:显示详细信息 vgdisplay 显示详细信息 lvdisplay 显示详细信息
    pvcreate /dev/device... :创建PV vgcreate [-s #[kKmMgGtTpPeE]] VG_Name /dev/device...]#创建vg,-s指明pe大小,默认4m lvcreate -L #[mMgGtT] -n NAME VolumeGroup #-l 指明pe多少个 ,-L lv大小
    pvremove /dev/device...删除PV vgextend VG_Name /dev/device... #扩容vg lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME: lv扩容后还需要修改逻辑大小:resizefs /dev/VG_NAME/LV_NAME
    pvmove /dev/device /dev/device:数据迁移 vgreduce VG_Name /dev/device... #缩容 缩减逻辑卷看缩减步骤
    vgremove vg_name删除卷组 :注收缩需先迁移数据 lvremove /dev/VG_NAME/LV_NAME #删除逻辑卷

    lv缩减步骤:

    # umount /dev/VG_NAME/LV_NAME#先卸载,xfs可以不用卸载
    # e2fsck -f /dev/VG_NAME/LV_NAME #强制检测文件系统
    # resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT] #执行缩减操作
    # lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME #缩减lv
    # mount

    简单实践:

    [root@xt ~]# pvcreate /dev/sdb{1,2}
      Physical volume "/dev/sdb1" successfully created.
      Physical volume "/dev/sdb2" successfully created.
    [root@xt ~]# pvs
      PV         VG Fmt  Attr PSize PFree
      /dev/sdb1     lvm2 ---  1.00g 1.00g
      /dev/sdb2     lvm2 ---  1.00g 1.00g
    [root@xt ~]# pvdisplay 
      "/dev/sdb2" is a new physical volume of "1.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb2
      VG Name               
      PV Size               1.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               3XTOcT-uIc3-73Hc-alkn-EKWJ-yyqv-CZYDsR
    
      "/dev/sdb1" is a new physical volume of "1.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb1
      VG Name               
      PV Size               1.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               KZ6Mwf-GPQc-xGQf-xWwS-FCnS-yLtn-XqJofh
    = ================================================== 
    [root@xt ~]# vgcreate myvg /dev/sdb1
      Volume group "myvg" successfully created
    [root@xt ~]# vgs
      VG   #PV #LV #SN Attr   VSize    VFree   
      myvg   1   0   0 wz--n- 1020.00m 1020.00m
    [root@xt ~]# vgextend myvg /dev/sdb2
      Volume group "myvg" successfully extended
    [root@xt ~]# vgs
      VG   #PV #LV #SN Attr   VSize VFree
      myvg   2   0   0 wz--n- 1.99g 1.99g
    [root@xt ~]# vgdisplay 
      --- Volume group ---
      VG Name               myvg
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  2
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                0
      Open LV               0
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               1.99 GiB
      PE Size               4.00 MiB
      Total PE              510
      Alloc PE / Size       0 / 0   
      Free  PE / Size       510 / 1.99 GiB
      VG UUID               b5t7N7-xMBg-5O8w-xS5m-2OTV-IpBd-98mR5w
    ===================================================
    [root@xt ~]# lvcreate -L 200m --name mylv myvg 
      Logical volume "mylv" created.
    [root@xt ~]# lvs
      LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      mylv myvg -wi-a----- 200.00m                                                    
    [root@xt ~]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/myvg/mylv
      LV Name                mylv
      VG Name                myvg
      LV UUID                PelWrs-D13Q-8btE-q0RV-tFsA-6miC-FTqwns
      LV Write Access        read/write
      LV Creation host, time xt.com, 2019-01-11 22:24:56 +0800
      LV Status              available
      # open                 0
      LV Size                200.00 MiB
      Current LE             50
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    =================================================
    [root@xt ~]# mkfs.ext4 /dev/myvg/mylv 
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=1024 (log=0)
    Fragment size=1024 (log=0)
    Stride=0 blocks, Stripe width=0 blocks
    51200 inodes, 204800 blocks
    10240 blocks (5.00%) reserved for the super user
    First data block=1
    Maximum filesystem blocks=33816576
    25 block groups
    8192 blocks per group, 8192 fragments per group
    2048 inodes per group
    Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done 
    
    [root@xt ~]# mount /dev/myvg/mylv /mnt
    [root@xt ~]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/sda1               10G  4.0G  6.1G  40% /
    devtmpfs               984M     0  984M   0% /dev
    tmpfs                  993M     0  993M   0% /dev/shm
    tmpfs                  993M  8.7M  985M   1% /run
    tmpfs                  993M     0  993M   0% /sys/fs/cgroup
    /dev/sda3              256M   83M  173M  33% /boot
    tmpfs                  199M     0  199M   0% /run/user/0
    /dev/mapper/myvg-mylv  190M  1.6M  175M   1% /mnt
    ==========================================
    模拟数据迁移:需要同一个vg
    [root@xt mnt]# mount /dev/myvg/mylv /mnt
    [root@xt mnt]# cp -r /tmp/ /mnt/
    [root@xt tmp]# pvs
      PV         VG   Fmt  Attr PSize    PFree    
      /dev/sdb1  myvg lvm2 a--  1020.00m  820.00m #数据主要在sdb1,迁移到目标的容量要比现有大
      /dev/sdb2  myvg lvm2 a--  1020.00m 1020.00m
    [root@xt tmp]# pvmove /dev/sdb1 /dev/sdb2
      /dev/sdb1: Moved: 4.00%
      /dev/sdb1: Moved: 100.00%
    [root@xt tmp]# pvs
      PV         VG   Fmt  Attr PSize    PFree   
      /dev/sdb1  myvg lvm2 a--  1020.00m 1020.00m
      /dev/sdb2  myvg lvm2 a--  1020.00m  820.00m
    [root@xt tmp]# vgreduce myvg  /dev/sdb1
      Removed "/dev/sdb1" from volume group "myvg"
    [root@xt tmp]# pvs
      PV         VG   Fmt  Attr PSize    PFree  
      /dev/sdb1       lvm2 ---     1.00g   1.00g
      /dev/sdb2  myvg lvm2 a--  1020.00m 820.00m
    [root@xt tmp]# vgs
      VG   #PV #LV #SN Attr   VSize    VFree  
      myvg   1   1   0 wz--n- 1020.00m 820.00m

    lvm与raid的配置使用

    标签:信息   remove   cto   run   lvcreate   sha   resize   虚拟   ica   

    原文地址:http://blog.51cto.com/12580678/2341848

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!