slow website, cpu / mem at 100%? — banning IPs on aws lightsail

this is a note-to-self about a bandaid:

back / debug story

periodically and increasingly frequently over the last few years my website would get super slow and i would just restart mysql. usually then things were happy. this time i restarted mysql and also restarted the entire server and it was still laggy (thanks possibly llm scrapers?)

( One time I was looking up project prior art and an LLM confidently linked to my blog post as prior work, but specified my friend by full name as the author lol )

Turns out the issue was actually just some bot attack exhausting server resources, per @gongomgra https://github.com/bitnami/vms/issues/420#issuecomment-1288922908

Diagnose the IP by tailing the apache access log:

Running: tail -n 100000 access_log | awk '{print $1}' | sort | uniq -c | sort -nr | head -n 10 | awk '{print $1}'
In: /opt/bitnami/apache2/logs/

7432 34.32.72.73
1039 144.76.32.235
206 <turned out to be my own ip oops lol, connected to my phone hotspot to undo>

per aqyno 

Ban the IP with iptables:

sudo iptables -A INPUT -p all -s 1.2.3.4 -j DROP 
# to undo:
sudo iptables -D INPUT -p all -s 1.2.3.4 -j DROP

Note that this is not persistent across reboot.

Also note this is because my instances is so old I can’t upgrade easily nor apt install anything anymore (eg the usual fail2ban, ufw, etc.), but I’m too lazy to do a wordpress migration right now. 

Obviously a band-aid since some new ip will come around in a day or a week. But meh, happy with how fast my website runs again, briefly. A little said that this probably costs me like $4/month in hosting costs though :///

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.