#!/bin/bash##********************************************************************#Author: llliuhuiii#QQ: 1694993508#Date: 2020-10-27#FileName: install_httpd.sh#URL: http://www.lianlianlianlian.cn#Description: The test script#Copyright (C): 2020 All rights reserved#********************************************************************
target_dir=/usr/local/src
install_dir=/apps/httpd
#安装相关包
yum -y installwget gcc make pcre-devel openssl-devel expat-devel
rpm -q wget||yum -y installwget#下载源代码并解压缩wget -P $target_dir https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget -P $target_dir https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget -P $target_dir https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
cd$target_dirtar xf httpd-2.4.46.tar.gz
tar xf apr-1.7.0.tar.gz
tar xf apr-util-1.6.1.tar.gz
mv apr-1.7.0 httpd-2.4.46/srclib/apr
mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
cd httpd-2.4.46/
./configure --prefix=/apps/httpd --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&&makeinstall#创建apache用户useradd -r -s /sbin/nologin apache
#修改配置文件sed -i 's/^User.*/User apache/'${install_dir}/conf/httpd.conf
sed -i 's/^Group.*/Group apache/'${install_dir}/conf/httpd.conf
echo'PATH="/apps/httpd/bin:$PATH"'> /etc/profile.d/httpd.sh
/etc/profile.d/httpd.sh
echo'MANDATORY_MANPATH /apps/httpd/man'>> /etc/man_db.conf
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/httpd/bin/apachectl start
ExecReload=/apps/httpd/bin/apachectl graceful
ExecStop=/apps/httpd/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