请提前准备好相关软件包
apr源码包
apr-util源码包
httpd源码包
Apache官网
#!/bin/bash
#
#********************************************************************
#Author: Wuvikr
#QQ: 744123155
#Date: 2020-10-27
#FileName aaa.sh
#URL: http://www.wuvikr.com
#Description The test script
#Copyright (C): 2020 All rights reserved
#********************************************************************
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
. /etc/init.d/functions
cpu=`lscpu | sed -rn ‘s/^CPU\(s\)[^0-9]+([0-9]+)/\1/p‘`
apr_version=apr-1.7.0.tar.bz2
apr_util_version=apr-util-1.6.1.tar.bz2
httpd_version=httpd-2.4.46.tar.bz2
apr_name=${apr_version%.tar*}
apr_util_name=${apr_util_version%.tar*}
httpd_name=${httpd_version%.tar.*}
install_dir=/apps/httpd24
echo -e ‘\e[1;32m开始安装httpd,请稍候...\e[0m‘
install_httpd(){
# 安装依赖包
echo -e ‘\e[1;32m正在安装相关依赖包...\e[0m‘
yum -y install wget gcc make pcre-devel openssl-devel expat-devel &> /dev/null || { action "依赖包安装失败,请检查网络和yum源!" false; exit ; }
# 解压
echo -e ‘\e[1;32m开始解压...\e[0m‘
[ -e ${apr_version} ] && tar xf ${apr_version} || { action "没有找到${apr_version},安装失败!" false; exit ; }
[ -e ${apr_util_version} ] && tar xf ${apr_util_version} || { action "没有找到${apr_util_version},安装失败!" false; exit ; }
[ -e ${httpd_version} ] && tar xf ${httpd_version} || { action "没有找到${httpd_version},安装失败!" false; exit ; }
# 合并源码,共同编译安装
echo -e ‘\e[1;32m开始编译Httpd...\e[0m‘
mv ${apr_name} ${httpd_name}/srclib/apr
mv ${apr_util_name} ${httpd_name}/srclib/apr-util
cd ${httpd_name}
./configure --prefix=${install_dir} --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
make -j $cpu &> /dev/null && action "Httpd 编译成功!" || { action "Httpd 编译安装失败!" false; exit; }
make install &> /dev/null
}
config_httpd(){
echo -e ‘\e[1;32m开始配置Httpd相关设置...\e[0m‘
# 创建apache账户
useradd -r -s /sbin/nologin apache
# 修改配置文件
sed -ri ‘s/^(User ).*/\1apache/‘ ${install_dir}/conf/httpd.conf
sed -ri ‘s/^(Group ).*/\1apache/‘ ${install_dir}/conf/httpd.conf
# 配置环境变量
echo "PATH=${install_dir}/bin:\$PATH" > /etc/profile.d/httpd.sh
# 配置man帮助
echo "MANDATORY_MANPATH ${install_dir}/man" >> /etc/man_db.conf
# 创建service文件
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
ExecStart=${install_dir}/bin/apachectl start
ExecReload=${install_dir}/bin/apachectl graceful
ExecStop=${install_dir}/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
# 开机启动
systemctl enable --now httpd.service &> /dev/null
action "Httpd 编译安装完成!!!"
}
install_httpd
config_httpd
源码编译安装apache2.4脚本