linux Centos7 adds swap partition detail
- 2020-06-23 02:38:57
- OfStack
Note :(Redhat5 official recommendation)
RAM < =4G,swap=2G;RAM > 4G, < 16G,swap=4G;RAM > 16G, < 64G,swap=8G;RAM > 64G, < 256G,swap=16G
Redhat6/7 Official recommendation RAM < =2G,swap=2*RAM;RAM > 2G, < 8G,swap=RAM;RAM > 8G, < 64G,swap > =4G;RAM > =64G,swap > = 4 G; (Sleep state is another consideration)
There are two ways to add swap: 1. Add swap partition; 2. 2. Add swap file;
Method 1.
Adding swap space can be used to solve the problem that some services are forced to shut down due to excessive physical memory usage on the system
Add 1 hard disk of 200M (0.2ES52en) in shutdown state
View the swap size
free -m // or cat /proc/meminfo | grep -i swap or fdisk -l or swap -s
So if you look at the new hard disk that was added here the new disk that was added was sdb (see capacity)
cat /proc/partitions
Create the partition and set it to swap format
fdisk /dev/sdb
n // Create partitions
p // Create primary partition
1 // Create partitions 1
Press enter twice // Initial sector and Last Sector selection default
t // Convert partition format
82 // convert swap space
p // View the partition results created
w // Save the exit
Format to swap space
mkswap /dev/sdb1
Enable swap
swapon /dev/sdb1
The edit profile is set to boot auto mount
vim /etc/fstab
Add the following to save and exit
/dev/sdb1 swap swap defaults 0 0
Set to automatically enable all swap Spaces
swapon -a
Restart the validation
reboot
Check the swap size again
cat /proc/partitions
0
Note: You can see that swap has changed
Method 2.
Adding swap space can be used to solve the problem of insufficient physical memory on the system causing some services to be forced to shut down
View the swap size
cat /proc/partitions
1
Note: If swap displays 0 or does not output swap, the system does not add swap space
Create the swap file
cat /proc/partitions
2
Set to allow root users to work with this file only
chmod 600 /etc/swap
Check file sizes and permissions
cat /proc/partitions
4
Set the file to swap
cat /proc/partitions
5
Enable the swap file
cat /proc/partitions
6
Make the swap file permanent
cat /proc/partitions
7
Add:
/etc/swap swap swap defaults 0 0
Change the swap configuration
cat /proc/partitions
9
Modify if there is, add if there is no :(modify the value as required)
vm.swappiness=30 // A higher value indicates a greater propensity to use swap space
Restart to take effect
reboot
Check the swap size again
free -m // or cat /proc/meminfo | grep -i swap or fdisk -l or swap -s
Above is this site to organize the full content, thank you for the site's support.