之前做过实验而未做记录,今天在生产坏境中再次遇到。现将整个操作过程记录如下,供以后参考使用:

使用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的扩充有三种方法:

  1. 如果你原有的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


以上三种方式皆可,这次用的是低三种方式,方便。