[Linux] How to troubleshoot high disk or memory usage?

When Linux disk space is full

  • 请注意,在进行任何删除操作之前,请确保你知道哪些文件可以安全删除,并备份重要文件,以免意外丢失数据。
  • When the Linux disk space is full, you can follow the following steps to troubleshoot:
    1. Check Disk Usage: Run df -hcommand to check disk usage. This command will display the disk usage for each mount point, as well as free space and usage.
    2. Determine the largest directory or file: Use du -h --max-depth=1 /path/to/directorythe command to step through the size of each subdirectory under a directory. Start at the root directory and drill down to find the directory or file taking up the most space.
    3. Find large files: Run find / -type f -size +100Mthe command to find files larger than 100MB. This will scan the entire file system and you can adjust the size threshold if needed.
    4. Clean up unnecessary log files: Check /var/logthe log files in the directory, especially the older log files, and consider backing up or deleting log files that are no longer needed.
    5. Clean up temporary files: Check /tmpthe temporary files in the directory, you can use find /tmp -type f -mtime +7 -exec rm {} \;the command to delete the temporary files a week ago.
    6. Find deleted but still open files: Run lsof | grep deletedthe command to find deleted files that are still occupied by processes. These files do not free up disk space until the associated process is closed.
    7. Clean Package Cache: Run apt-get clean(Ubuntu/Debian) or yum clean all(CentOS/RHEL) command to clean package manager's cache.
    8. Delete unnecessary large files: If you find some large files that you no longer use, you can back them up and delete them to free up disk space.
    9. Check logs and application errors: Check system log files (such as /var/log/syslogor /var/log/messages) and application logs for anomalies that are causing disk space to run out quickly.
    10. Consider expanding disk space: If the steps above do not resolve the issue, you may want to consider expanding disk space to make more space available to your system.

The running memory usage of Linux system is high

  • Please note that before taking any action, make sure to back up important data and carefully assess the potential impact on your system and applications.
  • When the running memory usage of the Linux system is high, you can troubleshoot according to the following steps:
    1. View system memory usage: Run free -hthe command to view the system's memory usage, including used, available, and cache/buffer information. Pay attention to the "used" and "available" fields.
    2. Check process memory usage: Run the topor htopcommand to see the most memory-consuming processes on your system in real time. Press "Shift + M" to sort the process list by memory usage. Pay attention to check whether there are abnormal processes or applications that take up a lot of memory.
    3. Check for memory leaks: Run ps aux --sort=-%memthe command to list all processes in descending order of memory usage and watch for signs of memory leaks. If a process's memory usage continues to grow without being freed, you may have a memory leak.
    4. Check caching and buffer usage: Look at freethe "cached" and "buffers" fields in the output of the command. These are memory used by the operating system to improve file system performance. In general, you don't need to worry about these values.
    5. Check for services that use a lot of memory: Use the topor htopcommand to observe which services or processes are taking up a lot of memory. Look for services that may be causing high memory consumption, such as database servers, web servers, etc.
    6. Check for memory leaking apps: If a suspect app is leaking memory, consider restarting the app to free up memory and check to see if the high memory usage still occurs.
    7. Tuning Kernel Parameters: In some cases, it may be necessary to tune Linux kernel parameters to optimize memory management. This requires a detailed understanding of the system and specific application requirements, and it is recommended to consult a system administrator or professional if you are unsure about this.
    8. Upgrade hardware or add memory: If your system's memory usage is consistently high and cannot be resolved by the steps above, you may want to consider upgrading your hardware or adding more memory to provide greater capacity.

Guess you like

Origin blog.csdn.net/qq_39017153/article/details/132276696