Create a swap file in CentOS 7

Reading Time: 2 minutes

Before we proceed with your CWP installation, let us access your VPS via SSH and create a swap file. By default, you need to create a swap file in CentOS manually. 

If you have not installed your Droplet in Digital Ocean, you may check my Install your CentOS 7 (VPS). This should include step by step on how to lunch your first VPS in Digital Ocean.

First, you will need to log in to your root user via SSH. In this example, I will use PuTTY as our SSH Client. Once login, you should have this window below:

image-19 Create a swap file in CentOS 7
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
image-21 Create a swap file in CentOS 7

Once completed, run these command below:

sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
image-27 Create a swap file in CentOS 7

Let us edit the fstab (known as file systems table) file.

sudo nano /etc/fstab

Then, add this line below:

/swapfile   swap    swap    sw  0   0
image-28 Create a swap file in CentOS 7

To save our changes, press ctrl + x, then enter y. Once saved, run this command below:

sudo sysctl vm.swappiness=10
image-29 Create a swap file in CentOS 7

Then,

sudo nano /etc/sysctl.conf

From here, add these lines below:

vm.swappiness = 10
vm.vfs_cache_pressure = 50
image-30 Create a swap file in CentOS 7

To save our changes, press ctrl + x, then enter y. Once completed, you may verify these changes via:

free -h
image-31 Create a swap file in CentOS 7

At this point, you should be all set. Great Job.

Next step. Creating a fully qualified domain (FQDN) for our hostname.

Was this post helpful?

Leave a Reply