Oberst Server - Hosting von Infrastrukturservern

Kontaktinformation

Twist 96072377

[email protected]

Loslegen
swap 1
image_pdfPDF herunterladen

Platz in Linux austauschen: Was es ist und wie man es auf CentOS kreiert

Tauschen Sie den Speicherplatz in Linux -Funktionen ähnlich wie der virtuelle Speicher in Windows aus, Als Erweiterung des physischen RAM fungieren, wenn das System einen geringen Speicher läuft. Instead of allowing the operating system to crash or hang when RAM is fully utilized, swap space temporarily holds inactive data by using part of the hard drive. While swap is much slower than RAM (even on SSDs or NVMe drives), it plays a crucial role in maintaining system stability under high memory pressure.

How Much Swap Space Should You Allocate?

Premium RDP

Premium RDP Service by ColonelServer

🌟 Starting From $8.99/monthly

🌍 25+ Locations Worldwide

Buy RDP Now

There’s no strict rule, but here are some common recommendations:

  • If your system has 16 GB RAM, and you’re not limited by disk space, allocate 8–16 GB of swap.
  • SSDs or NVMe drives offer better performance, but are still slower than RAM, so don’t expect RAM-level performance from swap.

Preliminary Steps Before Proceeding

  • Backup your data before making any system-level changes.
  • Ensure you have root access to the system.
  • If you’re using a server, connect via SSH (seeHow to Connect via SSH“).

Creating Swap Space on CentOS

  1. Log in as Root Access your CentOS system as the root user or with sudo privileges.
  2. Create Swap File Use the following command to allocate 8GB of disk space to swap:
dd if=/dev/zero of=/swapspace bs=1024 count=8388608

Explanation:

  • 8 GB = 8192 MB
  • 8192 × 1024 = 8,388,608 KB
  • bs=1024: sets the block size
  • count=8388608: number of blocks to write
  1. Set Ownership to Root
chown root:root /swapspace
  1. Set Permissions
chmod 0600 /swapspace
  1. Format as Swap
mkswap /swapspace
  1. Activate Swap
swapon /swapspace
  1. Make Swap Persistent Open the /etc/fstab file:
nano /etc/fstab

If nano is not installed, run: yum install nano

Add the following line at the end of the file:

Debian VPS

Debian VPS Server

Sicher, Stable & Affordable

Explore Now
/swapspace none swap sw 0 0

Reboot the System

Now reboot to ensure changes are applied:

reboot

Verify Swap Activation

After reboot, use the following command to check swap:

Linux VPS

Zuverlässiger Linux -VPS -Hosting

Perfekt für Entwickler

Beginnen Sie jetzt
free -m

You will see the RAM and swap usage stats.

Need Expert Help?

If you’d prefer to leave server management to the pros, purchase a managed VPS. Hosting providers like Mizbanfa offer full server support including swap configuration, monitoring, and optimization.

Teilen Sie diesen Beitrag

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert