%title缩略图

检测MySQL服务,宕机自动重启

cd ~

vim /mysqllisten.sh

#!/bin/bash
pgrep -x mysqld &> /dev/null
if [ $? -ne 0 ]
then
echo "MySQL stoped at time: `date` ">> /home/wwwlogs/mysql_messages
/etc/init.d/mysql restart
sleep 15s
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $4}'`
if [ "$MYSQLPORT" == "3306" ]
then
echo "MySQL restart successful at time: `date` ">> /home/wwwlogs/mysql_messages
else
echo "MySQL restart failed at time: `date` ">> /home/wwwlogs/mysql_messages
mail -s "wann! yourwebsitedomain's mysql restart failed" 这里写你的邮箱地址
fi
else
echo "MySQL server is running"

 

给予写入权限

chmod +x ./mysqllisten.sh

添加定时任务

crontab -e */10 * * * * /bin/bash /root/mysqllisten.sh service crond restart

重启不成功发送邮件给管理者

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

19 − 8 =

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据