command output indicates the average number of processes in the run queue in the past 1, 5, and 15 minutes.
Under normal circumstances, these values will have some differences depending on the number of CPUs in the system. For a single-core CPU, if the load value reaches 1, it indicates that the system load has reached 100%, but for the dual-core system. In terms of 1, only the system load value is only about 50%.
and so on, in multiprocessor systems, the load mean is determined based on the number of cores. Calculated at 100% load, 1.00 represents a single processor, while 2.00 means there are two dual processors, then 4.00 means the host has four processors.
Automatically restart the web service according to the system load value
The following script uses the VPS with the Apache server as an example to periodically judge the system load value. When it reaches 5, the system is considered to be overloaded. Run, at this time, the script will automatically restart the Apache service, release system resources, in order to achieve smooth operation of the VPS server.
*Note: The script comes from the network, not original, the source is unknown, I made a few changes.
#!/bin/sh
#usage: */2 * * * * root /root/checkload.sh >>/root/checkload.log
TOP_SYS_LOAD_NUM=5
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 "AutoStart:" $(date +"%y-%m -%d %H:%M:%S") "pkill httpd" `ps -ef grep httpd wc -l`
pkill httpd
sleep 10
for i in 1 2 3
do
if [ `pgrep httpd wc -l` -le 0 ]
then
service httpd start
sleep 15
echo "AutoStart:" $(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
service httpd start
sleep 15
echo "AutoStart:" $(date +"%y-%m-%d %H:%M:%S") "start httpd" `ps -ef grep httpd wc -l`
fi
fi
The TOP_SYS_LOAD_NUM in the script indicates the maximum allowable system average load value, when this value is exceeded The script starts to restart the apache service. The use of the script is also very simple, directly to /etc/cron.d/to create a timed execution file, fill in the following content:
*/2 * * * * root /root/checkload .sh >>/root/checkload.log
where */2 means that the specified script is executed every two minutes and the execution result is output to the /root/checkload.log file. .
You can also modify the execution frequency according to your needs.
Summary
This script has been deployed to my VPS for a while, and from the usage situation, the effect is quite good.
I am a network administrator, recently installed the Windows 2003 server operating system on one, an
server perfect settings, support asp php cgi jsp asp.net mysql! First download the program we want
Understand what is the permanent redirection of resources. Under the simple unders
At present, the server CPU is still divided according to the CPU instruction system, usually divided
Using SecureRDP to Enhance Server Security
Error in SVN update: Cannot open new file svn-base system cannot find the specified file
Set database and directory permissions to prevent website hacking
Serv-U 6.0.0.2 security settings Raiders
Nginx prohibits an IP or an IP segment from accessing the website.
Use linux to do FTP server (1)
Apache server supports CGI program and SSI program setting method
Graphical installation of IIS7 in Vista and configuration of ASP environment
Windows Server's three major crashes and avoidance methods
Want to save money and avoid risks. Server hosting needs to pay attention to these points
Method of setting port mapping and reverse proxy in Apache server
What should I do if the driver does not have a disk when the win7 computer is shut down?
Bear the burden, Microsoft's future depends on Win9
Win 7 start menu input command to start various programs
Realtek HD Audio Driver 2.26 version For Vista/Windows 7
20 strokes to accelerate Windows 2003 operating system
Forgot your password, how do I unlock BitLocker?
Wonderful life "Win7+IE9" one-click easy to lock
Wonderful solution to Win xp can not shut down failure