mysql健康检查_服务器php、mysql的健康状态检测

这篇博客介绍了一个Shell脚本,用于检查Web服务器和MySQL服务的运行状态,若发现问题会自动重启并发送通知。通过`checkweb.php`和`checkdb.php`进行健康检查,针对不同故障采取相应的措施。
摘要由CSDN通过智能技术生成

#!/bin/sh

cd /usr/local/sbin

test -e "checkweb.php" && rm -rf checkweb.php

test -e "checkdb.php" && rm -f checkdb.php

test -e "wget-log" && rm -f wget-log

test -e "wget-log.1" && rm -f wget-log.1

wget -b "http://127.0.0.1/checkweb.php" > /dev/null 2>&1

wget -b "http://127.0.0.1/checkdb.php" > /dev/null 2>&1

sleep 2

checkweb=`cat checkweb.php`

checkdb=`cat checkdb.php`

if

[ "$checkweb" == "ok" ] ;then

echo "`date +%d/%m/%Y:%H:%M:%S` - - Webserver successfully!"

if

[ "$checkdb" == "ok" ] ;then

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected successfully!"

echo " "

echo "-------------------------------------------------------------"

elif

[ "$checkdb" != "ok" ] ;then

/etc/init.d/mysqld restart

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected bad!restart successful!"

curl "http://sms.api.bz/fetion.php?username=150********&password=******&sendto=150********&message=php连接数据库失败,数据库重启成功!"

echo " "

echo "-------------------------------------------------------------"

fi

exit 0

elif

[ "$checkweb" != "ok" ] ;then

killall -9 nginx

/usr/local/nginx/sbin/nginx

/usr/local/php-fcgi/sbin/php-fpm restart

echo "`date +%d/%m/%Y:%H:%M:%S` - - Webserver is down!restart successfully!"

wget -b "http://127.0.0.1/checkdb.php" > /dev/null 2>&1

sleep 2

checkdb2=`cat checkdb.php`

if

[ "$checkdb2" == "ok" ] ;then

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected successfully!"

curl "http://sms.api.bz/fetion.php?username=150********&password=******&sendto=150********&message=php服务器down机,重启成功!"

echo " "

echo "-------------------------------------------------------------"

elif

[ "$checkdb2" != "ok" ] ;then

/etc/init.d/mysqld restart

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected bad!restart successful!"

curl "http://sms.api.bz/fetion.php?username=150********&password=******&sendto=150********&message=php服务器,mysql服务器down机,重启成功!"

echo " "

echo "-------------------------------------------------------------"

fi

exit 0

fi

#!/bin/sh

cd /usr/local/sbin

test -e "checkweb.php" && rm -rf checkweb.php

test -e "checkdb.php" && rm -f checkdb.php

test -e "wget-log" && rm -f wget-log

test -e "wget-log.1" && rm -f wget-log.1

wget -b "http://127.0.0.1/checkweb.php" > /dev/null 2>&1

wget -b "http://127.0.0.1/checkdb.php" > /dev/null 2>&1

sleep 2

checkweb=`cat checkweb.php`

checkdb=`cat checkdb.php`

if

[ "$checkweb" == "ok" ] ;then

echo "`date +%d/%m/%Y:%H:%M:%S` - - Webserver successfully!"

if

[ "$checkdb" == "ok" ] ;then

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected successfully!"

echo " "

echo "-------------------------------------------------------------"

elif

[ "$checkdb" != "ok" ] ;then

/etc/init.d/mysqld restart

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected bad!restart successful!"

curl "http://sms.api.bz/fetion.php?username=150********&password=******&sendto=150********&message=php连接数据库失败,数据库重启成功!"

echo " "

echo "-------------------------------------------------------------"

fi

exit 0

elif

[ "$checkweb" != "ok" ] ;then

killall -9 nginx

/usr/local/nginx/sbin/nginx

/usr/local/php-fcgi/sbin/php-fpm restart

echo "`date +%d/%m/%Y:%H:%M:%S` - - Webserver is down!restart successfully!"

wget -b "http://127.0.0.1/checkdb.php" > /dev/null 2>&1

sleep 2

checkdb2=`cat checkdb.php`

if

[ "$checkdb2" == "ok" ] ;then

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected successfully!"

curl "http://sms.api.bz/fetion.php?username=150********&password=******&sendto=150********&message=php服务器down机,重启成功!"

echo " "

echo "-------------------------------------------------------------"

elif

[ "$checkdb2" != "ok" ] ;then

/etc/init.d/mysqld restart

echo "`date +%d/%m/%Y:%H:%M:%S` - - Mysql connected bad!restart successful!"

curl "http://sms.api.bz/fetion.php?username=150********&password=******&sendto=150********&message=php服务器,mysql服务器down机,重启成功!"

echo " "

echo "-------------------------------------------------------------"

fi

exit 0

fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值