Use the Linux server/dev/shm/to release the disk pressure

Source: Internet
Author: User
Tags apache php php session temporary file storage

Use the Linux server/dev/shm/to release the disk pressure
    • Browse:646
    • |
    • Updated: 2013-06-18 18:08
    • |
    • Tags: disk

TMPFS is a memory-based file system on the Linux/unix system. TMPFS can use your memory or swap partition to store files. Thus, TMPFS primarily stores staged files. It has the following 2 advantages: 1. The size of the dynamic file system. 2. Another major benefit of TMPFS is its lightning-fast speed. Because a typical TMPFS file system resides completely in memory RAM, read-write can be almost instantaneous. It also has a drawback that TMPFS data is not retained after a reboot because virtual memory is inherently volatile. So it is necessary to do some scripts such as loading, binding operations.

Tools/Materials
    • Linux Server Systems

Method/Step
  1. 1

    /dev/shm/is a device file that uses the Tmpfs file system (note: Under CentOS and Redhat,/dev/ SHM Directory is a link to the/run/shm directory, the Ubuntu system Tmpfs file system corresponding to the/RUN/SHM directory, you can use the DF command to view), because/dev/shm/this 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.4 64 (single core, 512 memory) allocates memory to 512M, so/dev/shm is about 250M, view/dev/shm as follows:

    [[email  Protected] ~]# df-h

    Filesystem            size  used Avail use% mounted on

    /DEV/HDA1              20g  7.6g   11G  42%/

    Tmpfs                 250M     0  250m   0%/dev/shm

     

  2. 2

    Tmpfs is a memory-based file system that does not need to be initialized with MKFS when it is created. If I want to change the size of/dev/shm TMPFS to 512M, modify

    Tmpfs                  /dev in/etc/fstab /SHM                TMPFS   defaults        0 0

    Changed to /p>

    Tmpfs                  /DEV/SHM           &NBS P   tmpfs,defaults,size=512m        0 0

     

  3. 3

    Then executes mount-o remount/dev/shm

    [[email protected]]# Mount-o REMOUNT/DEV/SHM

    [[email protected]]# df-h

    Filesystem            size &N Bsp Used Avail use% mounted on

    /dev/hda1              20g  7.6g   11G   ; 42%/

    Tmpfs                 512M     0  512m   0%/dev/ SHM

     

  4. 4

    TMPFS (/DEV/SHM) use and application scenarios:

    TMPFS is memory-based, speed is needless to say, hard disk and it can not compare. The automatic Memory management feature in Oracle uses/DEV/SHM. In addition, if the site dimension good use of TMPFS, there will be unexpected harvest. We will first build a TMP at/DEV/SHM, and bind with/tmp.

    [Email protected] ~]# mkdir/dev/shm/tmp

    [[email protected] ~]# chmod 1777/dev/shm/tmp//Note permissions

    [email protected] ~]# Mount--bind/dev/shm/tmp/tmp

    [Email protected] ~]# ls-ld/tmp

    DRWXRWXRWT 2 root root 21:46/tmp

    The following application examples of the Tmpfs file system are used by/TMP, which generally TMPFS the memory file system to make Web cache, temporary file storage will have a good acceleration of web access, thereby increasing the speed of website access.

  5. 5

    Place the session file of PHP in/tmp

    For a large access to Apache PHP Web site, may be tmp under the temporary files will be many, such as seesion or some cache files, then you can save it to the Tmpfs file. The way to save the seesion is simple: Just modify php.ini, through the phpinfo test file to see your PHP session storage location, if not in/tmp, modify the php.ini file, modify the following: Session.save_path = " /tmp "

  6. 6

    Place the socket file for the service in/tmp

    such as Nginx.socket and Mysql.sock

    As for the other applications of TMPFS, I think we may be inspired by this article. Again: TMPFS data is not retained after reboot, restart TMPFS data is lost, so it is necessary to do some scripts such as loading, binding operation!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.