MirrorNest
← Tüm kılavuzlar

Swap file on a low-RAM VPS

Add swap space on a small VPS (512MB-2GB RAM) to prevent the OOM killer from taking down services during a memory spike, especially during package installs/builds.

Hedef: Ubuntu / Debian / any Linux with a standard filesystemServer AdministrationResmi ana sayfa ↗Resmi belgeler ↗
Bu kılavuz, yukarıda bağlantısı verilen Swap file on a low-RAM VPS kendi resmi belgelerinden derlenmiştir — dağıtım ve proje sürümleri zamanla değiştiğinden, bu komutları bir üretim sunucusunda çalıştırmadan önce tam paket/sürüm adlarını her zaman orada kontrol edin.
  1. 1Check if swap already exists

    sudo swapon --show
    free -h
  2. 2Create a swap file

    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile

    2G is a reasonable default for a 512MB-1GB RAM VPS -- adjust to roughly 1-2x your RAM size. If fallocate isn't supported on your filesystem, use: sudo dd if=/dev/zero of=/swapfile bs=1M count=2048

  3. 3Make it permanent across reboots

    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  4. 4Tune swappiness for a server workload

    The default swappiness (60) favors swapping proactively, which fits desktop use better than a server -- a lower value keeps data in RAM longer.

    sudo sysctl vm.swappiness=10
    echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf