In case you have a CentOS 6/7 server running out of space you may face to many unstable issues. We recommend to free up the disk space as soon as possible. In this article only top scenarios are highlighted.
Check the disk space
The first step should be checking the available disk space, type:
root$ df -l
You will get an output something similar to:
Filesystem Size Used Avail Use% Mounted on /dev/vda3 41G 41G 10M 100% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/vda1 240M 151M 77M 67% /boot
Resolution: you are running out of space, start cleaning.
Cleaning logs
Execute the command below and it will truncate any *.log files on the volume /var that are either older than 7 days and greater than 50M or older than 30 days.
find /var -name "*.log" \( \( -size +50M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;
The next step is installing yum-utils to manage the server:
yum -y install yum-utils
Flushing ‘yum’ cache
Let’s apply the command to cleanup ‘yum’ caches. It will not remove everything related to yum generally, only cache.
yum clean all
Removing orphan packages
Checking all existing orphan packages:
package-cleanup --quiet --leaves
Then removing orphan packages selected by the previous command:
package-cleanup --quiet --leaves | xargs yum remove -y
Removing error_log files
Server panels are usually creating many log files not rotating. For example in cpanel you may find many of error_log files scattered across your users directories. Removing these files will free up an extra space:
find /home/*/public_html/ -name error_log -delete