#/bin/bash
# AUTHOR wanglanfeng
# DATE 2024-4-18
# THEME judgment apache server
#判断apache是否安装
rpm -qa|grep httpd-2.4.6
if [ $? -eq 0 ]
then
echo "apache已安装"
active=`systemctl status httpd | awk /Active/'{print $2}'`
if [ $active = "active" ] # 判断apache是否运行
then
echo "apache正在运行"
else
echo "apache没有运行"
fi
else # apache没有安装
echo "安装apache"
yum install -y httpd >> /dev/null
echo "启动apache"
systemctl start httpd >> /dev/null
if [ $? -eq 0 ]
then
echo "apache服务启动成功"
else
echo "apache服务启动失败"
ss -tlnp|grep 80|grep httpd < /dev/null #80端口是否占用
if [ $? -eq 0 ];then
echo "请检查apache配置文件"
else
echo "尝试停止nginx,启动apache"
systemctl stop nginx
systemctl start httpd
echo "apache已成功启动"
fi
fi
fi
#/bin/bash
# AUTHOR wanglanfeng
# DATE 2024-4-18
# THEME judgment apache server
cat << EFO
##########################################
#### judgment apache server ####
##########################################
# 1 检查服务器上有没有apach包 #
# 2 安装 apache服务 #
# 3 apache是否在运行 #
# 4 start apache #
# 5 检查port_80是否被占用 #
# 6 停止nginx服务&&开启apache服务 #
##########################################
EFO
while 1>0
do
read -p "inputing you want to step:" var
case "$var" in
1) # 检查服务器上有没有httpd包
rpm -qa |grep httpd-2.4.6
if [ $? -eq 0 ]
then
echo "服务器上有httpd包"
else
echo "服务器上没有httpd包,建议执行步骤2"
fi
;;
2) # install httpd
yum install -y httpd > /dev/null
echo "apache服务已安装"
;;
3) # apache is running?
active=`systemctl status httpd | awk /Active/'{print $2}'` > /dev/null
if [ "$active" = "active" ] # 判断apache是否运行
then
echo "apache服务正在运行"
else
echo "apache服务没有运行,建议执行步骤4"
fi
;;
4) # apache是否启动
systemctl start httpd &> /dev/null
if [ $? = 0 ];then
echo "apache服务已启动"
else
echo "apache服务启动失败,检查服务器有没有apache包,否则执行5 "
fi
;;
5) # 检查 port_80是否被nginx占用
ss -tlnp|grep 80|grep nginx > /dev/null #80端口是否占用
if [ $? -eq 0 ];then
echo "尝试停止nginx,启动apache,建议执行步骤6"
else
echo "执行步骤3,查看apache是否运行,否则请检查apache配置文件"
fi
;;
6) #stop nginx && start apache server
systemctl stop nginx
echo "nginx已关闭"
systemctl start httpd
echo "apache已启动"
;;
*)
exit
;;
esac
done