一键编译安装apache2.4脚本

一键安装apache2.4脚本

#!/bin/bash
#****************************************************
#Author:        阿俊(panda)
#QQ:            949786521
#Date:          
#Version:
#Discription:
#Color--help 基本格式 开始:\033[1;32m 结束:\033[0m
#30黑,31红,32绿,33黄,34蓝,35紫红,36青蓝,37白
#****************************************************
APACHE=https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.bz2
APNM=`echo ${APACHE} |sed -r 's#.*/([^/]+)\..*\..*$#\1#'`
APR=https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.bz2
APRNM=`echo ${APR} |sed -r 's#.*/([^/]+)\..*\..*$#\1#'`
UTIL=https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
UTILNM=`echo ${UTIL} |sed -r 's#.*/([^/]+)\..*\..*$#\1#'`
OSVERSION=`cat /etc/redhat-release |grep -o '[[:digit:]]' |head -1`


#创建用户和准备目录
function uradd (){
id apache &>dev/null || useradd -r -u 80 -d /var/www -s /sbin/nologin apache
[ -d /apps ] || mkdir /apps
}


#安装依赖包:
function denpendence () {
yum -y install gcc make pcre-devel bzip2 &>/dev/null
yum -y install openssl-devel expat-devel wget &>/dev/null
}
#下载apache2.4以及apr源码包并解压:
function getpackage () {
wget -P /usr/local/src ${APACHE} 
wget -P /usr/local/src ${APR} 
wget -P /usr/local/src ${UTIL} 
cd /usr/local/src
tar jxf httpd-2.4.46.tar.bz2 
tar jxf apr-1.7.0.tar.bz2
tar jxf apr-util-1.6.1.tar.bz2
}

#编译安装
function makeconfig (){
cd /usr/local/src
mv ${APRNM}  ${APNM}/srclib/apr
mv ${UTILNM}  ${APNM}/srclib/apr-util
cd /usr/local/src/${APNM}
./configure --prefix=/apps/httpd24 \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-inclde-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
make -j `lscpu |grep '^CPU(s)'|tr -s ' ' |awk -F: '{print $2}'` && make install
}

#设置环境变量
function env (){
echo 'PATH=/apps/httpd24/bin:$PATH' >/etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
}

#修改配置文件
function etc () {
echo 'user apache' >> /apps/httpd24/conf/httpd
echo 'group apache' >> /apps/httpd24/conf/httpd
echo 'MANDATORY_MANPATH	/apps/httpd24/man' >> /etc/man_db.conf
echo '/apps/httpd24/bin/apachectl start' >>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
}

#创建service unit文件
function startscript7 () {
cat > /usr/lib/systemd/system/httpd24.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
ExecStart=/apps/httpd24/bin/apachectl start
ExecReload=/apps/httpd24/bin/apachectl graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
}

function startscript6 () {
cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
cat > /etc/rc.d/init.d/httpd24 << EOF
apachectl=/apps/httpd24/bin/apachectl
httpd=${HTTPD-/apps/httpd24/bin/httpd}
pidfile=${PIDFILE-/apps/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
EOF
chkconfig -add httpd24
chkconfig -list httpd24
}

uradd
denpendence
getpackage
makeconfig
env
etc
if [ ${OSVERSION} -ge 7 ] ;then
startscript7
else
startscript6
fi
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值