# 查看内存状态
free -h
-------------------------------------------------------------------------------
total used free shared buff/cache available
Mem: 15G 299M 15G 11M 209M 14G
Swap: 2.0G 0B 2.0G
-------------------------------------------------------------------------------
# 增加虚拟内存,其中count单位KB,下面为从1G的位置开始,扩充到20G
dd if=/dev/zero of=/var/swap bs=1024 count=20480000
-----------------------------------------------------
20480000+0 records in
20480000+0 records out
20971520000 bytes (21 GB) copied, 22.6087 s, 928 MB/s
-----------------------------------------------------
# 创建交换分区
mkswap /var/swap
----------------------------------------------------
Setting up swapspace version 1, size = 20479996 KiB
no label, UUID=68268e63-7a55-41b3-8f8c-02df407482d3
----------------------------------------------------
# 挂载并激活分区
swapon /var/swap
-------------------------------------------------------------
swapon: /var/swap: insecure permissions 0644, 0600 suggested.
-------------------------------------------------------------
# 查看是否挂载成功
free -h
-------------------------------------------------------------------------------
total used free shared buff/cache available
Mem: 1.8G 84M 64M 2.2M 1.6G 1.5G
Swap: 21G 39M 21G
-------------------------------------------------------------------------------
# 上述方式增加虚拟内存是通过临时方式挂载
echo "/var/swap swap swap defaults 0 0" >> /etc/fstab
# 编辑配置文件
vim /etc/fstab
--------------------------------------
/var/swap swap swap defaults 0 0
--------------------------------------
# 重启
reboot
# 查看是否成功
free -h
-------------------------------------------------------------------------------
total used free shared buff/cache available
Mem: 1.8G 115M 1.5G 9.4M 201M 1.5G
Swap: 21G 0B 21G
-------------------------------------------------------------------------------