My VPS server specs is: Package Name: VPS S SSD, Processor: 4 cores, RAM:8 GB, Storage: 200 GB (100% SSD), Bandwidth: 200 Mbit/s Run on: Ubuntu 22.04, Price: With the same price I got much better specs compared to other hosting provider, checkout here.
Firstly I love the fact that I can use the server to host several websites of my own without paying much and got decent server specs for a good price.
However I found that sometimes my websites are down without knowing the caused.
Here are step by step I toook to resolved the problem:
1. Login to your server using PuTTy and check if your swap file is exist, use command $ sudo swapon –show if the result is empty it means you don’t have a swap file, like mine below:
note: I use root user, this is not a best practice, you should use other than root user and use sudo to execute command that require admin rights.
You can also use command $ free -h
Check your existing free space first, mine have 167Gb available as I only use it for 10%.
Create a file for swap. I use 8G because my RAM is 8G, for RAM2-8G use the same size for swap file.
Once created set permission to 600 to prevent regular user using that swap file.
Create Linux swap area on the file
the output will be like this:
activate the swap file
Make the changes permanent /etc/fstab
file:
$ sudo nano etc/fstab and paste following line /swap.img swap swap defaults 0 0
write the changes and exit from nano. Check if the swap is now active. Mine below is active and the size is 8G
adjusting the swappiness file value. Check the current value
For most Linux users 60 is enough, but if you want to change the lower value to 10 use command.
sudo sysctl vm.swappiness=10
for me I left the value to 60 for now and see if the server is now run smoothly.
The original source is: https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-22-04/