Ubuntu 20.04服务器Laravel 8应用140GB磁盘耗尽问题排查及无损清理咨询
Answers to Your Disk Space Issues
1. Why is "Laravel-related" disk usage so high?
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/journaldirectory (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
syslogfile to zero bytes (preserves the file so logging doesn't stop):sudo truncate -s 0 /var/log/syslog - Delete the archived
syslog.1file (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:
- Open the rsyslog rotation config file:
sudo nano /etc/logrotate.d/rsyslog - Ensure it has a rule for
syslogthat 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 logsdaily: Rotate logs every daycompress: Compress old log files to save space
- 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.confand set:
Then restart the journal service:SystemMaxUse=1Gsudo systemctl restart systemd-journald
Step 4: Optimize Laravel's logging configuration
Prevent Laravel from flooding syslog unnecessarily:
- Open your Laravel logging config file:
nano /var/www/laravel-project/config/logging.php - Check if your default logging channel includes
syslog. If you don't need Laravel logs in the system syslog, switch the default todaily(Laravel's built-in rotating log driver):'default' => env('LOG_CHANNEL', 'daily'), - Ensure the
dailychannel 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
相关产品推荐
相关产品推荐

