centos6 under linux VPS increases virtual memory, based on KVM virtual architecture

888u

Last update at :2024-05-01,Edit by888u

Nowadays, KVM-based VPS are getting cheaper and cheaper. They only cost a few dollars a year. However, this type of VPS often has very little memory. In normal use, there will be insufficient memory. This requires We increased the virtual memory ourselves. The method is very simple. Just copy a few commands, paste them and run them.

Finally, OpenVZ cannot increase virtual memory.


Add swap file

1. Use the dd command to create a swap file
dd if=/dev/zero of=/home/swap bs=1024 count=1024000
This creates a partition file of /home/swap with a size of 1G.

2. Make it into a swap format file:
mkswap /home/swap

3. Then use the swapon command to mount this file partition to the swap partition
/sbin/swapon /home/swap

We used the free -m command to take a look and found that there is already a swap partition.



But after restarting the system, the swap partition became 0 again.

4. To prevent the swap partition from becoming 0 after restarting, modify the /etc/fstab file
echo "/home/swap swap swap default 0 0" >> /etc/fstab
In this way, even if the system is restarted, the swap partition will still have value.

Delete swap file
1. Stop the swap partition first
/sbin/swapoff /home/swap

2. Delete the swap partition file
rm -rf /home/swap

3. Delete the automatic mounting configuration command
sed -i "/'\/home\/swap swap swap defaults 0 0'//" /etc/fstab

In this way, the manually added swap file can be deleted.

Note:
1. The operation of adding and deleting swap can only be performed by the root user.
2. It seems that the swap partition allocated when installing the system cannot be deleted.
3. The swap partition is generally 2 times the memory, but the maximum does not exceed 2G

Recommended site search: server, virtual host trial for 30 days, Hong Kong vps host rental, free website space application, foreign php host, host server Rental, ip rental, American independent host, ip query detailed address, Hong Kong virtual host space,

centos6 under linux VPS increases virtual memory, based on KVM virtual architecture

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码