**环境准备
准备一台Centos7服务器
系统: Centos7.3
内存:1G
cpu: 2核
IP地址: 10.0.0.41**
vim jk_httpd.sh
#!/bin/bash
while true
do
port_num=$(ss -ntl | grep -c 80)
if [ $port_num -eq 0 ];then
echo "httpd服务已经停止运行!"
/usr/local/sbin/mail.py 1052802235@qq.com "警告! ! " "httpd服务已经停止运行! "
num=1
while [ $num -le 30 ]
do
sleep 2
port_num=$(ss -ntl | grep -c 80)
if [ $port_num -eq 1 ];then
echo "httpd服务恢复! "
/usr/local/sbin/mail.py 1052802235@qq.com "恢复 " "httpd服务已经恢复运行! "
break
fi
let num++
done
fi
sleep 5
done
sh jk_httpd.sh
# 停止阿帕奇服务
systemctl stop httpd

# 启动阿帕奇服务
systemctl start httpd

本文介绍了一个用于Centos7系统中httpd服务的监控与自动重启脚本。该脚本会定期检查httpd服务的状态,如果发现服务停止,将发送邮件警告并尝试自动重启服务,直至服务恢复正常。
601

被折叠的 条评论
为什么被折叠?



