Linux system resource load is too high and Apache shell script is automatically restarted
When we routinely maintain Apache Web servers in Linux, the endless loop caused by crawler crawling cannot jump out, or the collection of data from peers brings huge additional overhead to the server load, seriously, Apache will be shut down over load 2, leading to the failure of the website to provide external services, resulting in irreparable losses to enterprises. Find the relevant shell script for the warning mechanism for automatically restarting Apache on the Internet, and share it with more administrators. Make changes based on your actual situation. It is applicable to all web services that can be installed through service httpd START | stop or source code to restart Apache VPs or servers. Finally, execute the command every several minutes in the crontab settings.
[Root @ club root] # Cat/admin_tools/loadavg_restart_apache.sh
#! /Bin/sh
# Crontab usage: */3 *****/admin_tools/loadavg_restart_apache.sh>/admin_tools/restart_apache.log
Top_sys_load_num = 3
Sys_load_num = 'uptime | awk' {print $ (NF-2)} '| SED's /,//''
Echo $ (date + "% Y-% m-% d") 'uptime'
If ['echo "$ top_sys_load_num <$ sys_load_num" | BC '-EQ 1]
Then
Echo "#0 #" $ (date + "% Y-% m-% d % H: % m: % s ") "pkill httpd" 'ps-Ef | grep httpd | WC-l'
/Home/Server/Apache/bin/apachectl stop
Sleep 8
Pkill httpd
Sleep 8
For I in 1 2 3
Do
If ['pgrep httpd | WC-l'-Le 0]
Then
/Home/Server/Apache/bin/apachectl start
Sleep 30
Echo "#1 #" $ (date + "% Y-% m-% d % H: % m: % s ") "Start httpd" 'ps-Ef | grep httpd | WC-l'
Fi
Done
Else
If ['pgrep httpd | WC-l'-Le 0]
Then
/Home/Server/Apache/bin/apachectl start
Sleep 30
Echo "#2 #" $ (date + "% Y-% m-% d % H: % m: % s ") "Start httpd" 'ps-Ef | grep httpd | WC-l'
Fi
Fi