To add swap memory (2GB) to a CentOS 7 Linux Box, please run the following commands in order:
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
*Note* For the next step, you will need nano installed. If you do not have nano installed, you can install with:
yum install nano
Once nano is installed run the following:
sudo nano /etc/fstab
Once the editor is open add the following to the file at the bottom and save the file:
/swapfile swap swap sw 0 0
Then turn the swap on:
sudo swapon /swapfile