之前做過實驗而未做記錄,今天在生產壞境中再次遇到。現將整個操作過程記錄如下,供以後參考使用:
使用free -m查看現在swap的大小:
[root@mcluster-alpha2-node2 ~]# free -m
total used free shared buffers cached
Mem: 48227 47870 356 0 1862 28928
-/+ buffers/cache: 17079 31148
Swap: 5999 5138 861
如上可知現在可用的swap分區爲6G,且絕大部分被佔用。
swap的擴充有三種方法:
如果你原有的swap是用的lvm,那很簡單。擴容lvm即可。
Disable swapping for the associated logical volume: # swapoff -v /dev/VolGroup00/LogVol01 Resize the LVM2 logical volume by 256 MB: # lvm lvresize /dev/VolGroup00/LogVol01 -L +256M Format the new swap space: # mkswap /dev/VolGroup00/LogVol01 Enable the extended logical volume: # swapon -va Test that the logical volume has been extended properly: # cat /proc/swaps 或者# free
2.新建邏輯卷做swap分區
Create the LVM2 logical volume of size 256 MB: # lvm lvcreate VolGroup00 -n LogVol02 -L 256M Format the new swap space: # mkswap /dev/VolGroup00/LogVol02 Add the following entry to the /etc/fstab file: /dev/VolGroup00/LogVol02 swap swap defaults 0 0 Enable the extended logical volume: # swapon -va Test that the logical volume has been extended properly: # cat /proc/swaps 或者# free
3.新建swapfile
mkdir /letv/swap dd if=/dev/zero of=/letv/swap/96g.out bs=1G count=96 mkswap /letv/swap/96g.out -f swapon -p 100 /letv/swap/96g.out echo '/letv/swap/96g.out swap swap defaults 0 0' >> /etc/fstab
以上三種方式皆可,這次用的是低三種方式,方便。