Skip to content

Instantly share code, notes, and snippets.

@johnyaucc
Last active January 2, 2016 16:29
Show Gist options
  • Select an option

  • Save johnyaucc/8330156 to your computer and use it in GitHub Desktop.

Select an option

Save johnyaucc/8330156 to your computer and use it in GitHub Desktop.

Revisions

  1. johnyaucc renamed this gist Jan 9, 2014. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gistfile1.txt → Add Swap on CentOS6
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    # Reference: https://www.digitalocean.com/community/articles/how-to-add-swap-on-centos-6

    # check for swap space
    swapon -s

  2. johnyaucc created this gist Jan 9, 2014.
    33 changes: 33 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # Reference: https://www.digitalocean.com/community/articles/how-to-add-swap-on-centos-6

    # check for swap space
    swapon -s

    # check filesystem
    df -h

    # create and enabled the swap file (e.g. 512MB)
    sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k
    sudo mkswap /swapfile

    # activate the swap file
    sudo swapon /swapfile

    # add swap to filesystem
    vi /etc/fstab
    # by pasting the following
    /swapfile swap swap defaults 0 0

    # set ownership and permission
    chown root:root /swapfile
    chmod 600 /swapfile

    # configure swappiness (0-100, 100 = swap often and too soon usually)
    sysctl vm.swappiness=10
    cat /proc/sys/vm/swappiness

    # (optional) set swappiness on boot
    vi /etc/sysctl.conf
    # and set
    vm.swappiness=10
    # note: It may be useful to set your swappiness to 0 to ensure that your VPS operates optimally.