简体   繁体   中英

How to clean up aws ec2 server?

I recently ran a report on my EC2 server and was told that it ran out of space. I deleted the csv that was partially generated from my report (it was going to be a pretty sizable one) and ran df -h and was surprised to get this output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  7.0G  718M  91% /
devtmpfs         15G  100K   15G   1% /dev
tmpfs            15G     0   15G   0% /dev/shm 

I surprised not only by how little was available/how much space was used,(I am on the /dev/xvda1 instance) but also surprised to see 2 alternative filesystems.

To investigate what was taking so much space, I ran du -h in ~ and saw the list of all directories on the server. Their reported size in aggregate should not be even close to 7 gb...which is why I ask "what is taking up all that space??"

The biggest directory by far was the ~ directory containing 165MB all other were 30MB and below. My mental math added it up to WAY less than 7gb. (if I understand du -h correctly, all directories within ~ ought to be included within 165MB...so I am very confused how 7 gb could be full)

Anyone know what's going on here, or how I can clean up the space? Also, just out of curiosity, is there a way to utilize the devtmpfs/tmpfs servers from the same box? I am running on AWS Linux, with versions of python and ruby installed

According to this answer , it seems as though it might be because of log files getting too large. Try run the command OP mentioned in their answer, in order to find all large files: sudo find / -type f -size +10M -exec ls -lh {} \\;

For me, the best option was to delete the overlay2 docker folder and to completely refresh docker to a clean state. It clears up more than 3GB in my case.

Important note: it will stop and remove your instances, so you need to rebuild them.

In order to do that, first stop the docker engine

sudo systemctl stop docker

Prune and then delete the entire docker directory (not just the overlay2 folder):

docker system prune
sudo rm -rf /var/lib/docker

Restart docker:

sudo systemctl start docker

The engine will restart without any images, containers, volumes, user created networks, or swarm state.

Additionaly you can remove snap with:

sudo apt autoremove --purge snapd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM