linux系统增加swap交换分区

swap分区为系统交换分区,在内存不足的时候可以适当增加swap分区。

1、创建部署2G的swap分区

root@v2ray-tw:/var# dd if=/dev/zero of=swapfile bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB, 2.0 GiB) copied, 15.2948 s, 137 MB/s

2、创建swapfile文件

root@v2ray-tw:/var# mkswap swapfile 
mkswap: swapfile: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 2 GiB (2097147904 bytes)
no label, UUID=7b55e7ce-7da3-4ad4-8bf6-1e5fa2ffbc25

3、激活swap分区

root@v2ray-tw:/var# swapon swapfile
swapon: /var/swapfile: insecure permissions 0644, 0600 suggested.

4、查看是否成功

root@v2ray-tw:/var# free -m
total used free shared buff/cache available
Mem: 2998 1925 90 52 982 863
Swap: 1999 0 1999

5、加入到开机启动挂载

root@v2ray-tw:/var# vi /etc/fstab                                     /var/swapfile swap swap defaults 0 0 
root@v2ray-tw:/var# mount -a

一定要执行mount,无报错就可以了

发表评论

后才能评论