计划任务添加以下shell脚本自动重启mysql服务(根据负载状态重启)
计划任务设置每五分钟执行一次,脚本也是检测的最近五分钟的负载状态
#+------------------------------------
#+ 宝塔根据负载重启mysql脚本
#+------------------------------------
# $1 = 1min, $2 = 5min, $3 = 15min
loadavg=$(cat /proc/loadavg|awk '{printf "%f", $1}')
maxload=65
if [ $(echo "$loadavg > $maxload"|bc) -eq 1 ]; then
log="重启mysql!"
echo "★ $log 负载$loadavg"
/etc/init.d/mysqld reload
fi
sync
sleep 2
sync
echo 3 > /proc/sys/vm/drop_caches