In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use / dev/shm/ under linux CVM". The content in 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 use / dev/shm/ under linux CVM".
I. what are tmpfs and / dev/shm/?
Tmpfs is a memory-based file system on Linux/Unix systems. Tmpfs can use your memory or swap partition to store files. Thus it can be seen that tmpfs mainly stores temporary files. It has the following two advantages:
1) size of the dynamic file system.
2) another major benefit of tmpfs is its lightning speed. Because a typical tmpfs file system resides entirely in the in-memory RAM, reads and writes can be almost instantaneous.
It also has a drawback that tmpfs data will not be retained after a reboot because virtual memory is inherently volatile. So it is necessary to do some scripts to do operations such as loading and binding. Tmpfs does not have persistence, data will not be retained after restart, please pay attention to it!
/ dev/shm/ is a device file, it uses the tmpfs file system (Note: under Centos and Redhat, the / dev/shm directory is a link to the / run/shm directory, while under the Ubuntu system, the tmpfs file system corresponds to the / run/shm directory, which can be viewed using the df command), because the / dev/shm/ directory is not on the hard disk, but in memory, it is called tmpfs. In linux distributions such as Redhat/CentOS, the default size is half of physical memory. For example, my Red Hat Enterprise Linux Server 5.464 (single core, 512 memory) allocates memory of 512m, so / dev/shm is about 250m. Check / dev/shm as follows:
[root@AY1212111202285f63122 ~] # df-h FilesystemSize Used Avail Use% Mounted on / dev/hda120G 7.6G 11G 42% / tmpfs250M 0250M 0% / dev/shm
Tmpfs is a memory-based file system that is created without initialization such as mkfs. If I want to change the / dev/shm tmpfs size to 512m, modify the / etc/fstab:
Tmpfs / dev/shm tmpfs defaults 0 0
Change to
Tmpfs / dev/shm tmpfs defaults,size=512m 0 0
Then execute mount-o remount / dev/shm
[root@AY1212111202285f63122] # mount-o remount / dev/shm [root@AY1212111202285f63122] # df-h FilesystemSize Used Avail Use% Mounted on / dev/hda120G 7.6G 11G 42% / tmpfs512M 0512M 0% / dev/shm
How, become 512m, it is very convenient to use it, there is no problem to restart, . Of course, you can increase the memory in the production environment, anyway, the memory is very cheap, in order to improve performance, you also need to increase / dev/shm.
II. The use and application scenarios of tmpfs (/ dev/shm)
Tmpfs is based on memory, the speed is needless to say, the hard disk can not be compared with it. The Automatic Memory Management feature in Oracle uses / dev/shm. In addition, if you make good use of tmpfs in the operation and maintenance of the website, there will be unexpected gains. Let's first build a tmp in / dev/shm and bind it to / tmp.
[root@AY1212111202285f63122 ~] # mkdir / dev/shm/tmp [root@AY1212111202285f63122 ~] # chmod 1777 / dev/shm/tmp / / attention permissions [root@AY1212111202285f63122 ~] # mount-- bind / dev/shm/tmp / tmp [root@AY1212111202285f63122 ~] # ls-ld / tmp drwxrwxrwt 2 root root 40 May 29 21:46 / tmp
The following / tmp uses some application examples of tmpfs file system. Generally, tmpfs memory file system will accelerate web access when doing web caching, cache, and temporary file storage, thus improving the speed of website access.
(1) put the cache directory cache_dir of squid under / tmp
Vi / etc/squid/squid.conf
Modify to
Cache_dir ufs / tmp 256 16 256
The first 256 here means using 256 megabytes of memory, restart the squid service, so that the cache directory is placed in the tmpfs file, needless to say.
(2) put the session file of php under / tmp
For a heavily visited apache php site, there may be a lot of temporary files under tmp, such as seesion or some cache files, so you can save it to a tmpfs file. The way to save seesion is very simple: just modify the php.ini. Check your php session storage location through the phpinfo test file. If it is not under / tmp, modify the php.ini file as follows:
Session.save_path = "/ tmp"
(3) put the socket file of the service under / tmp
Such as nginx.socket and mysql.sock.
As for other applications of tmpfs, I think you may be inspired by this article. Emphasize again: tmpfs data will not be retained after reboot, restart tmpfs data will be lost, so it is necessary to do some scripts such as loading, binding operations!
Thank you for your reading. The above is the content of "how to use / dev/shm/ under linux CVM". After the study of this article, I believe you have a deeper understanding of how to use / dev/shm/ under linux CVM, and the specific usage 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.