In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to configure swap exchange area in CentOS". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to configure swap exchange area in CentOS".
CentOS as the most stable server version in the linux world, rhas5 has always had a wide range of applications. Before, it has always focused on freebsd, because of the needs of applications, especially in cooperation with mysql and oracle, red hat has too many advantages.
Use centos instead of redhat as, because centos5 uses the source code of rhas5 and compiles and distributes it after removing the trademark and icon of redhat. It is the most compiled version of the source code. I use centos 5.2.
When installing centos 5.2, forget to set the swap swap partition, in the case of small memory, increasing the role of swap is more effective.
Before configuring swap, check the swap and disk space through free and df in order to compare the changes after configuring swap.
The code is as follows:
Free-m
[root@ithomer] # free-m
Total used free shared buffers cached
Mem: 1008 955 53 0 17 168
-/ + buffers/cache: 769 239
Swap: 0 0 0
Df-h
[root@ithomer] # df-h
Filesystem Size Used Avail Use% Mounted on
/ dev/xvda1 20G 15G 4.2G 79% /
Tmpfs 505m 0505m 0% / dev/shm
/ dev/xvdb 9.9G 5.1G 4.4G 54% / home/data
The first step is to create a file block
The code is as follows:
[root@ithomer ~] # cd / var (enter a folder)
[root@ithomer var] # dd if=/dev/zero of=swapfile bs=1024 count=1024000 (swap for creating 1GB, usually twice the amount of memory)
1024000 million 0 records in
1024000 million 0 records out
1048576000 bytes (1.0 GB) copied, 23.3843 s, 44.8 MB/s
[root@ithomer var] # / sbin/mkswap swapfile (create the swap file, actually the dd has been created, you don't have to create it here)
Mkswap: swapfile: warning: don't erase bootbits sectors
On whole disk. Use-f to force.
Setting up swapspace version 1, size = 1023996 KiB
No label, UUID=e878f535-ea6f-4516-8a34-f1458951aa36
[root@ithomer var] # ll swapfile
-rw-r-r- 1 root root 1048576000 November 27 00:55 swapfile
[root@ithomer var] # / sbin/swapon swapfile (activate swap file)
[root@ithomer var] # / sbin/swapon-s (check if swap is correct)
Filename Type Size Used Priority
/ var/swapfile file 1023992 0-1
[root@ithomer var] # vi / etc/fstab (added to the fstab file to start automatically when the system boots)
Add the following at the end:
The code is as follows:
/ var/swapfile swap swap defaults 0 0
[root@ithomer var] # reboot
After the restart, the top command checks to see that there is the size of the swap partition.
The code is as follows:
Free-m
[root@ithomer] # free-m
Total used free shared buffers cached
Mem: 1008 528 480 0 25 128
-/ + buffers/cache: 375633
Swap: 999 0 999
Df-h
[root@ithomer] # df-h
Filesystem Size Used Avail Use% Mounted on
/ dev/xvda1 20G 16G 3.2G 84% /
Tmpfs 505m 0505m 0% / dev/shm
/ dev/xvdb 9.9G 5.1G 4.4G 54% / home/data
According to the above comparison of free and df with that before configuring swap, it is found that swap has increased from 0 to 999 (about 1GB), while the system master disk (/ dev/xvda1) has been reduced from 4.2g to 3.2g, that is, the space of swap comes from the system master disk (/ dev/xvda1).
Problems and solutions
1. Format and launch swap files
Next, execute the mkswap command to format the myswap file into an s file system before the system can use it, change to the / tmp directory, and execute the following command:
The code is as follows:
# mkswap swapfree (format the file to swap file format)
Setting up swapspace version 1, size = 262144 KB
# swapon / tmp/swapfree (# start swap partition)
To stop using the newly created swap file, simply execute the swapoff / tmp/swapfree command and delete it if the swap swap file is no longer in use.
2. Check swap
The code is as follows:
# swapon-s
3. Start the newly added swap partition automatically when you boot
If you have to execute the swapon command to start the swap partition or file after every boot, it is too troublesome. At this time, you can use the text editor to add a line to the / etc/fstab file, so that the swap partition and files can be started automatically when you boot:
The code is as follows:
/ dec/hdb5 swap swap defaults 0 0 (start this swap partition when booting)
/ tmp/swapfree swap swap defaults 0 0 (start this swap file on boot).
Swap space size:
In general, Swap space should be greater than or equal to the size of physical memory, the minimum should not be less than 64m, and usually the size of Swap space should be 2-2.5 times the size of physical memory. However, according to different applications, there should be different configurations: if it is a small desktop system, only a small Swap space is needed, while large server systems need different sizes of Swap space according to different circumstances. Especially the database server and Web server, with the increase of access volume, the requirement of Swap space will also increase. For specific configuration, please see the description of each server product.
Number of swap:
The number of Swap partitions also has a significant impact on performance. Because the operation of Swap exchange is the operation of disk IO, if there are multiple Swap exchanges, the allocation of Swap space will operate on all Swap in turn, which will greatly balance the load of IO and accelerate the speed of Swap exchange. If there is only one switching area, all the switching operations will make the switching area very busy, leaving the system waiting most of the time and inefficient. Using the performance monitoring tool, you will find that the CPU is not very busy at this time, but the system is slow. This shows that the bottleneck lies in IO, and the problem cannot be solved by increasing the speed of CPU.
Thank you for reading, the above is the content of "how to configure swap exchange in CentOS". After the study of this article, I believe you have a deeper understanding of how to configure swap exchange in CentOS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.