服务器空间(当LINUX服务器磁盘空间不够时如何进行磁盘扩容)

概述 最近不知道写啥,就分享下之前生产环境装oracle rac环境的时候做的一个磁盘扩容案例吧,整理了一下,按照流程下来基本没问题的,主要是作为备忘。平滑扩容基础环境检查fdisk -ldf -h做啥事之前先检查总是没错的,通过上面的两个命令对系统磁盘有个大概的了解。[root@S-ppxt-dm7-1 ~]# fdisk -l
Disk /dev/sdb: 299.0 GB, 298999349248 bytes
255 heads, 63 sectors/track, 36351 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000d4200
Device Boot Start End Blocks Id System
/dev/sdb1 1 36352 291990528 8e Linux LVM
Disk /dev/sda: 479.0 GB, 478998953984 bytes
255 heads, 63 sectors/track, 58234 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000c4a37
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 58235 467259392 8e Linux LVM
Disk /dev/mapper/VolGroup-swap_lv: 34.6 GB, 34603008000 bytes
255 heads, 63 sectors/track, 4206 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-root_lv: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdd: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sde: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-var_lv: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-home_lv: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-tmp_lv: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000
[root@S-ppxt-dm7-1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-root_lv
9.8G 6.7G 2.6G 73% /
tmpfs 127G 72K 127G 1% /dev/shm
/dev/sda1 477M 40M 412M 9% /boot
/dev/mapper/VolGroup-home_lv
4.8G 10M 4.6G 1% /home
/dev/mapper/VolGroup-tmp_lv
4.8G 11M 4.6G 1% /tmp
/dev/mapper/VolGroup-var_lv
4.8G 213M 4.4G 5% /var
1、分析pv、vg情况pvsvgs[root@S-ppxt-dm7-1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup lvm2 a–u 445.61g 388.38g
/dev/sdb1 VolGroup lvm2 a–u 278.46g 278.46g
[root@S-ppxt-dm7-1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 2 5 0 wz–n- 724.07g 666.84g
2、创建物理卷(不做)pvcreate /dev/sda
pvs
这里我选择不做是因为已经在里面了,所以没做这一步。3、扩展逻辑卷(不做)vgextend VolGroup /dev/sda
pvs
lvs
vgs
df -h
这里我选择不做是因为已经在里面了,所以没做这一步。4、拉伸磁盘空间lvextend -L +300G /dev/mapper/VolGroup-root_lvlvextend -L +200G /dev/mapper/VolGroup-home_lvvgs[root@S-ppxt-dm7-1 ~]# lvextend -L +300G /dev/mapper/VolGroup-root_lv
Size of logical volume VolGroup/root_lv changed from 10.00 GiB (2560 extents) to 310.00 GiB (79360 extents).
Logical volume root_lv successfully resized.
[root@S-ppxt-dm7-1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 2 5 0 wz–n- 724.07g 366.84g
5、resize2fs生效resize2fs /dev/mapper/VolGroup-root_lvresize2fs /dev/mapper/VolGroup-home_lv[root@S-ppxt-dm7-1 ~]# resize2fs /dev/mapper/VolGroup-root_lv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-root_lv is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 20
Performing an on-line resize of /dev/mapper/VolGroup-root_lv to 81264640 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-root_lv is now 81264640 blocks long.
6、检查df -hpvsvgslvs[root@S-ppxt-dm7-1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-root_lv
306G 6.7G 283G 3% /
tmpfs 127G 72K 127G 1% /dev/shm
/dev/sda1 477M 40M 412M 9% /boot
/dev/mapper/VolGroup-home_lv
4.8G 10M 4.6G 1% /home
/dev/mapper/VolGroup-tmp_lv
4.8G 11M 4.6G 1% /tmp
/dev/mapper/VolGroup-var_lv
4.8G 213M 4.4G 5% /var
[root@S-ppxt-dm7-1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup lvm2 a–u 445.61g 88.38g
/dev/sdb1 VolGroup lvm2 a–u 278.46g 278.46g
[root@S-ppxt-dm7-1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 2 5 0 wz–n- 724.07g 366.84g
[root@S-ppxt-dm7-1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home_lv VolGroup -wi-ao—- 5.00g
root_lv VolGroup -wi-ao—- 310.00g
swap_lv VolGroup -wi-ao—- 32.23g
tmp_lv VolGroup -wi-ao—- 5.00g
var_lv VolGroup -wi-ao—- 5.00g
总结:上面的整体流程实际上是先通过fdisk -l看哪个盘准备拿来用,然后pvcreate它,接下来用vgextend扩展卷组,然后对其中的一个逻辑卷lvextend拉伸磁盘空间,最后resize2fs生效。后面会分享更多DBA和devops方面的内容,感兴趣的朋友可以关注下!!


本文出自快速备案,转载时请注明出处及相应链接。

本文永久链接: https://www.xiaosb.com/beian/36681/