1. swap Overview
Swap partition, that is, Swap zone. The role of Swap space can be simply described as: when the physical memory of the system is insufficient, a part of the physical memory needs to be released, for the currently running program. The released space may come from some programs that haven't been operated for a long time. The released space is temporarily saved to the Swap space and will be executed by those programs, then, the stored data is restored from Swap to the memory. In this way, the system always performs Swap switching when the physical memory is insufficient. In fact, Swap adjustment is crucial to the performance of Linux servers, especially Web servers. By adjusting Swap, the system performance bottleneck is sometimes crossed to save system upgrade costs.
2. Create a swap
When you install Centos 6.0, you forget to create a swap partition. As a result, zabbix is used to monitor the server. Then we found that no swap partition was created. Create a swap partition as follows:
First, use a user with ROOT permissions to remotely log on to the system through SSH or a local terminal to create a swap partition.
Dd if =/dev/zero of =/swap bs = 1024 count = 1024000
If // Input
Of // output bs // block size
Count // create a Linux swap file in total size
Mkswap/swap activate immediately/swap file
Check whether swapon/swap takes effect
[Root @ webserver ~] # Free-mtotal used free shared buffers cached
Mem: 2007 140 1867 0 8 35-/+ buffers/cache: 96 1911
Swap: 972 0 972 the above output shows that the swap partition has been successfully created.
Set to permanently valid
It takes effect now, but wait until the next restart of the server. This swap virtual disk will become invalid. To ensure permanent effectiveness, you need to add the following instruction set in the/etc/fstab file:
Echo "/swap defaults 0 0">/etc/fstab so far, the swap partition has been created.
2. Delete swap partitions
Sometimes you may need to delete the swap partition. How can you delete the partition correctly?
Stop swap partition first
Swapoff/swap Delete swap partition File
Rm-rf/swap Delete the specified file "/etc/swap"
In this way, you can manually add and delete swap partitions.
Sed-I "/'\/swa \/swap defaults 0 0' //"/etc/fstab