Linux:在线扩容

发布于:2024-04-26 ⋅ 阅读:(31) ⋅ 点赞:(0)

目录

项目场景

所需技术

操作步骤

Ⅰ:查看pv(物理卷)、vg(卷组)大小是否还够扩容

Ⅱ:vda磁盘新增分区vda3 

Ⅲ:pv(逻辑卷)扩容

Ⅳ:vg(卷组)扩容

Ⅴ:lv(逻辑卷)扩容

Ⅵ:将扩容的空间加到操作系统


项目场景

甲方给划了几台服务器,每台服务器配置是一样的。

操作系统版本:centos7.9 

一块磁盘vda,500G;两个分区vda1、vda2,vda1 1G、vda2 99G;还有400G的空间没有应用。

找甲方给扩容,但甲方说不会,你们自己搞。

正好最近在备考RHCE,所以此操作还能应付。

所需技术

Linux的lvm技术

操作步骤

Ⅰ:查看pv(物理卷)、vg(卷组)大小是否还够扩容

至于怎么判断够不够,和您需要进行扩容的lv大小进行比对即可。

pvs
vgs

我今天遇到的场景就是都不够,那么采用如下步骤。

Ⅱ:vda磁盘新增分区vda3 

分区命令如下: 

fdisk /dev/vda

分区操作如下(忽略分区大小和磁盘名称,这是在我自己虚拟机上做的,没有用项目上的服务器) 

[root@localhost ~]# fdisk /dev/sdb
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 0x379cedfb.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): P

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x379cedfb

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10485759     5241856   83  Linux

Command (m for help): w
The partition table has been altered!

上述分区操作中:

  • Command (m for help): n

 n 代表新增分区;

  • Select (default p): p”

 p 代表新增分区类型为主分区;

  • First sector (2048-10485759, default 2048):

代表新增分区的起始扇区,这里如果直接回车就是按照从默认的扇区ID 2048 开始

  • Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):

代表新增分区的结束扇区,这里如果直接回车就是按照默认的扇区ID 10485759 结束

【以上配置新增分区大小,也可以直接在起始扇区那里写  +400G,然后结束扇区直接回车即可】

  • Command (m for help): P

查看新添加的分区

  • Command (m for help): w

w 代表保存刚刚操作并退出

Ⅲ:pv(逻辑卷)扩容

pvcreate /dev/vda3

Ⅳ:vg(卷组)扩容

扩容前,先用vgs看看要扩容的卷组叫啥名。(忽略下面命令的输出卷组大小,是在我自己虚拟机上操作的,不是在项目服务器上)

[root@localhost dev]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   2   2   0 wz--n- 83.99g 1016.00m

 卷组扩容

vgextend centos /dev/vda3

Ⅴ:lv(逻辑卷)扩容

扩容前,先用lvs命令看下要扩容的lv逻辑卷叫啥名,别扩错了。

lv扩容命令 

lvextend /dev/centos/root -L 450G

上述命令中:

  • /dev/centos/root,

centos是vg卷组名称,root是要扩容的lv逻辑卷名称。

  • -L

-L 450G 参数是指定该lv逻辑卷450G大小,不是在现在基础上扩大450G;是一个最终大小值,不是一个增长大小值。

Ⅵ:将扩容的空间加到操作系统

  • 如果是xfs文件系统 
xfs_growfs /dev/centos/root
  • 如果是ext4文件系统
resize2fs /dev/centos/root

至此,扩容完成。您现在已经可以df -h看到已经扩容的lv逻辑卷了。