linux7 vg,CentOS 7 下的LVM 实战

一、背景

前段时间收到zabbix的报警信息 PROBLEM: Free disk space is less than 20% on volume /

adb9d8979bc93c1a19ecb456df38be53.png

通过df h可以得知,我们做了一个VGname为centos的LVM ,并且在/home下还有46G可用,但是centos 7的LVM 文件系统格式为xfs,而xfs文件系统只能增加VG的大小,不能减少。

通过vgdisplay查看只有16M可用的PE 。

2790c4bbd3731c00a9a9e002e4abbabf.png

因此这里为解决这个问题,我选择新增一块硬盘,通过LVM  加入VG  centos中来扩大 目录 / 的容量

二、增加硬盘

插入硬盘后可通过fdisk l来查看,这里的sdb就是我新增加的硬盘。

99fc2a8f813f4d088b117804961c46ff.png

三、LVM

具体步骤如下

1. 用 fdisk 设定新的具有 8e system ID 的 partition

2. 利用 pvcreate 建置 PV

3. 利用 vgextend 将 PV 加入VG centos

4. 利用 lvresize 将新加入的 PV 内的 PE 加入 root 中

5. 透过 xfs_growfs 将文件系统的容量确实增加

3.1用 fdisk 设定新的具有 8e system ID 的 partition

[root@zabbix-server dev]# 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 0xf93c2ab9.

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0xf93c2ab9

Device Boot      Start         End      Blocks   Id  System

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): 1

First sector (2048-104857599, default 2048):

Using default value 2048

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

Using default value 104857599

Partition 1 of type Linux and of size 50 GiB is set

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0xf93c2ab9

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048   104857599    52427776   83  Linux

Command (m for help):t

Selected partition 1

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0xf93c2ab9

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048   104857599    52427776   8e  Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@zabbix-server dev]#partprobe  不要忘记这一步

格式化 mkfs.xfs /dev/sdb1

3cc0c32c20cda7366a2a86a5a174e9fb.png

3.2利用 pvcreate 建置 PV

[root@zabbix-server dev]#pvcreate  /dev/sdb1

3.3利用 vgextend 将 PV 加入VG  centos

[root@zabbix-server dev]#vgextend  centos /dev/sdb1

3.4利用 lvresize 将新加入的 PV 内的 PE 加入 root 中

[root@zabbix-server dev]# lvextend -L +50G /dev/centos/root

3.5透过 xfs_growfs 将文件系统的容量确实增加

[root@zabbix-server dev]#xfs_growfs  /dev/mapper/centos-root

3c9591187f35fe23a6667b45d90c8f5e.png

3.6通过dh –hT来验证结果

10d4e1a5c55202bae3d83d2b722315be.png

配置完成后过一会儿就收到了报警正常的邮件。

79df585c5a756f594266e8beca9ec43c.png

谢谢你打开这篇博文,并一直坚持看到了这里,如果觉得对你有帮助,请不要吝啬点一下右下角的赞。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值