一、背景@H_502_2@
前段时间收到zabbix的报警信息 PROBLEM: Free disk space is less than 20% on volume /@H_502_2@
通过df h可以得知,我们做了一个VGname为centos的LVM,并且在/home下还有46G可用,但是centos 7的LVM 文件系统格式为xfs,而xfs文件系统只能增加VG的大小,不能减少。@H_502_2@
通过vgdisplay查看只有16M可用的PE 。@H_502_2@
因此这里为解决这个问题,我选择新增一块硬盘,通过LVM 加入VG centos中来扩大 目录 / 的容量@H_502_2@
插入硬盘后可通过fdisk l来查看,这里的sdb就是我新增加的硬盘。@H_502_2@
三、LVM@H_502_2@
具体步骤如下@H_502_2@
1. 用 fdisk 设定新的具有 8e system ID 的 partition@H_502_2@
2. 利用 pvcreate 建置 PV@H_502_2@
3. 利用 vgextend 将 PV 加入VG centos@H_502_2@
4. 利用 lvresize 将新加入的 PV 内的 PE 加入 root 中@H_502_2@
5. 透过 xfs_growfs 将文件系统的容量确实增加@H_502_2@
3.1用 fdisk 设定新的具有 8e system ID 的 partition@H_502_2@
[root@zabbix-server dev]# fdisk /dev/sdb@H_502_2@@H_502_2@
Welcome to fdisk (util-linux 2.23.2).@H_502_2@
Changes will remain in memory only,until you decide to write them.@H_502_2@
Be careful before using the write command.@H_502_2@
Device does not contain a recognized partition table@H_502_2@
Building a new DOS disklabel with disk identifier 0xf93c2ab9.@H_502_2@
Command (m for help): p@H_502_2@@H_502_2@
Disk /dev/sdb: 53.7 GB,53687091200 bytes,104857600 sectors@H_502_2@
Units = sectors of 1 * 512 = 512 bytes@H_502_2@
Sector size (logical/physical): 512 bytes / 512 bytes@H_502_2@
I/O size (minimum/optimal): 512 bytes / 512 bytes@H_502_2@
Disk label type: dos@H_502_2@
Disk identifier: 0xf93c2ab9@H_502_2@
Device Boot Start End Blocks Id System@H_502_2@
Command (m for help): n@H_502_2@@H_502_2@
Partition type:@H_502_2@
p primary (0 primary,0 extended,4 free)@H_502_2@
e extended@H_502_2@
Select (default p): p@H_502_2@@H_502_2@
Partition number (1-4,default 1): 1@H_502_2@@H_502_2@
First sector (2048-104857599,default 2048): @H_502_2@
Using default value 2048@H_502_2@
Last sector,+sectors or +size{K,M,G} (2048-104857599,default 104857599): @H_502_2@
Using default value 104857599@H_502_2@
Partition 1 of type Linux and of size 50 GiB is set@H_502_2@
Command (m for help): p@H_502_2@@H_502_2@
Disk /dev/sdb: 53.7 GB,104857600 sectors@H_502_2@
Units = sectors of 1 * 512 = 512 bytes@H_502_2@
Sector size (logical/physical): 512 bytes / 512 bytes@H_502_2@
I/O size (minimum/optimal): 512 bytes / 512 bytes@H_502_2@
Disk label type: dos@H_502_2@
Disk identifier: 0xf93c2ab9@H_502_2@
Device Boot Start End Blocks Id System@H_502_2@
/dev/sdb1 2048 104857599 52427776 83 Linux@H_502_2@
Command (m for help): t@H_502_2@@H_502_2@
Selected partition 1@H_502_2@
Hex code (type L to list all codes): 8e@H_502_2@@H_502_2@
Changed type of partition 'Linux' to 'Linux LVM'@H_502_2@
Command (m for help): p@H_502_2@
Disk /dev/sdb: 53.7 GB,104857600 sectors@H_502_2@
Units = sectors of 1 * 512 = 512 bytes@H_502_2@
Sector size (logical/physical): 512 bytes / 512 bytes@H_502_2@
I/O size (minimum/optimal): 512 bytes / 512 bytes@H_502_2@
Disk label type: dos@H_502_2@
Disk identifier: 0xf93c2ab9@H_502_2@
Device Boot Start End Blocks Id System@H_502_2@
/dev/sdb1 2048 104857599 52427776 8e Linux LVM@H_502_2@
Command (m for help): w@H_502_2@@H_502_2@
The partition table has been altered!@H_502_2@
Calling ioctl() to re-read partition table.@H_502_2@
Syncing disks.@H_502_2@
[root@zabbix-server dev]#partprobe 不要忘记这一步@H_502_2@
格式化 mkfs.xfs /dev/sdb1@H_502_2@
3.2利用 pvcreate 建置 PV@H_502_2@
[root@zabbix-server dev]#pvcreate /dev/sdb1@H_502_2@
3.3利用 vgextend 将 PV 加入VG centos@H_502_2@
[root@zabbix-server dev]#vgextend centos /dev/sdb1@H_502_2@
3.4利用 lvresize 将新加入的 PV 内的 PE 加入 root 中@H_502_2@
[root@zabbix-server dev]# lvextend -L +50G /dev/centos/root@H_502_2@
3.5透过 xfs_growfs 将文件系统的容量确实增加@H_502_2@
[root@zabbix-server dev]#xfs_growfs /dev/mapper/centos-root@H_502_2@
3.6@H_502_2@通过dh �hT来验证结果@H_502_2@
@H_502_2@配置完成后过一会儿就收到了报警正常的邮件。@H_502_2@
谢谢你打开这篇博文,并一直坚持看到了这里,如果觉得对你有帮助,请不要吝啬点一下右下角的赞。@H_502_2@