最近在做rac,在環境檢查的時候發現swap空間檢查不通過,所以我們第一想到的是對swap進行擴容,那麼swap擴容有哪些方法呢?這裡主要介紹兩種方法,一通過添加額外磁碟,擴展swap分區,二是通過本地多餘空間的方式擴展swap分區。 一、現象描述 查看內容使用情況: 查看磁碟分區掛在情況: 這裡看 ...
最近在做rac,在環境檢查的時候發現swap空間檢查不通過,所以我們第一想到的是對swap進行擴容,那麼swap擴容有哪些方法呢?這裡主要介紹兩種方法,一通過添加額外磁碟,擴展swap分區,二是通過本地多餘空間的方式擴展swap分區。
一、現象描述
Check: Swap space Node Name Available Required Status ------------ ------------------------ ------------------------ ---------- rac02 10GB (1.0485756E7KB) 15.7037GB (1.6466544E7KB) failed rac01 10GB (1.0485756E7KB) 15.7032GB (1.6466E7KB) failed
查看內容使用情況:
[root@rac01 ~]# free -g total used free shared buffers cached Mem: 15 8 7 0 0 8 -/+ buffers/cache: 0 15 Swap: 9 0 9
查看磁碟分區掛在情況:
[root@rac01 ~]# cat /etc/fstab /dev/mapper/VolGroup-lv_root / ext4 defaults 1 1 UUID=ea4095fa-f040-1234-b0b5-abcd1532d332 /boot ext4 defaults 1 2 /dev/mapper/VolGroup-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/shm /tmp tmpfs defaults 0 0
[root@rac01 ~]# fdisk -l /dev/mapper/VolGroup-lv_swap Disk /dev/mapper/VolGroup-lv_swap: 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 / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
這裡看到swap空間為10.7GB,而我們系統記憶體時16GB,所以至少要擴展6GB才能達到rac檢查的要求
二、swap擴容
1、通過添加磁碟擴容
本系統看到是通過邏輯捲做的swap分區,那麼我們可以考慮通過邏輯捲擴展的方式擴容swap分區,如果邏輯捲組空間有富餘最好,如果沒有富餘而我們磁碟添加允許的情況下可以通過添加額外的磁碟來擴展邏輯捲組,進而擴展邏輯捲,再到swap分區。本系統是虛擬機,所以擴展磁碟還是比較方便的,具體操作步驟如下:
查看邏輯捲——>查看邏輯捲組——>邏輯捲組擴展(空間不足的情況下)——>卸載邏輯捲——>邏輯捲擴展——>格式化邏輯捲——>重新掛載
1)查看邏輯捲和邏輯捲組
[root@rac01 ~]# lvdisplay /dev/VolGroup/lv_swap --- Logical volume --- LV Path /dev/VolGroup/lv_swap LV Name lv_swap VG Name VolGroup LV UUID 4K2GGg-An39-9Vim-RdQW-U0es-BU9R-gwKoBb LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-10-11 14:42:02 +0800 LV Status available # open 1 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
[root@rac01 ~]# vgdisplay VolGroup --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 49.51 GiB PE Size 4.00 MiB Total PE 12674 Alloc PE / Size 7680 / 30.00 GiB Free PE / Size 4994 / 19.51 GiB VG UUID HYL3bE-tccs-SUil-i75E-qUqG-d6dD-6jzj2u
這裡看到swap對應的邏輯捲組還有多餘的19G空間,所以我們可以直接擴容swap分區
2)卸載swap分區
[root@rac01 ~]# swapoff /dev/mapper/VolGroup-lv_swap
3)擴展swap邏輯捲
[root@rac01 ~]# lvextend -L +6GB /dev/mapper/VolGroup-lv_swap Size of logical volume VolGroup/lv_swap changed from 10.00 GiB (2560 extents) to 16.00 GiB (4096 extents). Logical volume lv_swap successfully resized.
[root@rac01 ~]# fdisk -l /dev/mapper/VolGroup-lv_swap Disk /dev/mapper/VolGroup-lv_swap: 17.2 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 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
4)格式化新swap分區
[root@rac01 ~]# mkswap /dev/mapper/VolGroup-lv_swap mkswap: /dev/mapper/VolGroup-lv_swap: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 16777212 KiB no label, UUID=5cef886d-5537-4aa0-88d8-f4ce92e01698
5)重新掛在swap分區
[root@rac01 ~]# swapon /dev/mapper/VolGroup-lv_swap [root@rac01 ~]# free -g total used free shared buffers cached Mem: 15 8 7 0 0 8 -/+ buffers/cache: 0 15 Swap: 15 0 15
至此swap分區擴容完畢,但如果我們捲組容量不夠的情況下如何擴展呢?首先肯定是擴展卷組,然後再重覆上面的步驟。下麵將擴展卷組的方法在下麵補充
磁碟添加
[root@rac02 ~]# fdisk -l |grep sd Disk /dev/sda: 53.7 GB, 53687091200 bytes /dev/sda1 * 1 64 512000 83 Linux /dev/sda2 64 6528 51915776 8e Linux LVM Disk /dev/sdb: 107.4 GB, 107374182400 bytes Disk /dev/sdc: 8589 MB, 8589934592 bytes Disk /dev/sdd: 5368 MB, 5368709120 bytes /dev/sdd1 1 652 5237158+ 83 Linux Disk /dev/sdf: 107.4 GB, 107374182400 bytes /dev/sdf1 1 13054 104856223+ 83 Linux Disk /dev/sde: 5368 MB, 5368709120 bytes /dev/sde1 1 652 5237158+ 83 Linux Disk /dev/sdg: 10.7 GB, 10737418240 bytes /dev/sdg1 1 1305 10482381 83 Linux
6)創建新的物理捲
[root@rac02 ~]# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created
7)擴展邏輯捲組
[root@rac02 ~]# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 49.51 GiB PE Size 4.00 MiB Total PE 12674 Alloc PE / Size 7680 / 30.00 GiB Free PE / Size 4994 / 19.51 GiB VG UUID HYL3bE-tccs-SUil-i75E-qUqG-d6dD-6jzj2u [root@rac02 ~]# vgextend VolGroup /dev/sdc Volume group "VolGroup" successfully extended [root@rac02 ~]# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 57.50 GiB PE Size 4.00 MiB Total PE 14721 Alloc PE / Size 7680 / 30.00 GiB Free PE / Size 7041 / 27.50 GiB VG UUID HYL3bE-tccs-SUil-i75E-qUqG-d6dD-6jzj2u
這裡邏輯捲組擴容完畢,後面可以重覆1——5步驟完成swap擴容。
正常資料庫擴容後需要執行以下命令才能看到擴容後的磁碟容量:
e2fsck -f /dev/vgtest/vgtest-lv
resize2fs /dev/vgtest/vgtest-lv