You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04服务器Laravel 8应用140GB磁盘耗尽问题排查及无损清理咨询

Answers to Your Disk Space Issues

Based on your disk stats, the real culprit isn't Laravel itself (your project is only ~1GB) — it's your system's syslog files that have ballooned to over 120GB combined. Here's why this ties back to Laravel:

  • Most likely, your Laravel application is configured to send its logs to the system syslog (via the Monolog logging library) in addition to its own storage logs.
  • Your server's log rotation setup (for rsyslog) was either missing or misconfigured, so these syslog files never got rotated, compressed, or deleted. They just kept growing indefinitely as Laravel logged every request, error, and debug message.
  • The /var/log/journal directory (systemd's journal logs) also has some accumulation, but it's nowhere near the size of the syslog files.

2. How to clean up while preserving all data and configurations

Follow these steps safely on your running server:

Step 1: Emergency cleanup of oversized log files

Never delete actively written log files directly (it can break logging services). Use these commands instead:

  • Truncate the active syslog file to zero bytes (preserves the file so logging doesn't stop):
    sudo truncate -s 0 /var/log/syslog
    
  • Delete the archived syslog.1 file (this is no longer being written to):
    sudo rm /var/log/syslog.1
    
  • Remove old compressed syslog archives (confirm you don't need historical logs first):
    sudo rm /var/log/syslog.*.gz
    

Step 2: Fix log rotation to prevent recurrence

Configure logrotate to automatically manage your syslog files:

  1. Open the rsyslog rotation config file:
    sudo nano /etc/logrotate.d/rsyslog
    
  2. Ensure it has a rule for syslog that looks like this (adjust values if needed):
    /var/log/syslog
    {
        rotate 7
        daily
        missingok
        notifempty
        delaycompress
        compress
        postrotate
            /usr/lib/rsyslog/rsyslog-rotate
        endscript
    }
    
    • rotate 7: Keep 7 days of logs
    • daily: Rotate logs every day
    • compress: Compress old log files to save space
  3. Trigger an immediate rotation to apply the changes:
    sudo logrotate -f /etc/logrotate.d/rsyslog
    

Step 3: Clean up systemd journal logs

Systemd's journal can also accumulate over time:

  • Check current disk usage:
    sudo journalctl --disk-usage
    
  • Clean up logs older than 7 days:
    sudo journalctl --vacuum-time=7d
    
  • Or limit journal logs to a maximum of 1GB (adjust as needed):
    sudo journalctl --vacuum-size=1G
    
  • To make this permanent, edit /etc/systemd/journald.conf and set:
    SystemMaxUse=1G
    
    Then restart the journal service:
    sudo systemctl restart systemd-journald
    

Step 4: Optimize Laravel's logging configuration

Prevent Laravel from flooding syslog unnecessarily:

  1. Open your Laravel logging config file:
    nano /var/www/laravel-project/config/logging.php
    
  2. Check if your default logging channel includes syslog. If you don't need Laravel logs in the system syslog, switch the default to daily (Laravel's built-in rotating log driver):
    'default' => env('LOG_CHANNEL', 'daily'),
    
  3. Ensure the daily channel is configured to rotate logs (Laravel 8 does this by default, but double-check):
    'daily' => [
        'driver' => 'daily',
        'path' => storage_path('logs/laravel.log'),
        'level' => env('LOG_LEVEL', 'debug'),
        'days' => 14, // Keep 14 days of Laravel logs
    ],
    

Important Notes

  • Before cleaning, if you need to debug past issues, back up critical logs first (e.g., sudo cp /var/log/syslog ~/syslog-backup).
  • Verify no other services are generating excessive logs (check Nginx logs in /var/log/nginx/ if needed, though your stats don't show them as a problem).

内容的提问来源于stack exchange,提问作者Ahmed Yehia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 23:17:30