Author Topic: How to add swap on CentOS server  (Read 16384 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
How to add swap on CentOS server
« on: September 17, 2014, 11:31:53 AM »
Check for Swap Space

Before we proceed to set up a swap file, we need to check if any swap files have been enabled by looking at the summary of swap usage.

Code: [Select]
swapon -s
If nothing is returned, the summary is empty and no swap file exists.


Check Disk Space Usage
After we know that we do not have a swap file enabled, we can check how much space we have on the server with the df -h command.

Code: [Select]
df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda2        20G  7.0G   12G  39% /
tmpfs           246M     0  246M   0% /dev/shm
/dev/vda1       504M   38M  441M   8% /boot


Create and Enable Swap (512k = 512 MB)
Code: [Select]
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k
sudo mkswap /swapfile
sudo swapon /swapfile

Now you can see your swap using command
Code: [Select]
free -m
This file will last on the server until the machine reboots. You can ensure that the swap is permanent by adding it to the /etc/fstab file.

Code: [Select]
sudo nano /etc/fstab
Paste in the following line:
Code: [Select]
/swapfile          swap            swap    defaults        0 0

To prevent the file from being world-readable, you should set up the correct permissions on the swap file:
Code: [Select]
chown root:root /swapfile
chmod 0600 /swapfile
AntiDDoS Protection (web + mail)
http://centos-webpanel.com/website-ddos-protection-proxy

Join our Development Team and get paid !
http://centos-webpanel.com/develope-modules-for-cwp


Services Monitoring & RBL Monitoring
http://centos-webpanel.com/services-monitor


Do you need Fast and FREE Support included for your CWP linux server?
http://centos-webpanel.com/noc-partner-list
Installation Instructions
http://centos-webpanel.com/installation-instructions
Get Fast Support Here
http://centos-webpanel.com/support-services

Offline
*
Swap not visible in the dashboard front end
« Reply #1 on: August 17, 2019, 12:56:15 PM »
Hi, I have followed your steps and created a 2 GB SWAP FILE. But when I open the CWP dashboard, I dont see swap activated. However if I visit Disk Quota in Server settings, in the "Your disk status from the file /etc/fstab" section, it shows the swap file present but in partition scheme, it doesnt.
Even when I run df -h in terminal, I dont see the swap activated.
If I try to run swapon /swapfile it says
Code: [Select]
swapon: /swapfile: swapon failed: Device or resource busyIf I execute free -m it shows Mem and Swap but the swap is 100% free

If I execute swapon -s it shows the /swapfile entry with 0 as a value in Used field and -2 in the priority field

How to know swap is working and how to show it in the dashboard also?
« Last Edit: August 17, 2019, 12:59:41 PM by shobhit »