Archive for November 22, 2017

High load,Automatic restart mysql,apache

#!/bin/sh
# crontab: */3 * * * * /root/loadavg_restart_apache.sh >> /Wise / People / Ristart_apacheklog
sync
sync
echo 3 > /proc/sys/vm/drop_caches
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
sync
echo “#0#” $(date +”%y-% m-% d% H:%M:%S”) “pkill httpd” `ps -ef | grep httpd | wc -l`
echo “#0#” $(date +”%y-% m-% d% H:%M:%S”) “pkill mysql” `ps -ef | grep mysql | wc -l`
service httpd stop
service mysql stop
sleep 8
pkill httpd
pkill mysql

sleep 8
for i in 1 2 3
do
if [ `pgrep mysql | -The toilet -l` 0 ]
then
/sbin/service mysql start

sleep 30
echo “#1#” $(date +”%y-% m-% d% H:%M:%S”) “start mysql” `ps -ef | grep mysql | wc -l`

be

if [ `pgrep httpd | -The toilet -l` 0 ]
then

service httpd start

service wdapache start

sleep 30

echo “#1#” $(date +”%y-% m-% d% H:%M:%S”) “start httpd” `ps -ef | grep httpd | wc -l`
be

done
else
if [ `pgrep mysql | -The toilet -l` 0 ]
then
/sbin/service mysql start

sleep 30
echo “#2#” $(date +”%y-% m-% d% H:%M:%S”) “start mysql” `ps -ef | grep mysql | wc -l`

be

if [ `pgrep httpd | -The toilet -l` 0 ]
then

service httpd start

 

sleep 30

echo “#2#” $(date +”%y-% m-% d% H:%M:%S”) “start httpd” `ps -ef | grep httpd | wc -l`
be

be

The above documents,Save /root/loadavg_restart_apa_my.sh

Then

crontab -e

Add to

*/3 * * * * /root/loadavg_restart_apa_my.sh >> /Wise / People / Ristart_ap_mayklog

*/3 ***** It represents three minutes,/root / loadavg_restart_apa_my.sh you can customize。

Comments