• LVM扩容案例


    测试数据

    cd / && dd if=/dev/zero of=file bs=1M count=10000
    将磁盘变大的测试命令. 生产环境不要用. 这只是用于测试扩容后的效果
    

    LVM基础命令:

    pvdisplay 查看检查pv
    pvremove /dev/sdb    #清除一个pv
    vgremove [vg名]      #清除一个vg
    lvremove [lv名]      #清除一个lv
    
    fdisk -l  检查磁盘
    df -h     检查全部磁盘大小
    df -Th    检查磁盘大小和分区格式类型
    pvdisplay 检查pv
    vgdisplay 检查vg
    lvdisplay 检查lv
    

    0. 添加磁盘后需要进行扫描识别

    echo "- - -" > /sys/class/scsi_host/host0/scan
    echo "- - -" > /sys/class/scsi_host/host1/scan
    echo "- - -" > /sys/class/scsi_host/host2/scan
    

    1. 检查当前磁盘

    [root@localhost /]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   40G  9.6G   31G  24% /
    devtmpfs                 982M     0  982M   0% /dev
    tmpfs                    993M     0  993M   0% /dev/shm
    tmpfs                    993M  8.7M  984M   1% /run
    tmpfs                    993M     0  993M   0% /sys/fs/cgroup
    /dev/sda1                197M  103M   95M  53% /boot
    tmpfs                    199M     0  199M   0% /run/user/0
    

    注意: /dev/mapper/centos-root 是逻辑卷的路径.

    2. 检查pv [ pvdisplay ]

    [root@localhost /]# pvdisplay 
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               19.80 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              5069
      Free PE               0
      Allocated PE          5069
      PV UUID               4YLVja-jT6q-FphK-3E60-5Qde-Z3gw-zLpcYT
       
      --- Physical volume ---
      PV Name               /dev/sdb1
      VG Name               centos
      PV Size               <20.00 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              5119
      Free PE               0
      Allocated PE          5119
      PV UUID               SBfuCJ-tli0-Mi2U-wO3w-eQub-0v36-0XkQBw
    

    3. 检查vg

    [root@localhost ~]# vgdisplay 
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  2
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               19.80 GiB
      PE Size               4.00 MiB
      Total PE              5069
      Alloc PE / Size       5069 / 19.80 GiB
      Free  PE / Size       0 / 0   
      VG UUID               lkJhAi-7Df5-0K69-LYV4-exS2-ZqE1-FYMyIG
    

    4. 检查lv

    [root@localhost ~]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                tUUfhM-dDfU-Aw6K-tiAj-wyqf-cvbl-FcLOxj
      LV Write Access        read/write
      LV Creation host, time localhost.localdomain, 2019-11-22 04:12:42 +0800
      LV Status              available
      # open                 1
      LV Size                19.80 GiB
      Current LE             5069
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    

    扩容思路

    1. 加入磁盘
    2. 检查磁盘id 修改成需要扩容的磁盘ID一致,通过fdisk -l 可以查看ID
    [root@localhost ~]# fdisk -l /dev/sda
    .....
     Device   Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      411647      204800   83  Linux
    /dev/sda2          411648    41943039    20765696   8e  Linux LVM
    
    可以看到ID是 8e LVM,所以新加入的磁盘也需要改为 8e
    
    3. 创建物理卷 pv 
    4. pv加入vg卷组
    5. 扩容磁盘
    6. 格式化磁盘
    7. 结束
    

    扩容磁盘

    1. 添加磁盘

    xxx 自己意淫把

    2. 扫描新增磁盘

     扫描:
     echo "- - -" > /sys/class/scsi_host/host0/scan
     echo "- - -" > /sys/class/scsi_host/host1/scan
     echo "- - -" > /sys/class/scsi_host/host2/scan
    

    3. 分区更改磁盘格式为LVM:

    ## 创建分区并修改磁盘格式为 [8e]:
    fdisk /dev/sdc [操作新磁盘]
     
    [root@localhost /]# fdisk /dev/sdc
    	Welcome to fdisk (util-linux 2.23.2).
    	
    	Changes will remain in memory only, until you decide to write them.
    	Be careful before using the write command.
    	
    	Device does not contain a recognized partition table
    	Building a new DOS disklabel with disk identifier 0xc7dec5f2.
    	
    	Command (m for help): n    #####-----创建分区
    	Partition type:
    	p   primary (0 primary, 0 extended, 4 free)
    	e   extended
    	Select (default p): 
    	Using default response p   #####-----创建默认主分区[主分区总共就只能分出4个超过4个需要创建扩展分区]
    	Partition number (1-4, default 1): 
    	First sector (2048-62914559, default 2048): 
    	Using default value 2048
    	Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
    	Using default value 62914559
    	Partition 1 of type Linux and of size 30 GiB is set
    	
    	Command (m for help): t       #####-----更改磁盘格式 
    	Selected partition 1
    	Hex code (type L to list all codes): 8e        #####-----更改为8e
    	Changed type of partition 'Linux' to 'Linux LVM'
    	
    	
    	Command (m for help): p     ### 查看一下是不是 8e
    
    	Disk /dev/sdc: 32.2 GB, 32212254720 bytes, 62914560 sectors
    	Units = sectors of 1 * 512 = 512 bytes
    	Sector size (logical/physical): 512 bytes / 512 bytes
    	I/O size (minimum/optimal): 512 bytes / 512 bytes
    	Disk label type: dos
    	Disk identifier: 0xc7dec5f2
    	
    	Device Boot      Start         End        Blocks    Id  System
    	/dev/sdc1            2048    62914559    31456256   8e  Linux LVM    #确实已经是8e了
    
    	
    	Command (m for help): w     #####-----保存
    	The partition table has been altered!
    	
    	Calling ioctl() to re-read partition table.
    	Syncing disks.
    	
    	##分区和磁盘格式更改完毕
    

    4. 创建物理卷组:

    # 创建物理卷 pvcreate /dev/sdc1
    	[root@localhost /]# pvcreate /dev/sdc1
        Physical volume "/dev/sdc1" successfully created.
        
    # 物理卷加入刀 centos 这个 vg 中
    [root@localhost /]# vgextend centos  /dev/sdc1
      Volume group "centos" successfully extended
    

    5. 检查PE个数

     vgdisplay 
     
     [root@localhost /]# vgdisplay 
    	--- Volume group ---
    	VG Name               centos
    	System ID             
    	Format                lvm2
    	Metadata Areas        3
    	Metadata Sequence No  5
    	VG Access             read/write
    	VG Status             resizable
    	MAX LV                0
    	Cur LV                1
    	Open LV               1
    	Max PV                0
    	Cur PV                3
    	Act PV                3
    	VG Size               69.79 GiB
    	PE Size               4.00 MiB
    	Total PE              17867
    	Alloc PE / Size       10188 / <39.80 GiB
    	Free  PE / Size       7679 / <30.00 GiB         ###这是剩余PE数量, 7679,也是新增的30G磁盘,7679个PE
    	VG UUID               lkJhAi-7Df5-0K69-LYV4-exS2-ZqE1-FYMyIG
    

    6. 扩容磁盘:

     #先看目前磁盘情况:
     [root@localhost /]# df -h
     Filesystem               Size  Used Avail Use% Mounted on
     /dev/mapper/centos-root   40G  9.6G   31G  24% /          ## 31G.
     devtmpfs                 982M     0  982M   0% /dev
     tmpfs                    993M     0  993M   0% /dev/shm
     tmpfs                    993M  8.7M  984M   1% /run
     tmpfs                    993M     0  993M   0% /sys/fs/cgroup
     /dev/sda1                197M  103M   95M  53% /boot
     tmpfs                    199M     0  199M   0% /run/user/0
    
    
    # 扩容并格式化磁盘:
    lvresize -r -l +7679  /dev/centos/root
     
    #结果: 
    [root@localhost /]# lvresize -r -l +7679  /dev/centos/root
          Size of logical volume centos/root changed from <39.80 GiB (10188 extents) to 69.79 GiB (17867 extents).
          Logical volume centos/root successfully resized.
      meta-data=/dev/mapper/centos-root isize=512    agcount=9, agsize=1297664 blks
               =                       sectsz=512   attr=2, projid32bit=1
               =                       crc=1        finobt=0 spinodes=0
      data     =                       bsize=4096   blocks=10432512, imaxpct=25
               =                       sunit=0      swidth=0 blks
      naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
      log      =internal               bsize=4096   blocks=2560, version=2
               =                       sectsz=512   sunit=0 blks, lazy-count=1
      realtime =none                   extsz=4096   blocks=0, rtextents=0
      data blocks changed from 10432512 to 18295808
      
     #这是将所有PE都划分给了 /dev/centos/root , 其中 -r 是划分的同时格式化这块新磁盘,并加入到 该分区中.
     #也就是自己先格式化后扩容给/dev/centos/root 磁盘 . 
     #这种方法是按照PE个数来划分磁盘的, 磁盘总大小就是   磁盘总大小 = PE个数 * PE size
    

    7. 检查磁盘现有情况:

    # 查看现有磁盘大小:
      [root@localhost /]# df -h
      Filesystem               Size  Used Avail Use% Mounted on
      /dev/mapper/centos-root   70G  9.6G   61G  14% /        ##-----扩容成功,磁盘从 32%下降到了14 ,大小也变成了 61G
      devtmpfs                 982M     0  982M   0% /dev
      tmpfs                    993M     0  993M   0% /dev/shm
      tmpfs                    993M  8.7M  984M   1% /run
      tmpfs                    993M     0  993M   0% /sys/fs/cgroup
      /dev/sda1                197M  103M   95M  53% /boot
      tmpfs                    199M     0  199M   0% /run/user/0
      
      ## 31G+扩容给的 30G一共是 61G 全部划分正确.
    

    查看磁盘UUID:

    [root@localhost ~]# blkid 
    /dev/sda1: UUID="cb322c86-f37a-49e8-86a0-924d9b0c719e" TYPE="xfs" 
    /dev/sda2: UUID="4YLVja-jT6q-FphK-3E60-5Qde-Z3gw-zLpcYT" TYPE="LVM2_member" 
    /dev/sdb1: UUID="SBfuCJ-tli0-Mi2U-wO3w-eQub-0v36-0XkQBw" TYPE="LVM2_member" 
    /dev/sdc1: UUID="Z7K8RO-denr-cyn8-sCjb-9HMa-Pu3I-ciK3kt" TYPE="LVM2_member" 
    /dev/sr0: UUID="2017-09-06-10-51-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
    /dev/mapper/centos-root: UUID="e3508edd-30c0-4e7d-9d8f-622c8dbd174e" TYPE="xfs" 
    

    扩容完成.

    PDF文档:

    lvm01.pdf

  • 相关阅读:
    JavaScript中出现这个statement expected
    java: 非法字符: 'ufeff' 需要class, interface或enum
    码云如何配置公钥
    Git命令
    配置git签名
    Scanner练习总结
    怎么将项目在Eclipse中生成doc文档
    java文件使用命令生成doc文档
    包机制总结
    变量和运算符总结
  • 原文地址:https://www.cnblogs.com/superlinux/p/11923739.html
Copyright © 2020-2023  润新知