云服务器linux部署SWAP分区

查看当前虚拟内存大小

root@VM-0-9-ubuntu:/var# free -m
               total        used        free      shared  buff/cache   available
 Mem:           1833        1265         107          43         460         351
 Swap:          1024         866         158

在var目录中创建swapfile文件

root@VM-0-9-ubuntu:/var# dd if=/dev/zero of=swapfile bs=1024 count=3096000
 3096000+0 records in
 3096000+0 records out
 3170304000 bytes (3.2 GB, 3.0 GiB) copied, 29.5982 s, 107 MB/s

部署swapfile

root@VM-0-9-ubuntu:/var# mkswap swapfile 
 mkswap: swapfile: insecure permissions 0644, 0600 suggested.
 Setting up swapspace version 1, size = 3 GiB (3170299904 bytes)
 no label, UUID=e9e2df41-cad3-48a8-bad3-7d0906013a5d

激活swap

root@VM-0-9-ubuntu:/var# swapon swapfile
 swapon: /var/swapfile: insecure permissions 0644, 0600 suggested.

查看是否生效

root@VM-0-9-ubuntu:/var# free -m
               total        used        free      shared  buff/cache   available
 Mem:           1833        1119          66          43         647         488
 Swap:          4048        1015        3033

设置开机自动挂载

root@VM-0-9-ubuntu:/var# vim /etc/fstab 
root@VM-0-9-ubuntu:/var# mount -a

发表评论

登录... 后才能评论