httpd 一键编译安装脚本

#!/bin/bash
#***********************************************************
#author :sissi
#date :2020-02-28
#QQ :1755639522
#Description :this script is to install http one shoot
#***********************************************************

CENTOS_VER=`egrep -wo '[0-9]+' /etc/centos-release | head -n 1`

httpd_list(){
echo "
which httpd version would you like to install:
**********************************************
httpd-2.2.18
httpd-2.2.20
httpd-2.2.26
httpd-2.4.37
or you can input other version
quit | q
**********************************************
"
}

BASE_DIR="/web"

check_pre(){
if[ -d ${BASE_DIR}/${1} ];then
echo "${1} has been installed!"
exit
fi
}

change_yum(){
mkdir /etc/yum.repos.d/lod
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/old
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Cento
s-${CENTOS_VER}.repo
wget -O /etc/yum.repos.d/epel/repo http://mirrors.aliyun.com/repo.com/repo/epel-${C
ENTOS_VER}.repo
}

env_pre(){
LISTNO="${1}"
###an zhuang qi ta bi yao de yi lai
yum clean all
yum groupinstall "Development Tools" -y
DEP_LIST1="gcc glibc apr-devel apr-util-devel pcre-devel openssl-devel expat-devel make"
DEP_LIST2="gcc glibc pcre-devel openssl-devel expat-devel make"
if[ $LISTNO == "1" ];then
for dep in "${DEP_LIST1}";do
rpm -q "${dep}" &> /dev/null || yum install $dep -y
done
elif [ $LISTNO == "2" ];then
for dep in "${DEP_LIST2}";do
rpm -q "${dep}" &> /dev/null || yum install $dep -y
done
fi
}

get_http_package(){
HTTP_VER=$1
[ -f ${HTTP_VER}.tar.bz2 ] || wget -t 5 -w 10
https://archive.apache.org/dist/httpd/${HTTP_VER}.tar.bz2
tar xf ${HTTP_VER}.tar.bz2 &>/dev/null || exit
}

install(){
INSTALL_DIR="$1"
WITH_APR="$2"
[ ! -d ${BASE_DIR} ] && mkdir -p ${BASE_DIR}
./configure --prefix=${BASE_DIR}/${INSTALL_DIR} \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpms=prefork ${WITH_APR} && \
make -j 4 && make install && \
ln -s ${INSTALL_DIR} ${BASE_DIR}/httpd
id apache || useradd -r -s /sbin/nologin apache
cp ${BASE_DIR}/httpd/conf/httpd.conf{,.bak}
sed -ri "/^#ServerName/s/^#//" ${BASE_DIR}/httpd/conf/httpd.conf
sed -ri "/^#ServerName/s/^#//" ${BASE_DIR}/httpd/conf/httpd.conf

}

get_httpd_init(){
HTTPD_INIT="$1"
if [ -f ${HTTPD_INIT} ];then
if [ ! -f /etc/init.d/${HTTPD_INIT} ];then
/cp ${HTTPD_INIT} /etc/init.d/${HTPPD_INIT}
chmod +x /etc/init.d/${HTTPD_INIT}
chkconfig --add ${HTTPD_INIT} ;chkconfig ${HTTPD_INIT} on
return 0
else
echo "/etc/init.d/${HTTPD_INIT} exsit." ;return 1
fi
else
echo "${HTTPD_INIT} not found,make it by yourself." ;return 1
fi
}

main(){
httpd_list
read -p "please select version:" httpd_version
case "$1" in
6)
case "$httpd_version" in
httpd-2.4.[2-3][6-7])
check_pri $http_version
change_yum
env_pre 2
get_http_package $http_version
APR_DEPS="apr-1.6.5 apr-util-1.6.1"
for apr_dep in ${APR_DEPS};do
[ -f ${apr_dep}.tar.bz2 ] || wget -t 5 -w 10
http://mirrors.tuna.tsinghua.edu.cn/apache/apr/${apr_dep}.tar.bz2
tar xf ${apr_dep}.tar.bz2 &>/dev/null
if [ $? -ne 0 ];then
echo "${apr_dep}.tar.bz2 download failed";exit
fi
done
cp -av apr_1.6.5 ${http_version}/srclib/apr
cp -av apr-util-1.6.1 ${http_version}/srclib/apr-util
cd $http_version
install $http_version --with-included-apr
cd ../
echo export PATH=${BASE_DIR}/httpd/bin:'$PATH' > /etc/profile.d/httpd24.sh
. /etc/profile.d/httpd24.sh
grep "MANPATH ${BASE_DIR}/httpd/man" /etc/man.conf || echo "MANPATH ${BASE_DIR}/httpd
/man" >> /etc/man.config
get_httpd_init httpd && /etc/init.d/httpd start
;;

httpd-2.2.[1-2-3][0-1-2-3-4-5-6-7-8-9])
check_pre $http_version
change_yum
env_pre1
get_http_package $http_version && cd $http_version
install $http_version
cd ../
echo export PATH=${BASE_DIR}/httpd/bin:'$PATH' > /etc/profile.d/httpd22.sh
. /etc/profile.d/httpd22.sh
grep "MANPATH ${BASE_DIR}/httpd/man" /etc/man.config || echo "MANPATH ${BASE_DIR}/htt
pd/man" >> /etc/man.config
get_httpd_init httpd && /etc/init.d/httpd start
;;

quit|q)
echo "Bye" && exit
;;

*)
echo "do not support this version" && exit
;;

esac
;;
7)
case "$http_version" in
httpd-2.2.[2][6-7-8-9]|httpd-2.4.[1-2-3-4][0-1-2-3-4-5-6-7-8-9])
check_pre $http_version
change_yum
env_pre 1
get_http_package $http_version && cd $http_version
install $http_version
cd ../
echo export PATH=${BASE_DIR}/httpd/bin:'$PATH' > /etc/profile.d/httpd24.sh
. /etc/profile.d/httpd24.sh
grep "MANDATORY_MANPATH ${BASE_DIR}/httpd/man" /etc/man_db.conf || echo "MANDATORY_MA
NPATH ${BASE_DIR}/httpd/man" >> /etc/man_db.conf
httpd -t && httpd
;;

quit|q)
echo "Bye" && exit
;;

*)
echo "do not support this version" && exit
;;

esac
esac

}
main $CENTOS_VER

 

 

 

 

本文链接:https://www.cnblogs.com/shichangming/p/10153464.html

posted @ 2020-02-29 11:12  偷懒曦  阅读(310)  评论(0编辑  收藏  举报