天天看点

centos 企业级对 /home 目录进行弹性扩容(不重启)

需求:线上的机器 /home 目录内存不足,需要扩容内存维持服务的正常运行
centos 企业级对 /home 目录进行弹性扩容(不重启)

一、查看服务器上的内存情况和配置分区

1.查看磁盘信息情况 /home 目录类型为 lvm 逻辑卷

[[email protected] ~]# lsblk
NAME                    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   1.9T  0 disk 
├─sda1                    8:1    0     1G  0 part /boot
└─sda2                    8:2    0   1.9T  0 part     #sda2为逻辑卷
  ├─centos_gdi2154-root 253:0    0    50G  0 lvm  /
  ├─centos_gdi2154-swap 253:1    0  15.7G  0 lvm  [SWAP]
  └─centos_gdi2154-home 253:2    0   1.8T  0 lvm  /home
sdb                       8:16   0 931.5G  0 disk     #空闲的磁盘
sdc                       8:32   0 931.5G  0 disk     #空闲的磁盘
           

2.给新的磁盘 sdb,sdc 进行分区

[[email protected] ~]# fdisk /dev/sdb
选 n 创建分区 -> 回车默认分配全部内存 -> w 保存退出(sdc同样操作)
这里如果提示繁忙,无法读取新分区信息。可以使用 partprobe 命令重新读取分区表

[[email protected] ~]# lsblk 
NAME                    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   1.9T  0 disk 
├─sda1                    8:1    0     1G  0 part /boot
└─sda2                    8:2    0   1.9T  0 part 
  ├─centos_gdi2154-root 253:0    0    50G  0 lvm  /
  ├─centos_gdi2154-swap 253:1    0  15.7G  0 lvm  [SWAP]
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home
sdb                       8:16   0 931.5G  0 disk 
└─sdb1                    8:17   0 931.5G  0 part 
sdc                       8:32   0 931.5G  0 disk 
└─sdc1                    8:33   0 931.5G  0 part 
           

二、对 /home 目录进行扩容

1.将 sdb1 和 sdc1 创建为 PV 卷

[[email protected] ~]# pvcreate /dev/sdb1
[[email protected] ~]# pvcreate /dev/sdc1
           

2.查看 VG 逻辑卷组

[[email protected] ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos_gdi2154    #逻辑卷名
    ......
           

3.将 sdb1 和 sdc1 加入到逻辑卷 centos_gdi2154 组中

[[email protected] ~]# vgextend centos_gdi2154 /dev/sdb1
[[email protected] ~]# vgextend centos_gdi2154 /dev/sdc1
           

4.查看扩容后 VG 卷的大小

[[email protected] ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos_gdi2154
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               3.68 TiB    #扩容后由 1.8T 提升为 3.7T
  PE Size               4.00 MiB
  Total PE              965054
  Alloc PE / Size       965054 / 3.68 TiB
  Free  PE / Size       0 / 0   
  VG UUID               zEsTP2-8I61-FaU4-xMiI-ZpyL-x5Wv-ECcJhI
           

5.查看 LV 逻辑卷名称对其进行全部分配

[[email protected] ~]# lvdisplay /dev/centos_gdi2154/home
  --- Logical volume ---
  LV Path                /dev/centos_gdi2154/home  #LV卷名称
  LV Name                home
  VG Name                centos_gdi2154
    ......
[[email protected] ~]# lvextend -l +100%FREE /dev/centos_gdi2154/home #将剩余空间都添加到逻辑卷中
           

三、对逻辑卷扩容后,同步到文件系统,实现真正的对目录的扩容

[[email protected] ~]# xfs_growfs /dev/centos_gdi2154/home (centos6中 用resize2fs /dev/centos_gdi2154/home)

xfs_growfs 命令同步前
[[email protected] ~]# df -h
        ......
/dev/mapper/centos_gdi2154-home  1.8T  1.7T  187G  90% /home
    ......
    
xfs_growfs 命令同步后
[[email protected] ~]# df -h
    ......
/dev/mapper/centos_gdi2154-home  3.7T  1.7T  2.0T  45% /home
    ......
    
查看分区的状态
[[email protected] ~]# lsblk 
NAME                    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   1.9T  0 disk 
├─sda1                    8:1    0     1G  0 part /boot
└─sda2                    8:2    0   1.9T  0 part 
  ├─centos_gdi2154-root 253:0    0    50G  0 lvm  /
  ├─centos_gdi2154-swap 253:1    0  15.7G  0 lvm  [SWAP]
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home
sdb                       8:16   0 931.5G  0 disk 
└─sdb1                    8:17   0 931.5G  0 part 
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home`在这里插入代码片`
sdc                       8:32   0 931.5G  0 disk 
└─sdc1                    8:33   0 931.5G  0 part 
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home
           

到此,扩容完成

注:3.中lvextend -l +100%FREE 后面也可以直接跟文件系统
例如:“lvextend -l +100%FREE /dev/mapper/centos_gdi2154-home”
或者:“lvextend -l +100%FREE /dev/centos_gdi2154/home”
后面用 xfs_growfs /dev/mapper/centos-root 命令同步
           

继续阅读