We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
[HowTo] Create and Add Swap On CentOS7 VestaCP
[HowTo] Create and Add Swap On CentOS7 VestaCP
In this Article we’re going to add Swap space to Linux OS (RHEL, CentOS, Ubuntu) to prevent memory full issues. Swap is important when your server frequently going out of memory and got hanged (OOM) this can cause MySQL database corruption and many issues with the server. Before we get started I like to inform that this tutorial is only valid for KVM type servers and Dedicated servers. For Openvz and other container based servers this tutorial will not work.
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
Follow this commands one by one :
STEP 2 :
We’ll create 1GB (1024MB) of Swap :
result will look like this :
STEP 3 :
Creating swap patition :
result will look like this :
STEP 4 :
Enabling Swap :
Checking Swap :
Step 5 :
making it Enable during server boot, run the below command which will add entry in /etc/fstab :
All done, you just enabled Swap partition on your server. let me know how it goes as i tried to make the tutorial as simple as could be.
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
- Protection against OOM (out of memory) errors, crashes, memory-related system unpredictability/instability.
- Increases available memory to the system and allows more programs to be run concurrently & more safely
- Prevent server non responsiveness/ hangs
Follow this commands one by one :
Code: Select all
cd /var
touch swap.img
chmod 600 swap.img
We’ll create 1GB (1024MB) of Swap :
Code: Select all
dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
Code: Select all
[root@srv1 var]# dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 3.30777 s, 317 MB/s
Creating swap patition :
Code: Select all
mkswap /var/swap.img
Code: Select all
[root@srv1 var]# mkswap /var/swap.img
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=5813e8e7-1034-4700-84c2-c06905e26535
Enabling Swap :
Code: Select all
swapon /var/swap.img
Code: Select all
free -h
Code: Select all
[root@srv1 var]# free -h
total used free shared buff/cache available
Mem: 1.9G 260M 144M 27M 1.6G 1.5G
Swap: 999M 0B 999M
making it Enable during server boot, run the below command which will add entry in /etc/fstab :
Code: Select all
echo "/var/swap.img none swap sw 0 0" >> /etc/fstab
Re: [HowTo] Create and Add Swap On CentOS7 VestaCP
Thanks, it works.
-
- Posts: 43
- Joined: Tue Apr 18, 2017 7:55 am
Re: [HowTo] Create and Add Swap On CentOS7 VestaCP
Shouldnt this be owned by root?
What about the following step...
# chown root:root /swap
What about the following step...
# chown root:root /swap