Skip to content

Instantly share code, notes, and snippets.

@jamesnguyen101
Last active January 7, 2019 14:57
Show Gist options
  • Save jamesnguyen101/af5af388c363a7b1dbff42ada6c9e445 to your computer and use it in GitHub Desktop.
Save jamesnguyen101/af5af388c363a7b1dbff42ada6c9e445 to your computer and use it in GitHub Desktop.
make 4G swap on CentOS
#!/bin/sh
SWAP_SIZE=4G
echo "create $SWAP_SIZE swap"
# on centos 6
#fallocate -l $SWAP_SIZE /swapfile
# on centos 7
dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
echo "enable swap"
chmod 600 /swapfile
mkswap -f /swapfile
swapon /swapfile
swapon -s
free -h
echo "add swapfile into fstab"
echo "/swapfile swap swap sw 0 0" >> /etc/fstab
echo "swap setting"
echo "vm.swappiness = 10" >> /etc/sysctl.conf
echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment