服务器磁盘怎么清理
服务器磁盘怎么清理
Hello,
First, understand where the disk space is being used:
After SSHing into the server, run the following commands for a preliminary check:
df -h # Overall partition usage
du -sh /var/lib/rancher/k3s/* 2>/dev/null | sort -h # K3s component usage
du -sh /var/log/* 2>/dev/null | sort -h # System + container logs
crictl images | awk '{print $7, $1":"$2}' | sort -h # Image cache
journalctl --disk-usage # systemd journal size
du -sh /tmp /var/tmp 2>/dev/null # Temporary files
Things you can safely clean yourself:
# 1. Shrink systemd journal to 500MB (keep recent, delete old)
journalctl --vacuum-size=500M
# 2. Clear failed login records (keep file structure, clear content)
truncate -s 0 /var/log/btmp
truncate -s 0 /var/log/auth.log
# 3. Clear old compressed logs
find /var/log -name "*.gz" -mtime +30 -delete
# 4. Clear old /tmp files (>7 days)
find /tmp -mtime +7 -type f -delete 2>/dev/null
Things the Zeabur platform handles automatically (no manual action needed):
crictl rmi --prune)To prevent future disk space issues:
Add the following to /etc/systemd/journald.conf:
SystemMaxUse=500M
SystemMaxFileSize=50M
Then run systemctl restart systemd-journald. The journal will no longer grow indefinitely.
My server disk usage has reached 93%: server-69cb1fd90824506cca6d1714 Disk: 73.1GB / 78.6GB
Please help me clean up unused K3s/containerd images, container logs, and system logs. Please do not delete my persistent data, database data, uploaded files, or project files. If a restart of the service or server is required, please let me know first.
Hello, I have checked your disk usage (currently 98%), and the main contributors are as follows:
| Item | Size |
|---|---|
/home/ubuntu/dan-runtime/dan-web.log | 57 GB |
| systemd journal logs | 4.0 GB |
| containerd images | 4.5 GB |
| btmp login failure logs | 358 MB |
| PVC data (your service data) | 2.3 GB |
The main issue is that the dan-web log file is taking up 57 GB. This is an application you installed manually on the server and is not managed by the Zeabur platform. You can handle this file yourself, for example:
# Clear the log while keeping the file
truncate -s 0 /home/ubuntu/dan-runtime/dan-web.log
It is recommended to set up log rotation to prevent it from filling up again. After clearing this file, your disk usage will drop from 98% to approximately 20%.
Additionally, you can also clean up the systemd journal (4 GB) and btmp (358 MB):
sudo journalctl --vacuum-size=500M
sudo truncate -s 0 /var/log/btmp.1 /var/log/btmp