I always make a list of SSH commands for a specific purpose. For example I have lists named: SSH for setting up a LEMP, SSH for setting up WordPress, so on and so forth.
The good thing about having the list is you don’t have to always google about the commands and trial and error every time. You already know what commands will work for specific scenario and it’s reusable and even automatable.
12 Useful Commands To Check Your Server Health using PuTTY or similar SSH client
The good thing about having the list is you don’t have to always google about the commands and trial and error every time…Read more
Here I am going to share all these SSH list that might save your life or at least make your life easier.
SSH to check if your server is overload/under attack
What would you do the first thing when your website is down and your server is in extremely high load? Would it be an attack? Or just some temporary spike?
Check your server load
Check the number of concurrent users
You can view the current concurrent users within SSH using:
netstat -plan | grep :80 | wc -l
Restart your server
Restart Nginx server:
service nginx restart Or service nginx reload
Restart Apache server:
/etc/init.d/apache2 restart Or sudo /etc/init.d/apache2 restart Or service apache2 restart
If your restarting your server doesn’t help, you might need to look into some logs and do further investigation.
Checkout what PHP script is running
ps -aux | grep php - see running php
Check if your server is busying sending emails
tail -f /var/log/exim_mainlog
Chances are high that your server hang because of sending out a large number of spam email. WordPress user always has this issue when they got unreliable plugins installed.
Check if the MySQL Database is busy
mysqladmin pr -p
Check if your server is generating large number of error log
tail -f /var/log/nginx/error.log
Please note that your error log directory may be different depends on your OS. If you happen to find your server is generating a large number of error log, look at the IP addresses that generating the error, if the IP addresses were the same, you are probably under attack attempts.
The hundreds of attack attempts generated by bot within a minute might is causing your server being busy. Ban these IP addresses can solve the problem temporary.
How to ban IP addresses
csf -d IP_ADDRESS csf -r