LVM扩容案例

LVM基础命令:

pvdisplay 查看检查pv
pvremove /dev/sdb    #清除一个pv

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@plat-ecloud01-andfleethe-prd-kafka02 ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/vda1                   20G  5.8G   13G  32% /
devtmpfs                    32G     0   32G   0% /dev
tmpfs                       32G     0   32G   0% /dev/shm
tmpfs                       32G  620K   32G   1% /run
tmpfs                       32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/datavg-lv_opt  180G   96G   85G  54% /opt
tmpfs                      6.3G     0  6.3G   0% /run/user/1001
tmpfs                      6.3G     0  6.3G   0% /run/user/10000

注意: /dev/mapper/datavg-lv_opt 是逻辑卷的路径.

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

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.

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
    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% /
 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

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

扩容完成.

相关文档:
https://chenleilei.net/fujian/lvm01.pdf

参考连接:https://chenleilei.net/article/87.html

猜你喜欢

转载自www.cnblogs.com/superlinux/p/11923739.html
今日推荐