#需求因系統內存資源緊張急需添加10G swap 交換空間
#創建存放swap文件的目錄
[root@localhost ~]# mkdir /swap#創建一個10G空文件
[root@localhost ~]# dd if=/dev/zero of=/swap/swap bs=1024M count=10 10+0 records in 10+0 records out 10737418240 bytes (11 GB) copied, 20.745 s, 518 MB/s#格式化為交換空間
[root@localhost ~]# mkswap /swap/swap mkswap: /swap/swap: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 10485756 KiB no label, UUID=844fb94b-c5e5-4d55-a091-c310b9e5e289#查看系統內存
[root@VM_37_0_centos ryzc]# free -m total used free shared buffers cached Mem: 24028 22842 1185 0 149 3530 -/+ buffers/cache: 19162 4866 Swap: 2047 1127 920#添加交換空間
[root@localhost ~]# swapon /swap/swap#再次查看系統內存
[root@localhost ~]# free -m total used free shared buffers cached Mem: 24028 22888 1139 0 150 3563 -/+ buffers/cache: 19174 4853 Swap: 12287 1125 11162#放到開機啟動
[root@localhost ~]# tail -1 /etc/rc.local swapon /swap/swap#刪除swap
[root@localhost ~]# swapoff /swap/swap [root@localhost ~]# rm -rf /swap/swap本文出自 “wsyht的博客” 博客,請務必保留此出處http://wsyht2015.blog.51cto.com/9014030/1792692