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 in Ubuntu

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

Share

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

Some time ago, I got on the bus to buy a student machine for more than three years. Together with the downconfiguration, I got a total of six years. However, after the memory dropped to 1 gigabyte, there was not enough memory for a long mysql. And for some unknown reason, Tencent Cloud's ubuntu actually has only 800 gigabytes of memory, which makes matters worse.

Finally, two days ago, the server crashed due to a burst memory and no open swap, which almost crashed, and the ssh could not be connected, and the console was forced to restart before returning to normal. To prevent this from happening again, I added a swap to the server.

Reference document: https://askubuntu.com/questions/33697/how-do-i-add-a-swap-partition-after-system-installation/796997#796997

First of all, let's find out what Swap is.

A Swap partition (also known as a swap partition) is an area on a hard disk that is designated as a place where the operating system can temporarily store data that can no longer be stored in RAM. Basically, this allows you to increase the amount of information that the server retains in its working "memory", but there are some caveats, mainly when there is not enough space in the RAM to hold the application data in use, the swap space on the hard drive will be used.

The information written to disk will be much slower than the information saved in RAM, but the operating system prefers to keep application data in memory and use to swap old data. In general, using swap space as fallback space may be a good safety net to prevent non-SSD storage systems from running out of memory when the system's RAM is exhausted.

The specific steps and commands are as follows:

# create an empty file For small memory machines, twice the memory size is recommended (in the example, 1K * 4m = 4 GiB). Sudo mkdir-v / var/cache/swapcd / var/cache/swapsudo dd if=/dev/zero of=swapfile bs=1K count=4Msudo chmod 600swapfile# converts the newly created file into a swap file. Sudo mkswap swapfile# enables swap.sudo swapon swapfile# to verify through the swapon or top command: swapon-s # or top-bn1 | grep-I swap# A message similar to this is displayed: KiB Swap: 4194300 total 4194300 when swap is disabled in 4194300 free#, you can use sudo swapoff swapfile.# to set the partition to boot to load .echo "/ var/cache/swap/swapfile none swap sw 00" | sudo tee-a / etc/fstab# test boot load: sudo swapoff swapfilesudo swapon-va

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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