先来查看一下free
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 32160 14212 17947 0 216 12096
-/+ buffers/cache: 1899 30260
Swap: 8189 0 8189
32G的内存,却只分配了8G的swap,在实际生产环境下经常出现swap空间不足的情况,需要手动增加swap空间,步骤如下:
创建一个10G的文件
[root@localhost ~]# dd if=/dev/zero of=/opt/swap bs=1k count=10240000
10240000+0 records in
10240000+0 records out
10485760000 bytes (10 GB) copied, 55.6452 seconds, 188 MB/s
将创建的文件用作交换分区
[root@localhost ~]# mkswap /opt/swap
Setting up swapspace version 1, size = 10485755 kB
开启swap
[root@localhost ~]# swapon /opt/swap
此时,swap空间增加到了18189MB,done。
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 32160 24504 7655 0 226 22096
-/+ buffers/cache: 2181 29978
Swap: 18189 0 18189