Question
How to enable/create a swap file on a Plesk Linux server?
Answer
Plesk requires a minimum of 1 GB of swap on a Linux server. According to this article, Plesk does not manage swap space. The recommend size for the SWAP can be checked in hardware requirements document. Usually, for servers with more than 2 GB, the recommendation is half of the amount of RAM.
This article describes how to manually create and enable the swap file in the Linux operating system.
Note: Not having a paging file of sufficient size can affect processes and make the system unstable if there is not enough memory or a memory leak occurs. The recommendation and importance explanation you may find in the next link Do we really need swap on modern systems?
- Start by creating a file that will be used for swap:
# fallocate -l 1G /swapfile
- Note: In old distributions like CentOS 7, you might have problems with the fallocate command.
To create the file in this case, use:# dd if=/dev/zero of=/swapfile count=1024 bs=1MiB
- Only the root user should be able to write and read the swap file. Set the correct permissions by typing:
# chmod 600 /swapfile
- Use the mkswap utility to set up a Linux swap area on the file:
# mkswap /swapfile
- Activate the swap file using the following command:
# swapon /swapfile
- To make the change permanent, open the
/etc/fstab
file:# vi /etc/fstab
- Add the following content:
CONFIG_TEXT: /swapfile swap swap defaults 0 0
- Verify that the swap is active by using either the swapon or the free command, as shown below:
# swapon --show
# free -h - Swappiness is a Linux kernel property that defines how often the system will use the swap space. Swappiness can have a value between 0 and 100. A low value will make the kernel try to avoid swapping whenever possible, while a higher value will make the kernel use the swap space more aggressively. The default swappiness value is 60. You can check the current swappiness value by typing the following command:
# cat /proc/sys/vm/swappiness
While the swappiness value of 60 is OK for most Linux systems, for production servers, you may need to set a lower value.
Comments
0 comments
Please sign in to leave a comment.