1、[root@test-1 ~]# free -m #查看当前的系统swap大小
total used free shared buffers cached
mem: 1972 1800 172 0 86 121
-/+ buffers/cache: 1592 379
swap: 3967 2119 18482、[root@test-1 ~]# dd if=/dev/zero of=/swap_file bs=1024 count=2097152 #复制磁盘空间,
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 gb) copied, 45.1339 s, 47.6 mb/s3、[root@test-1 ~]# mkswap /swap_file #格式化swaps分区
mkswap: /swap_file: warning: don't erase bootbits sectors
on whole disk. use -f to force.
setting up swapspace version 1, size = 2097148 kib
no label, uuid=e70c01f7-1117-46a5-ba36-955027112db64、[root@bcec-pud-1 ~]# swapon /swap_file #开启swap分区
5、[root@bcec-pud-1 ~]# free -m #再次查看swap空间增大
total used free shared buffers cached
mem: 1972 1720 251 0 35 273
-/+ buffers/cache: 1411 560
swap: 6015 2288 3727其中第二步,count指的的是需要的磁盘大小,我的是2g,所以2048*bs 即2048*1024=2097152,空间大小只改变count后面的数字即可
服务器重启之后swap分区会变成原来,要想开机也是增加后的大小,编辑/etc/fstab 在末端添加如下行
cat /etc/fstab
/swap_file swap swap defaults 0 0