用途:检测php-fpm、nginx、mysql进程是否正常,如果不正常,则重启服务!
#!/bin/bash
logpath=/home/scripts
url="**b.g**yz.com/index.php"
status=$(/usr/bin/curl -s --head "$url" | awk '/HTTP/ {print $2}')
if [ "$status" != "200" ] ; then
echo `date` > ${logpath}/nginxphpmysqlcheck.log 2>&1
/etc/init.d/php-fpm restart >> ${logpath}/nginxphpmysqlcheck.log 2>&1
/etc/init.d/nginx restart >> ${logpath}/nginxphpmysqlcheck.log 2>&1
fi
/data/mysql/bin/mysqladmin -uroot -p*** ping > ${logpath}/mysqlstatus.txt 2>&1
cat ${logpath}/mysqlstatus.txt | grep failed > ${logpath}/mysqlstatusfail.txt
if [ -s ${logpath}/mysqlstatusfail.txt ] ; then
echo "I will restart mysqld" >>${logpath}/nginxphpmysqlcheck.log 2>&1
service mysqld start
fi
工作中的脚本,备份只用!
这个脚本有时候有问题,在负载高的时候有问题的,我修改为:
[root@loldb scripts]# cat nginxphpmysqlcheck.sh
#!/bin/bash
logpath=/home/scripts
url="***b.g****z.com/index.php"
status=$(/usr/bin/curl -s --head "$url" | awk '/HTTP/ {print $2}')
if [ "$status" != "200" ] ; then
echo `date` > ${logpath}/nginxphpmysqlcheck.log 2>&1
killall -9 php-fpm ##如果不使用这个不能瞬间释放掉9000端口,再次启动的时候会提示9000端口在占用,造成不能成功重启
killall -9 nginx
sleep 30
/etc/init.d/php-fpm start >> ${logpath}/nginxphpmysqlcheck.log 2>&1
/etc/init.d/nginx start >> ${logpath}/nginxphpmysqlcheck.log 2>&1
fi
/data/mysql/bin/mysqladmin -uroot -pkuutown1601 ping > ${logpath}/mysqlstatus.txt 2>&1
cat ${logpath}/mysqlstatus.txt | grep failed > ${logpath}/mysqlstatusfail.txt
if [ -s ${logpath}/mysqlstatusfail.txt ] ; then
echo "I will restart mysqld" >>${logpath}/nginxphpmysqlcheck.log 2>&1
service mysqld start
fi
阅读(1782) | 评论(1) | 转发(0) |