前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布

lvm

作者头像
若与
发布2018-04-25 12:26:53
1.7K0
发布2018-04-25 12:26:53
举报
文章被收录于专栏:友弟技术工作室

逻辑卷管理LVM是一个多才多艺的硬盘系统工具。无论在Linux或者其他类似的系统,都是非常的好用。传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。可以让管理员弹性的管理逻辑卷的扩大缩小,操作简单,而不损坏已存储的数据。可以随意将新的硬盘添加到LVM,以直接扩展已经存在的逻辑卷。LVM并不需要重启就可以让内核知道分区的存在。

lvm架构

概念

DM:Device Mapper 逻辑设备 MD:multip Device /dev/md# meta device

linux系统一切皆文件,所有的设备都映射成文件在 /dev/目录下。

DM:逻辑设备 lvm2

DM:LVM2

代码语言:javascript
复制
   快照
   lincar
   mirror
   多路径(线路管理)实现数据的寻路多路径。
   动态增减(逻辑设备)


   多个物理磁盘组织成一个逻辑设备,可以中间增添。
   物理设备  --->  物理卷  physical volume PV
                  卷组    volume Group   VG(取决于物理设备)
                  逻辑卷     logical volume  LV 
                  逻辑卷可以有多个,可以动态增减。(逻辑卷之和不能超过物理容量)
物理边界,逻辑边界(文件系统边界)
逻辑卷相当于文件系统,对逻辑卷创建快照。快照卷必须和逻辑卷在同一个卷组。要预留空间。
快照:
代码语言:javascript
复制
访问同一数据的另一个路径(如软链接)(小于原数据)
恢复原来的数据,快照区是有数据备份的(发生修改的数据)
实现数据备份:线上的数据
RAID 1 RAID5 已经备份(硬件上备份防止硬件的损坏)
代码语言:javascript
复制
   数据访问  --->进程  磁盘  数据在线数据实时(备份耗时)
   快照瞬间完成
   zfs
chunk 和pe相同
  • PE:physical extend 物理盘区 加入卷组之后才有PE的概念,pe大小由卷组决定。 逻辑存储单元
  • 逻辑卷:LE :logiacal Extend 逻辑盘区(角度不同) 扩展空间边界:增加pe 减小空间边界:减少pe 逻辑卷也可以创建成镜像的形式。
包含逻辑关系
代码语言:javascript
复制
pv ---> vg ---> lv 
pv即可以示磁盘,分区,raid
创建,删除,查看
  • pv
代码语言:javascript
复制
   pvcreate,pvremove(删除数据),pvscan,pvdisplay,pvmove(磁盘上数据移动到其他磁盘上)
   pvs:pvdisplay 
   linux lvm :8e 
   pvmove - move physical extents
  • vg
代码语言:javascript
复制
   vgcreate,vgremove,vgextend,vgreduce  
      vgdisplay,vgscan
      vgcreate -s   
      vgcreatee vg_name  /path/to/pv 
     删除vg  
        vgremove  
        
 vgremove - remove a volume group
 vgreduce  
 vgreduce - reduce a volume group
    pvmove /dev/sdb1
    vgreduce myvg  /dev/sdb1 
    pvremove /dev/sdb1 
    
    vgextend - add physical volumes to a volume group
  • lv
代码语言:javascript
复制
    lvcreate,lvremove,lvextend,lvreduce,lvs,lvdisplay
    创建lv
      lvcreate -n lv_name -L size#G  VG_name
      lvcreate -l 50M -n testlv myvg 
      lvs 
      lvdisplay  
      lvremove 
操作过程
代码语言:javascript
复制
 创建10G的vg
  fdisk 只能创建15个 
 partprobe  
 cat /proc/partions
 pvcreate   /dev/sda{1,2}
 pvs
 pvdisplay 详细显示
 pvdisplay  /dev/sda1
 pvscan  扫描系统上所有的pv
 
 vgcreate  
 vgcreate  myvg /dev/sda{1,2}
  vgs 
  pvdisplay  /dev/sda10 
  
   pvcreate /dev/sdb2
   vgextend myvg /dev/sda2 

   
   创建lv 
     lv 
创建分区:是创建物理边界

文件系统:逻辑边界 lvm:先扩展物理边界,在扩展逻辑边界。 先缩减逻辑边界,再缩减物理边界。

一、扩展逻辑卷
代码语言:javascript
复制
扩展物理边界:
lvextend
      -L [+]# /path/to/lv   扩展到或扩展了。。。 
扩展逻辑边界:
resize2fs   /path/to/lv   大小    设备扩展到多大
resize2fs -p /path/to/lv 

lvcreate -L 2G -n testlv mylv 
mke2fs -j /dev/myvg/testlv 
mkdir /users
mount /dev/myvg/testlv /users
df -lh

lvextend -L 5G /dev/myvg/testlv 
df -lh
resize2fs -p /dev/myvg/testlv
df -lh
二、缩减逻辑卷

先缩减逻辑边界,再缩减物理边界。

代码语言:javascript
复制
   注意:1.不能在线缩减,得先卸载。
          2.确保缩减后的空间大小依然能存储原有的所有数据。
          3.在缩减前应该强行检查文件,以确保文件系统处于一致性状态。
resize2fs 
   ressize2fs /path/to/lv  #G 
lvreduce  -L [-]#  /path/to/lv 

重新挂载。
df -lh 
umount /users 
e2fsck -f /dev/myvg/testlv
resize2fs /dev/myvg/testlv 3G
lvreduce -L 3G /dev/myvg/testlv
mount /dev/myvg/testlv /user
三、快照卷

1.快照卷的生命周期为整个数据时长,在这段时长内,数据的增长量不能超出快照卷大小。 2.快照卷应该为只读。 3.和原卷在同一卷组内。

代码语言:javascript
复制
lvcreate 
   -s 
   -p  r|w
   lvcreate -L # 
lvcreate  -L # -n slv_name -p r /path/to/slv 
lvcreate -L 50M -n testlv-snap -s -p r /dev/myvg/testlv 
lvs 
mount /dev/myvg/testlv-snap  /snap 
cd /snap 
ls
cd /users 


tar -jcf /tmp/users.tar.bz2 /users/inittab
umount /snap 
lvremove /dev/myvg/testlv-snap 
完全备份,增量备份
tar xf /tmp/users.tar.bz2 -C /users 
lvm的配置文件
代码语言:javascript
复制
 ubuntu@youdi > /etc/lvm > vim /etc/lvm/lvm.conf 
lvm相关命令
代码语言:javascript
复制
COMMANDS
       The following commands implement the core LVM functionality.

       pvchange      Change attributes of a Physical Volume.
       pvck          Check Physical Volume metadata.
       pvcreate      Initialize a disk or partition for use by LVM.
       pvdisplay     Display attributes of a Physical Volume.
       pvmove        Move Physical Extents.
       pvremove      Remove a Physical Volume.                                                                                                                                                                    
       pvresize      Resize a disk or partition in use by LVM2.                                                                                                                                                   
       pvs           Report information about Physical Volumes.                                                                                                                                                   
       pvscan        Scan all disks for Physical Volumes.                                                                                                                                                         
       vgcfgbackup   Backup Volume Group descriptor area.                                                                                                                                                         
       vgcfgrestore  Restore Volume Group descriptor area.                                                                                                                                                        
       vgchange      Change attributes of a Volume Group.                                                                                                                                                         
       vgck          Check Volume Group metadata.                                                                                                                                                                 
       vgconvert     Convert Volume Group metadata format.                                                                                                                                                        
       vgcreate      Create a Volume Group.                                                                                                                                                                       
       vgdisplay     Display attributes of Volume Groups.                                                                                                                                                         
       vgexport      Make volume Groups unknown to the system.                                                                                                                                                    
       vgextend      Add Physical Volumes to a Volume Group.                                                                                                                                                      
       vgimport      Make exported Volume Groups known to the system.                                                                                                                                             
       vgimportclone Import and rename duplicated Volume Group (e.g. a hardware snapshot).                                                                                                                        
       vgmerge       Merge two Volume Groups.                                                                                                                                                                     
       vgmknodes     Recreate Volume Group directory and Logical Volume special files                                                                                                                             
       vgreduce      Reduce a Volume Group by removing one or more Physical Volumes.                                                                                                                              
       vgremove      Remove a Volume Group.                                                                                                                                                                       
       vgrename      Rename a Volume Group.                                                                                                                                                                       
       vgs           Report information about Volume Groups.                                                                                                                                                      
       vgscan        Scan all disks for Volume Groups and rebuild caches.                                                                                                                                         
       vgsplit       Split a Volume Group into two, moving any logical volumes from one Volume Group to another by moving entire Physical Volumes.                                                                
       lvchange      Change attributes of a Logical Volume.                                                                                                                                                       
       lvconvert     Convert a Logical Volume from linear to mirror or snapshot.                                                                                                                                  
       lvcreate      Create a Logical Volume in an existing Volume Group.                                                                                                                                         
       lvdisplay     Display attributes of a Logical Volume.                                                                                                                                                      
       lvextend      Extend the size of a Logical Volume.                                                                                                                                                         
       lvmchange     Change attributes of the Logical Volume Manager.                                                                                                                                             
       lvmconfig     Display the configuration information after loading lvm.conf(5) and any other configuration files.                                                                                           
       lvmdiskscan   Scan for all devices visible to LVM2.                                                                                                                                                        
       lvmdump       Create lvm2 information dumps for diagnostic purposes.                                                                                                                                       
       lvreduce      Reduce the size of a Logical Volume.                                                                                                                                                         
       lvremove      Remove a Logical Volume.                                                                                                                                                                     
       lvrename      Rename a Logical Volume.                                                                                                                                                                     
       lvresize      Resize a Logical Volume.                                                                                                                                                                     
       lvs           Report information about Logical Volumes.                                                                                                                                                    
       lvscan        Scan (all disks) for Logical Volumes.    
查看帮助使用 man
代码语言:javascript
复制
man lvm
man vgscan
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017.09.16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 概念
  • 快照:
  • chunk 和pe相同
  • 包含逻辑关系
  • 创建,删除,查看
  • 操作过程
  • 创建分区:是创建物理边界
    • 一、扩展逻辑卷
    • 二、缩减逻辑卷
      • 三、快照卷
      • lvm的配置文件
      • lvm相关命令
      • 查看帮助使用 man
      相关产品与服务
      对象存储
      对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档