#!/bin/bash
######
#Autho: tyzh
#Date: 2020-06-17
######
####安装前检查####
CurrentVersion=`httpd -v|head -1`
colorGreen=" 33[32m"
colorRed=" 33[31m"
colorEnd=" 33[0m"
###判断是否有运行的httpd服务#####
netstat -tnlp|grep httpd
if [ $? = 1 ];then
echo "当前版本为:$CurrentVersion"
read -p "请再次确认,是否要安装httpd2.4.43(yes/no)? $colorend" INPUT
INPUT=`echo $INPUT|tr 'A-Z' 'a-z'`
case $INPUT in
n|no)
exit 1
;;
y|yes)
echo "安装httpd2.4.43准备安装......"
;;
*)
echo 'Input fales,plese input yes or no'
;;
esac
else
echo "警告需要先停掉目前服务,再继续安装,apachectl -k stop"
read -p "请再次确认,是否要安装httpd2.4.43(yes/no)?" INPUT
INPUT=`echo $INPUT|tr 'A-Z' 'a-z'`
case $INPUT in
n|no)
exit 1
;;
y|yes)
echo "安装httpd2.4.43准备安装......"
apachectl -k stop
;;
*)
echo 'Input fales,plese input yes or no'
;;
esac
fi
sleep 5s
####安装依赖####
echo -e "$colorGreen yilai install starting.....$colorEnd"
yum -y install gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
if [ $? = 0 ];then
echo -e "$colorGreen yilai install finished.....$colorEnd"
else
echo -e "$colorRed yilai install false,please check your repo source!$colorEnd"
sleep 10s
exit 1
fi
sleep 5s
######添加apache用户,组#####
group apache
useradd -r -s /sbin/nologin -d /var/www/html apache
####安装httpd2.4.43包####
echo -e "$colorGreen httpd-2.4.43 starting......$colorEnd"
wget https://mirror.bit.edu.cn/apache//httpd/httpd-2.4.43.tar.bz2
tar xvf httpd-2.4.43.tar.bz2 -C /usr/local/src
cd /usr/local/src/httpd-2.4.43/
###配置httpd###
./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-ssl
###编译并安装####
make -j 2 && make install
echo -e "$colorGreen httpd-2.4.43 finished......$colorEnd"
####httpd启动环境配置,启动###
echo PATH=/usr/local/httpd/bin:$PATH > /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
sed -i 's/User daemon/User apache/' /etc/httpd/httpd.conf
sed -i 's/Group daemon/Group apache/' /etc/httpd/httpd.conf
###检查安装文件####
apachectl -t
####启动服务####
apachectl -k restart
echo 'httpd 服务已经启动.......'
echo $CurrentVersion