Over the years I have had web sites I work on go down because the server ran out of space (when I wasn’t responsible for the system administration). Well today I had it happen for some sites on one of my servers.
I have a remote monitoring service so I was notified when the sites were unavailable. Looking in the error logs I could see I ran out of space, which is a fairly lame error to make, I think. I cleared up some space quickly and things were in working order again.
A few tips from this experience. To see data on space used and available space from the command line (linux/ubuntu) use the df command.
[bash]df[/bash]
You could check that occasionally to see if anything strange is going on. But it is better to use something like Nagios to monitor the server and provide notice if usage goes past certain points is wise (75%, 80%…).
I found a nice way to find large files (that may be possible to delete to free up space)
[bash]sudo find . -mount -ls | awk ‘{print $7, $11}’ | sort -rn > large_file_list[/bash]
If you get an error with the file creation, you can log in as root (su) or create the file first and then it can overwrite the existing file.
It is smart to have log rotate setup for logs. I didn’t have it setup for every log. To create a file to keep track of all your logs for domains you can do the following. Create a file in the logrotate directory so it is run per your settings.
[bash]sudo vim /etc/logrotate.d/virtualhosts[/bash]
This article from Slicehost provide details on options, a simple setup is to include text such as this in the file created in the line above.
[bash]/var/www/domain1.com/logs/*log /var/www/domain2.com/logs/*log {
rotate 14
daily
compress
delaycompress
sharedscripts
postrotate
/usr/sbin/apache2ctl graceful > /dev/null
endscript
}[/bash]
Related: System Monitoring Tools for Ubuntu VPS – Phusion Passenger Tips and Troubleshooting Ideas – Checklist: Moving WordPress site to a New Host
Continue reading →