shell一键编译安装httpd

该脚本由LiangDong编写,用于在Linux系统中自动化编译安装Apache HTTPD服务器。首先,它下载必要的依赖包,如APR和APRUtil,然后配置编译选项并进行编译安装。最后,创建Apache用户,修改配置文件,并设置环境变量和服务单元文件以实现开机启动。
摘要由CSDN通过智能技术生成

shell一键编译安装httpd

#!/bin/bash
#
#####################################################################
#
#Author:                LiangDong
#Email:                 395539184@qq.com
#Date:                  2021-05-28
#FileName:             install_httpd.sh
#URL:                   https://github.com/ledrsnet
#Description:          
#Copyright (C):         2021 All rights reserved
#
#####################################################################

declare -A packages=([APR_URL]=https://downloads.apache.org/apr/apr-1.7.0.tar.bz2 \
[APR_UTIL_URL]=https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2 \
[HTTPD_URL]=https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2 )

APR_DIR=`echo ${packages[APR_URL]}|sed -nE 's#^.*/(.*).tar.*#\1#p'`
APR_UTIL_DIR=`echo ${packages[APR_UTIL_URL]}|sed -nE 's#^.*/(.*).tar.*#\1#p'`
HTTPD_URL_DIR=`echo ${packages[HTTPD_URL]}|sed -nE 's#^.*/(.*).tar.*#\1#p'`
CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'`

#echo ${APR_DIR}
#echo ${APR_UTIL_DIR}
#echo ${HTTPD_URL_DIR}
#echo ${#packages[*]}

preCompile(){
echo 安装相关编译环境包..
if [ `awk -F'"' '/^ID=/{print $2}' /etc/os-release` == "centos" ] &> /dev/null;then
 yum -y install gcc make pcre-devel openssl-devel expat-devel wget bzip2
else
 apt update
 apt -y install gcc make libapr1-dev libaprutil1-dev libpcre3 libpcre3-dev libssl-dev wget
fi
for i in ${packages[*]};do
    wget $i
    tar xf ${i##*/}
done
mv ${APR_DIR} ${HTTPD_URL_DIR}/srclib/apr
mv ${APR_UTIL_DIR} ${HTTPD_URL_DIR}/srclib/apr-util
echo 准备完成..
}
compile(){
echo 开始编译....
cd ${HTTPD_URL_DIR}
./configure \
--prefix=/apps/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

make -j $CPUS && make install
echo 编译完成..
}

postCompile(){
# 创建apache账户
id apache &> /dev/null || useradd -r -s /sbin/nologin apache
# 修改配置文件
sed -i 's/^User.*/User apache/' /apps/httpd24/conf/httpd.conf
sed -i 's/^Group.*/Group apache/' /apps/httpd24/conf/httpd.conf
# 配置环境变量
echo 'PATH="/apps/httpd24/bin:$PATH"' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
# 配置man帮助
echo 'MANDATORY_MANPATH  /apps/httpd/man' >> /etc/man_db.conf
# 创建service unit文件,设置开机启动
cat > /lib/systemd/system/httpd.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
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now httpd.service
}



preCompile
compile
postCompile
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清枫cc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值