#!/bin/sh
. /etc/init.d/functions
#相关软件包
PACKAGE="
deltarpm
gcc
make
pcre-devel
openssl-devel
expat-devel
bzip2
wget
"
#安装目录
FILE=/apps/httpd
#当前目录
ML=`pwd`
#相关软件安装
for PACK in $PACKAGE;do
rpm -q $PACK &> /dev/null || yum -y -q install $PACK
done
#下载相关源码包
wget https://downloads.apache.org//apr/apr-1.7.0.tar.bz2 &> /dev/null
wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2 &> /dev/null
wget https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2 &> /dev/null
#解压相关源码包
tar xf httpd-2.4.46.tar.bz2
tar xf apr-1.7.0.tar.bz2 && mv apr-1.7.0 ${ML}/httpd-2.4.46/srclib/apr
tar xf apr-util-1.6.1.tar.bz2 && mv ${ML}/apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
#编译
[ -d $FILE ] || mkdir -p $FILE
cd ${ML}/httpd-2.4.46/
./configure --prefix=$FILE --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 &> /dev/null && action "编译完成" || { action "编译失败" false; exit; }
#安装
make &> /dev/null && { make install &> /dev/null; action "httpd安装完成"; }
#创建用户
id apache &> /dev/null || useradd -s /sbin/nologin -r apache
#修改配置文件中的启动用户
sed -i 's/^User.*/User apache/' ${FILE}/conf/httpd.conf
sed -i 's/^Group.*/Group apache/' ${FILE}/conf/httpd.conf
#配置环境变量
echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
#配置man帮助
echo 'MANDATORY_MANPATH /apps/httpd/man' >> /etc/man_db.conf
#创建服务启动文件
cat > /usr/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
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/apps/httpd/bin/apachectl start
#ExecStart=/apps/httpd/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd/bin/apachectl graceful
#ExecReload=/apps/httpd/bin/httpd $OPTIONS -k graceful
ExecStop=/apps/httpd/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
#启动服务
systemctl daemon-reload
systemctl enable --now httpd.service &> /dev/null && action "httpd服务启动成功" || action "httpd服务启动失败,请检查配置文件" false