httpd 一键编译安装脚本(centos6&7_httpd2.2&2.4)

Posted

scm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpd 一键编译安装脚本(centos6&7_httpd2.2&2.4)相关的知识,希望对你有一定的参考价值。

httpd 一键编译安装脚本(centos6&7_httpd2.2&2.4)

说明

此安装脚本中涉及的服务启动脚本需要单独编写 : httpd启动脚本 https://www.cnblogs.com/shichangming/p/10154936.html

httpd_install.sh

#!/bin/bash
# *****************************************************
# author     : shchangming
# date       : 2018-06-06
# QQ         : 414945814
# 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/old
	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/Centos-${CENTOS_VER}.repo
	wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-${CENTOS_VER}.repo
}

env_pre() {
	LISTNO="${1}"
	### 安装其他必要的依赖
	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-mpm=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 "/^(User|Group)/s/daemon/apache/" ${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/${HTTPD_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:"  http_version
case "$1" in
	6)
		case "$http_version" in
			httpd-2.4.[2-3][6-7])
				check_pre $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.config || 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_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/httpd22.sh
				. /etc/profile.d/httpd22.sh
				grep "MANPATH ${BASE_DIR}/httpd/man" /etc/man.config || echo "MANPATH ${BASE_DIR}/httpd/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_MANPATH ${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

以上是关于httpd 一键编译安装脚本(centos6&7_httpd2.2&2.4)的主要内容,如果未能解决你的问题,请参考以下文章

LAMP 之 自动化编译安装

一键编译安装lamp

centos6 编译安装httpd-2.4

centos6 编译安装httpd-2.4方法二

centos6.9编译安装httpd2.4

HTTP 之 编译安装HTTPD2.4