Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add swap virtual memory and delete configuration in linux system

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to add swap virtual memory and delete linux system configuration, the article is very detailed, has a certain reference value, interested friends must read!

1. Swap Overview

Swap partition, that is, swap area, the role of Swap space can be simply described as: when the physical memory of the system is not enough, it is necessary to release part of the space in the physical memory for the current running program to use. The freed space may come from programs that have not operated for a long time, and the freed space is temporarily stored in Swap space, and when those programs are ready to run, the saved data is restored from Swap to memory. In this way, the system will always swap when physical memory is insufficient. Swap tuning is critical to the performance of Linux servers, especially Web servers. By tweaking Swap, you can sometimes bypass system performance bottlenecks and save on system upgrades.

2. Creating Swap

When installing Centos 6.0 OS, forget to create swap partition, cause alarm when using zabbix to monitor this server. At this point, it was discovered that no swap partition was created. So you need to create a swap partition, as follows:

First, use a user with ROOT permissions to log in to the system remotely through SSH or a local terminal to create a swap partition.

dd if=/dev/zero of=/swap/swap bs=1024 count=1024000

if //input

of //output

bs /block size

count //total size

Creating Linux Exchange Files

mkswap /swap/swap

Activate/swap/swap files now

swapon /swap/swap

Check if it works.

[root@webserver ~]# free -m

total used free shared buffers cached

Mem: 2007 140 1867 0 8 35

-/+ buffers/cache: 96 1911

Swap: 972 0 972

As you can see from the output above, the swap partition has been successfully created.

Set to Permanently Effective

Although it has been effective for now, after the next server restart. The swap virtual disk will be invalid. To ensure permanent validity, you need to add the following instruction set to the/etc/fstab file:

echo "/swap/swap swap swap defaults 0 0" >> /etc/fstab

The swap partition has now been created.

2. Delete swap partition

Sometimes it may be necessary to delete swap partitions, how to delete partitions correctly?

Stop the swap partition first

swapoff /swap/swap

Delete swap partition file

rm -rf /swap/swap

Delete the "/etc/swap" specified file

This allows you to manually add and remove swap partitions.

The code is as follows:

sed -i "/'\/swa\/swap swap swap defaults 0 0'//" /etc/fstab

The above is "linux system how to add swap virtual memory and delete configuration" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report