1:添加SWAP文件并设置空间为2G

# dd if=/dev/zero of=/var/swap bs=1024 count=2048000

  2048000+0 records in
  2048000+0 records out
  2097152000 bytes (2.1 GB) copied, 272.867 seconds, 7.7 MB/s
  

2:mkswap创建swap

# mkswap /opt/image/swap

3:free查看SWAP空间大小

# free -m 
 total       used       free     shared    buffers     cached    Mem: 
  1011        989        21          0         1           875    
 -/+ buffers/cache:   112         898    
  Swap:       1027            0       1027 
  

4:启动SWAP.

 # swapon /var/swap
 

5:增加的SWAP空间已生效,用free查看一下

  # free -m 
    total       used       free     shared    buffers     cached    Mem:  
       1011        995         15              0             4           877    
     -/+ buffers/cache:  113        897    
     Swap:      3027           0       3027 
     

6:挂载新增加的SWAP空间,修改/etc/fstab文件,系统重新启动后自动生效

 文件尾部添加:/var/swap     swap      swap  defaults 0 0