How to create swap for VPS VULTR

If your VPS has not enough ram (memery) for web service , you need create Swapto make website more smoothly. This post will show you how to create swap in VULTR VPS  and how to config swappiness value to make your vps server has more performance.

How do I add swap?

To add 1GB of swap to your server, for example, follow these steps:

  1. Create the file to be used for swap.

    If fallocate fails or is not installed, run the following command.

  2. Format the file for swap.

  3. Add the file to the system as a swap file.

  4. Add this line to the end of /etc/fstab to make the change permanent.

  5. To change the swappiness value edit /etc/sysctl.conf and add the following line.

    Start with a value of 10 and increase if needed. A typical default value for swappiness is 60. The higher the number (up to 100), the more often swap is utilized.

    How much swappiness affects performance depends on how your memory is being used, so experiment to find an optimal value. At 0 the swap file will only be used when the system runs completely out of memory. Higher values let the system swap idle processes out to allow the system to free memory for disk caching, potentially improving overall system performance.

  6. Check that the swap file was created.

  7. Reboot the server to ensure that the changes go into effect.

Leave a Reply

Your email address will not be published.