此脚本是Apache安装脚本,有需要朋友可以参考,脚本内容如下:
系统环境:CentOS 7.9文章源自小柒网-https://www.yangxingzhen.cn/6685.html
软件版本:2.4.29文章源自小柒网-https://www.yangxingzhen.cn/6685.html
[root@localhost ~]# vim auto_install_apache.sh文章源自小柒网-https://www.yangxingzhen.cn/6685.html
#!/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
脚本执行方式:文章源自小柒网-https://www.yangxingzhen.cn/6685.html
[root@localhost ~]# sh auto_install_apache.sh文章源自小柒网-https://www.yangxingzhen.cn/6685.html 文章源自小柒网-https://www.yangxingzhen.cn/6685.html
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
继续阅读
Wechat
微信扫一扫,加我!
我的微信
微信号已复制
微信公众号
微信扫一扫,关注我!
我的公众号
公众号已复制
评论