Centos opens swap partition to expand memory

The machine purchased by Alibaba Cloud does not open the swap partition by default. If necessary, you need to open it yourself.
Ali’s current approach is:
1. Do not create swap partitions, it is determined by mirroring
2. Set vm.swappiness to 0, that is, never use swap partitions

Open swap partition

Create a special file for swap partition

dd if=/dev/zero of=/data/swap bs=1024 count=8388616

Note: The size of this file is the size of count multiplied by the size of bs, the size of the above command is 8GB

Use the mkswap command to make the newly created file into a swap partition

mkswap /data/swap

View the kernel parameter vm.swappiness

If vm.swappiness is 0, adjust to 30 or 60 according to actual needs

cat /proc/sys/vm/swappiness   
sysctl -a | grep swappiness    
sysctl -w vm.swappiness=60

Note: If you want to modify it permanently, edit the /etc/sysctl.conf file

Enable the swap function of this swap partition

swapon /data/swap   
echo "/data/swap swap swap defaults    0  0" >> /etc/fstab

Close the swap partition

swapoff /data/swap   
swapoff -a >/dev/null

Guess you like

Origin blog.csdn.net/dndndnnffj/article/details/112094718