In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to manually add and delete the swap area in CentOS. I think it is very practical, so I share it with you. I hope you can get something after reading this article.
SWAP is the virtual memory in Linux, which is used to expand the existence of temporary data due to insufficient physical memory. It is similar to virtual memory in Windows. In Windows, only files can be used as virtual memory. Linux can be used as virtual memory by files or partitions.
First check the current memory and swap space size (the default unit is k and the-m unit is M):
Free-m
You can see here that the total memory is 503Mgamine swap does not exist.
View swap information, including file and partition details
# swapon-s
Or
# cat / proc/swaps
If none, we need to add the swap partition manually. Note that the VPS of the OPENVZ architecture does not support manual addition of swap partitions.
There are two options for adding swap space: add a swap partition or add a swap file. It is recommended that you add a swap partition; however, if you do not have much free space available, add a swap file.
First, add swap exchange files
1. Use the dd command to create a swap exchange file
Dd if=/dev/zero of=/home/swap bs=1024 count=1024000
This creates a / home/swap partition file with a size of 1G.
2. Make the file in swap format:
Mkswap / home/swap
3. Use the swapon command to mount the file partition to the swap partition
/ sbin/swapon / home/swap
Let's take a look at it with the free-m command and find that there is already a swap partition.
But after rebooting the system, the swap partition becomes zero again.
4. To prevent the swap partition from becoming 0 after reboot, modify the / etc/fstab file
Vi / etc/fstab
Add at the end of the file (the last line)
/ home/swap swap swap default 0 0
In this way, even if the system is rebooted, the swap partition still has a value.
Delete swap exchange file
1. Stop the swap partition first
/ sbin/swapoff / home/swap
2. Delete swap partition files
Rm-rf / home/swap
3. Delete the auto-mount configuration command
Vi / etc/fstab
This line is deleted
/ home/swap swap swap default 0 0
In this way, the manually added swap files can be deleted.
Note:
1. You can only use root users to add and delete swap.
2. It seems that the swap partition assigned when the system is installed cannot be deleted.
3. The swap partition is generally twice the amount of memory, but the maximum is no more than 2G.
Second, use partitions to do SWAP (virtual memory).
1 use fdisk to create a swap partition (assuming / dev/sdb2 is a created swap partition)
2 use the mkswap command to set the swap partition:
# mkswap / dev/sdb2
3 enable swapping:
# swapon / dev/sdb2
4 write / etc/fstab to enable at boot time:
/ dev/sdb2 swap swap defaults 0 0
Delete swap partition
The steps are as follows:
1. Stop the swap partition first
/ sbin/swapoff / dev/sdb2
2. Delete the auto-mount configuration command
Vi / etc/fstab
This line is deleted
/ dev/sdb2 swap swap defaults 00 or above is how to manually add and delete swap areas in CentOS. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.