[CENTOS] Create SWAP for CentOS7

Check the System for Swap Information

We can see if the system has any configured swap by using swapon, a general-purpose swap utility. With the -s
flag, swapon will display a summary of swap usage and availability on our storage device:

swapon -s

If nothing is returned by the command, then the summary was empty and no swap file exists.

Check Available Storage Space

df -h

Create a Swap File

sudo fallocate -l 4G /swapfile

ls -lh /swapfile

Enable a Swap File

sudo mkswap /swapfile
sudo swapon /swapfile

Make the Swap File Permanent

sudo nano /etc/fstab
At the bottom of the file, you need to add a line that will tell the operating system to automatically use the swap file that you created:
/swapfile swap swap sw 0 0

你可能感兴趣的:([CENTOS] Create SWAP for CentOS7)