Apache自动化安装脚本

小柒博客
小柒博客
小柒博客
313
文章
93
评论
2020-04-0716:33:29 评论 4.2K 3361字阅读11分12秒

此脚本是Apache安装脚本,有需要朋友可以参考,脚本内容如下:

系统环境:CentOS 7.4

软件版本:2.4.29

[root@localhost ~]# vim auto_install_apache.sh

#!/bin/bash
#2020-3-13 11:30:44
#By:YangXingZhen
#Auto Install Apache

source /etc/rc.d/init.d/functions

#Define APR path variables
APR_URL=http://mirrors.yangxingzhen.com/apr
APR_FILES=apr-1.7.0.tar.gz
APR_FILES_DIR=apr-1.7.0
APR_PREFIX=/usr/local/apr

#Define APR-util path variables
APR_UTIL_URL=http://mirrors.yangxingzhen.com/apr-util
APR_UTIL_FILES=apr-util-1.6.1.tar.gz
APR_UTIL_FILES_DIR=apr-util-1.6.1
APR_UTIL_PREFIX=/usr/local/apr-util

#Define PCRE path variables
PCRE_URL=http://mirrors.yangxingzhen.com/pcre
PCRE_FILES=pcre-8.41.tar.gz
PCRE_FILES_DIR=pcre-8.41
PCRE_PREFIX=/usr/local/pcre

#Define Apache path variables
APACHE_URL=http://mirrors.yangxingzhen.com/apache
APACHE_FILES=httpd-2.4.39.tar.gz
APACHE_FILES_DIR=httpd-2.4.39
APACHE_PREFIX=/usr/local/apache
APACHE_INIT_FILE=/etc/init.d/httpd

source /etc/rc.d/init.d/functions

function Install_apr (){
#Install APR
if [ ! -d ${APR_PREFIX} ];then
	yum -y install gcc gcc-c++ wget
	wget -c ${APR_URL}/${APR_FILES}
	tar zxf ${APR_FILES}
	cd ${APR_FILES_DIR}
	./configure --prefix=${APR_PREFIX}
	if [ $? -eq 0 ];then
		make && make install
		action "The APR Install Sussess..." /bin/true
	else
		action "The APR Install Failed..." /bin/false 
		exit 1
	fi
else
	echo -e "\033[31mThe APR already Install...\033[0m"
fi
}

function Install_apr_util (){
#Install APR-util
if [ ! -d ${APR_UTIL_PREFIX} ];then
	yum -y install expat expat-devel
	wget -c ${APR_UTIL_URL}/${APR_UTIL_FILES}
	tar zxf ${APR_UTIL_FILES}
	cd ${APR_UTIL_FILES_DIR}
	./configure --prefix=${APR_UTIL_PREFIX} --with-apr=${APR_PREFIX}
	if [ $? -eq 0 ];then
		make && make install
		action "The APR-util Install Sussess..." /bin/true
	else
		action "The APR-util Install Failed..." /bin/false 
		exit 1
	fi
else
	echo -e "\033[31mThe APR-util already Install...\033[0m"
fi
}

function Install_pcre (){
#Install PCRE
if [ ! -d ${PCRE_PREFIX} ];then
	wget -c ${PCRE_URL}/${PCRE_FILES}
	tar zxf ${PCRE_FILES}
	cd ${PCRE_FILES_DIR}
	./configure --prefix=${PCRE_PREFIX}
	if [ $? -eq 0 ];then
		make && make install
		action "The Pcre Install Sussess..." /bin/true
	else
		action "The Pcre Install Failed..." /bin/false 
		exit 1
	fi
else
	echo -e "\033[31mThe Pcre already Install...\033[0m"
fi
}

function Install_apache (){
#Install Apache
if [ ! -d ${APACHE_PREFIX} ];then
	yum -y install expat expat-devel openssl openssl-devel
	wget -c ${APACHE_URL}/${APACHE_FILES}
	tar zxf ${APACHE_FILES}
	cd ${APACHE_FILES_DIR}
	./configure --prefix=${APACHE_PREFIX} \
	--with-apr=${APR_PREFIX} \
	--with-apr-util=${APR_UTIL_PREFIX} \
	--enable-so \
	--enable-rewrite \
	--enable-ssl \
	--with-pcre=${PCRE_PREFIX} \
	--with-mpm=worker 
	if [ $? -eq 0 ];then
		make && make install
		action "The Apache Install Sussess..." /bin/true
	else
		action "The Apache Install Failed..." /bin/false 
		exit 1
	fi
else
	echo -e "\033[31mThe Apache already Install...\033[0m"
	exit 1
fi
}

function Config_apache (){
#config apache
\cp $APACHE_PREFIX/bin/apachectl /etc/init.d/httpd
chmod o+x /etc/init.d/httpd
echo "ServerName localhost:80" >>${APACHE_PREFIX}/conf/httpd.conf
service httpd start
}

function Config_iptables (){
#iptables(firewalld)、selinux config
SYSTEM_VERSION=`awk -F. '{print $1}' /etc/redhat-release |awk '{print $NF}'`
if [ $SYSTEM_VERSION -eq 6 ];then
	service iptables stop
	chkconfig iptables off
	sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
	setenforce 0
else
	systemctl stop firewalld.service
	systemctl disable firewalld.service
	sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
	setenforce 0
fi
}

function main (){
	Install_apr
	Install_apr_util
	Install_pcre
	Install_apache
	Config_apache
	Config_iptables
}
main

脚本执行方式:

[root@localhost ~]# sh auto_install_apache.sh

继续阅读
  • 微信号
  • 微信扫一扫加我!
  • weinxin
  • 微信公众号
  • 微信扫一扫关注我!
  • weinxin
小柒博客
  • 本文由 发表于 2020-04-0716:33:29
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: