Simple disk operation and maintenance

Time:2021-1-27

I took over the project, the site suddenly collapsed, the final location is because the disk is full of reasons. After the project has been running for a long time, the log file becomes more and more huge, which slows down the running speed of the system. If the disk is full, the file cannot be written, which will cause the website to crash.
In this case, the following two commands are enough.

  1. View disk usage

    df -h

    disk file help

    [[email protected]_6_184_centos Uploads]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/vda1        50G   36G   12G  77% /
    devtmpfs        1.9G     0  1.9G   0% /dev
    tmpfs           1.9G   24K  1.9G   1% /dev/shm
    tmpfs           1.9G  464K  1.9G   1% /run
    tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
    tmpfs           380M     0  380M   0% /run/user/0
    tmpfs           380M     0  380M   0% /run/user/1001

    This is a problem50GThe size of the disk (including the system disk), the system kernel should be only10G+/dev/vda1It’s a mount disk.

  2. Find large files

    du -h --max-depth=1 /www/wwwroot

--max-depthIt means the depth of the search,1It’s a folder0It’s a file. As long as you know this command, you can locate large files.
/www/wwwrootIs to find the file under the path.*The default is to find the files in the current directory.

  1. Examples
    Use the above command to navigate tologsIt’s a big folder. This is where the logs are kept.
    Simple disk operation and maintenance
    You can see the three years of operationnginxThe log is very big, that’s itaccess.log
    echo "" >access.log

    This makes room for the system25GIt’s space.

This work adoptsCC agreementReprint must indicate the author and the link of this article

focus