How to configure swap files on a VPS?

windows vps

windows vps

It doesn’t matter what type of droplet you have, 512mb or 8 GB, you may need more memory for Arch, CentOS, Fedora, or Ubuntu applications to run flawlessly. The same applies to servers and daemons. In most cases, allocating memory to virtual servers can help to get the job done in a perfect manner. People working with production servers should know that virtual memory is not allocated, and you can run out of space in a little time.

Even after allocating more memory, if it fails, the issue might be with the platform or the type of configuration you made in the beginning. Such problems lead to an array of undesirable issues, and there might be many unstable conditions that you have to deal with. Some other applications stop working, and you have no else option than terminating the application and running it again after creating more space.

Keeping a dedicated server or droplet seems like a healthy and effective choice which can work with Windows PC, Mac, Android tablets as well as phones. At least enabling a small amount of memory can help in this condition. Virtual memory will allow your device to surpass the threshold or the physical memory it has. There is a basic requirement that you should complete before getting started.

Requirements

In order to get started, you have to be specific with the requirement and look after having below mentioned three things. All these things are going to make your server work perfectly, and they will help flawlessly. Let’s have a look –

  • You need a virtual server or any droplet. We are talking about a dedicated server or a Linux-based system.
  • You should provide a root terminal access, which is SSH, VNC, or Local.
  • Look for command free, Swapoff, Swapon, dd, mkswap, and others that are available for the platform that you can use with the droplet.

Once all these requirements are fulfilled, you can look at other factors like how to install and other configurations for effective use. Keep it in mind that you should choose the best kind of server or droplet for effective use.

Step By Step Guide

You should follow the below-mentioned steps to effectively configure swapfile. Make sure that you meet the need to get started and have an excellent working swap configuration:

  1. The first process is to verify the swap and ensure that there is no existing swap in the entire process. You should run the ‘free -m‘ command to get started.
  2. Now, create a new swap file to get started. Start by choosing the location, and make sure that you store it at the root of the folder or directory. You can do it by entering ‘dd if=/dev/zero of=/swapfile count=2048 bs=1M‘ command. This command has dd, which will produce output.
  3. The third step is for the activation of the swap file. As you run swap files, they are not going to run automatically at all because they are not activated. You have to add a command to help the server getting the right file and location. Otherwise, there will be no valid swap in the entire process.
  4. Run ‘chmod 600 /swapfile‘ for the swap file, and once it is done, you have to change permission. It is easy as if you run ‘ls -lh /swapfile‘, and it will produce a file display mentioning ‘ls -lh /swapfile‘, and you can add a new command.
  5. You can tell the server for a swap file by entering ‘mkswap /swapfile‘, and you will get an output after this.

If you see the below-mentioned output after following all the steps, then the configuration is perfect, and you can begin using it. The display will show –

Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=ff3fc469-9c4b-4913-b653-ec53d6460d0e

The whole process is complete, and turning swap on is the only thing that you have to do. You have to command ‘swapon /swapfile‘, and then you should run the ‘free’ command at the end. Everything is done, but once you reboot, the configuration won’t work. To enable it, you should command ‘nano /etc/fstab‘, and it will begin working even after reboots.

Bottom Line

Completing all these steps and saving the file will complete the entire process. You can start using VPS and getting better performance. There will be no issues like application crashes or lack of space while running large files. In case you have any issue, even after following all the steps, you should check the requirement column and reconfirm everything.