How to Set Up Swap Space
How to Set Up Swap Space
If your server has limited RAM, adding swap space can prevent out-of-memory crashes:
# Create a 2GB swap file
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
# Make it permanent
echo '/swapfile none swap sw 0 0' >> /etc/fstab
# Verify
swapon --show
free -h
Recommended Swap Sizes
- 1 GB RAM server: 2 GB swap
- 2 GB RAM server: 2 GB swap
- 4+ GB RAM server: 2-4 GB swap