Warning: Undefined array key "cperpage" in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 255

Warning: Undefined variable $output in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 325

Warning: Undefined variable $fixed_tags in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 326

Warning: Undefined variable $isshowdots in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 327

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 330

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 333

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 336

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Undefined variable $more_text_link in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345
shell脚本监控mysql服务器状态 – 理想社会

shell脚本监控mysql服务器状态

目的:
1.监控mysql服务器的状态
2.当发现mysql down机就自动重启mysql服务
3.重启mysql不成功,发邮件给管理员警告mysql down机

#vi /usr/local/sbin/sbin/check_mysql.sh

#!/bin/sh
cat << EOF
+--------------------------------------------------------------------------+
| === Welcome to LinuxTone=== |
|-------------------------http://www.linuxtone.org------------------------ |
+-------------------------------By:hamgua----------------------------------+
EOF

PORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
MYSQLIP=`ifconfig eth0|awk '/inet/{print $2}'|cut -c 6-`
while [ `whoami` == "root" ]
do
if [ "$PORT" == "3306" ];then
echo "mysql is running......"
else
echo "restart mysql"
/etc/init.d/mysqld restart
if [ "$PORT" == "3306" ];then
echo "mysql restart successful......"
else
echo "mysql restart failure......"
echo "server: $MYSQLIP mysql is down,please try to restart mysql!" > /var/log/mymsg
mail -s "warn!server: $MYSQLIP mysql is down" hamgua@gmail.com < /var/log/mymsg
fi
fi
break
done

赋予check_mysql.sh可执行的权限
#chmod u+x /usr/local/sbin/check_mysql.sh

加入crontab,让系统五分钟检测一次mysql状态
#crontab -l

…………
*/5 * * * * /usr/local/sbin/check_mysql.sh > /dev/null 2>&1

评论

发表回复

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