|
#需求
因系统内存资源紧张急需添加10G swap 交换空间
#创建存放swap文件的目录
1
| [iyunv@localhost ~]# mkdir /swap
|
#创建一个10G空文件
1
2
3
4
| [iyunv@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
|
#格式化为交换空间
1
2
3
4
5
| [iyunv@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
|
#查看系统内存
1
2
3
4
5
| [iyunv@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
|
#添加交换空间
1
| [iyunv@localhost ~]# swapon /swap/swap
|
#再次查看系统内存
1
2
3
4
5
| [iyunv@localhost ~]# free -m
total used free shared buffers cached
Mem: 24028 22888 1139 0 150 3563
-/+ buffers/cache: 19174 4853
Swap: 12287 1125 11162
|
#开机自启动设置,法1:放到开机启动
1
2
| [iyunv@localhost ~]# tail -1 /etc/rc.local
swapon /swap/swap
|
#法2:放到/etc/fatab
1
2
| [iyunv@localhost opt]# tail -1 /etc/fstab
/swap/swap swap swap defaults 0 0
|
#删除swap
1
2
| [iyunv@localhost ~]# swapoff /swap/swap
[iyunv@localhost ~]# rm -rf /swap/swap
|
|
|