Skip to content

Instantly share code, notes, and snippets.

@antfu
Created April 11, 2019 22:45
Show Gist options
  • Save antfu/7a7c666b7ca5ef33a06f66c25c3ba700 to your computer and use it in GitHub Desktop.
Save antfu/7a7c666b7ca5ef33a06f66c25c3ba700 to your computer and use it in GitHub Desktop.
Create swap

From: https://unix.stackexchange.com/questions/294600/i-cant-enable-swap-space-on-centos-7

Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need

yum install nano -y

sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

sudo nano /etc/fstab

add this line:

/swapfile   swap    swap    sw  0   0

run this command

sudo sysctl vm.swappiness=10

sudo nano /etc/sysctl.conf

add this line

vm.swappiness = 10
vm.vfs_cache_pressure = 50

To verify swap's size

swapon --summary
free -h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment