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

The method of adding swap Partition to Centos7 in linux

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces the linux Centos7 to increase the swap partition method, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Note: (officially recommended by Redhat5)

RAM4G,16G,64G,=64G,swap > = 4G; (dormancy is considered separately)

There are two ways to add swap: 1, add swap partition; 2, add swap file

Method 1.

Adding swap space can be used to solve the problem that the system takes up too much physical memory, resulting in some services being forcibly shut down.

In the shutdown state, add a 200m (0.2g) hard disk

View swap size

Free-m / / or cat / proc/meminfo | grep-I swap or fdisk-l or swap-s

Check the newly added hard disk here the newly added disk is sdb (see capacity)

Cat / proc/partitions

Create a partition and set it to swap format

Fdisk / dev/sdbn / / create partition p / / create primary partition 1 / create partition 1 double enter / / start sector and Last sector choose default t / / convert partition format 82 / / convert to swap space p / / View the results of the created partition w / / save exit

Formatted into swap space

Mkswap / dev/sdb1

Enable swap

Swapon / dev/sdb1

Edit the configuration file to boot and mount automatically

Vim / etc/fstab

Add the following to save and exit

/ dev/sdb1 swap swap defaults 0 0

Set all swap spaces to be enabled automatically

Swapon-a

Restart verification

Reboot

Check the swap size again

Free-m / / or cat / proc/meminfo | grep-I swap or fdisk-l or swap-s

Note: you can see that swap has changed.

Method 2.

Adding swap space can be used to solve the problem that the system does not have enough physical memory, resulting in some services being forcibly shut down.

View swap size

Free-m / / or cat / proc/meminfo | grep-I swap or fdisk-l or swap-s

Note: if swap displays 0, or there is no output of swap, the system does not increase the swap space.

Create a swap file

Fallocate-l 2G / etc/swap / / specifies that the file is 2G

Set to allow only root users to manipulate the file

Chmod 600 / etc/swap

Check file size and permissions

Ls-lh / etc/swap

Set the file to a swap file

Mkswap / etc/swap

Enable swap files

Swapon / etc/swap

Make the swap file permanent

Vim / etc/fstab

Add at the end:

/ etc/swap swap swap defaults 0 0

Change swap configuration

Vim / etc/sysctl.conf

Modify it if you have it, or add it if you don't: (modify the value as needed)

The higher the vm.swappiness=30 / / value, the more inclined to use swap space.

Restart takes effect

Reboot

Check the swap size again

Free-m / / or cat / proc/meminfo | grep-I swap or fdisk-l or swap-s thank you for reading this article carefully. I hope the article "how to add swap Partition in linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

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