By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
IT Infras HolicIT Infras HolicIT Infras Holic
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Search
  • Privacy Policy
© 2024. All Rights Reserved.
Font ResizerAa
IT Infras HolicIT Infras Holic
Font ResizerAa
  • News
  • Linux
  • Docker
  • Web Server
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
Search
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Follow US
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
IT Infras Holic > Blog > Linux > Centos > How to Add Swap on CentOS 7
CentosLinux

How to Add Swap on CentOS 7

writer
Share
2 Min Read
SHARE

Add Swap on CentOS 7

Create Swap

1. Check the System for Swap Information

1
2
3
swapon -s
 
free -m

2. Create a Swap File 4GB with blocksize 1mb

1
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB

Change 4096 to size what you want

Contents
Add Swap on CentOS 7Create Swap1. Check the System for Swap Information2. Create a Swap File 4GB with blocksize 1mb3. Check Created Swapfile4. Enable a Swap File5. Check Modified Permission of Swapfile6. To secure, set up the swap space for use7. Verify that the procedure was successfulAfter you successfully add swap on CentOS 7, continue steps below8. Make the Swap File PermanentTweak Your Swap Settings (Optional)Set SwappinessCache PressureCheck  Present ValueResumeChange to 16GB

3. Check Created Swapfile

1
ls -lh /swapfile

 

4. Enable a Swap File

1
sudo chmod 600 /swapfile

 

5. Check Modified Permission of Swapfile

1
ls -lh /swapfile

 

6. To secure, set up the swap space for use

1
2
sudo mkswap /swapfile
sudo swapon /swapfile

 

7. Verify that the procedure was successful

1
2
swapon -s
free -m

After you successfully add swap on CentOS 7, continue steps below

8. Make the Swap File Permanent

1
sudo nano /etc/fstab

insert in the last line

1
/swapfile   swap    swap    sw  0   0

Tweak Your Swap Settings (Optional)

Set Swappiness

1
sudo sysctl vm.swappiness=10
1
sudo nano /etc/sysctl.conf
1
vm.swappiness = 10

 

Cache Pressure

1
sudo sysctl vm.vfs_cache_pressure=50
1
sudo nano /etc/sysctl.conf
1
vm.vfs_cache_pressure = 50

Check  Present Value

1
cat /proc/sys/vm/swappiness
1
cat /proc/sys/vm/vfs_cache_pressure

Resume

1
2
3
4
5
6
7
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo sysctl vm.swappiness=30
sudo sysctl vm.vfs_cache_pressure=50
sudo nano /etc/sysctl.conf
1
2
vm.swappiness = 30
vm.vfs_cache_pressure = 50

Change to 16GB

1
2
3
4
swapoff /swapfile
rm -f /swapfile && dd if=/dev/zero of=/swapfile bs=1MiB count=16384
mkswap /swapfile
swapon /swapfile

You Might Also Like

Monitoring File & Directory Changes using Bash Script

Vulnerability Checker CVE-2024-3094

Unleashing the Potential of Knowledge Management with Wiki.js

How to Install Apache Guacamole with Docker Compose

Unlocking Seamless Remote Access: Exploring the Power of Apache Guacamole

TAGGED: centos, centos7, swap
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Telegram Copy Link
Previous Article http headers How to Add Additional HTTP Headers in OpenLitespeed
Next Article add route in windows How to Add Route in Windows
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest News

http headers
Monitoring File & Directory Changes using Bash Script
Linux Application
vulnerability
Vulnerability Checker CVE-2024-3094
Linux
wiki.js
Unleashing the Potential of Knowledge Management with Wiki.js
Application Linux
Install Apache Guacamole
How to Install Apache Guacamole with Docker Compose
Application Linux

You Might also Like

How to Install Cyberpanel on Ubuntu 22.04
OpenlitespeedUbuntuWeb Server

Install Cyberpanel on Ubuntu 22.04

8 Min Read
How to map SFTP as a drive on Windows 10
LinuxWindows

How to map SFTP as a drive on Windows 10

3 Min Read
Follow US
© 2024
activity notes activity notes
Welcome Back!

Sign in to your account

Lost your password?