一键源码编译安装httpd-2.4.48
#!/bin/bash
#
#********************************************************************
#Author: LingXia
#QQ: 1589640561
#Date: 2021-07-08
#FileName: install_httpd.sh
#Copyright (C): 2021 All rights reserved
#********************************************************************
#直接关掉防火墙和SELINUX
#暂时未发现SELINUX的状态会影响httpd
systemctl disable --now firewalld
sed -r -i 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config
#检查firewalld状态
#firewall_status=`systemctl status firewalld.service | grep "Active" | awk '{print $2}'`
#if [ $firewall_status = active ];then
# echo "防火墙已启用,开放端口"
# firewall-cmd --permanent --add-service=http --add-service=https
# firewall-cmd --reload
#fi
#定义变量
DIR=/usr/local/src
INSTALLDIR=/apps/httpd
SYSCONFDIR=/etc/httpd
VERSION=2.4.48
SUFFIX=.tar.bz2
ERROR=/root/install_httpd_error.log
NULL=/dev/null
#安装必需的软件
SOFTWARES="wget bzip2 gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config"
for PACKAGE in $SOFTWARES ;do
rm -q ${PACKAGE} &> $NULL || yum -y install ${PACKAGE} &> $NULL
done
#yum install -y wget bzip2 gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config &> /dev/null
#下载解压
wget https://mirrors.cloud.tencent.com/apache/httpd/httpd-${VERSION}${SUFFIX} -P $DIR &> $NULL
#wget https://mirrors.cloud.tencent.com/apache/httpd/httpd-2.4.48.tar.bz2 -P /usr/local/src
ls $DIR/httpd-${VERSION}${SUFFIX} &> $NULL || { echo "httpd-${VERSION}${SUFFIX} 不存在,可能下载失败,请检查" ;exit; }
cd $DIR
tar xf $DIR/httpd-${VERSION}${SUFFIX}
#编译安装
cd $DIR/httpd-${VERSION}/
./configure --prefix=$INSTALLDIR --sysconfdir=$SYSCONFDIR --enable-ssl 1> $NULL 2> $ERROR
[ $? = 0 ] || { echo "编译失败,请查看文件$ERROR" ; exit; }
{ make -j `lscpu |sed -nr '4s/.*([0-9]+)/\1/p'` && make install; } 1> $NULL 2> $ERROR
[ $? = 0 ] || { echo "编译失败,请查看文件$ERROR" ; exit; }
#修改配置文件
sed -r -i 's/(.* )daemon$/\1apache/' $SYSCONFDIR/httpd.conf
mv ${INSTALLDIR}/htdocs/index.html ${INSTALLDIR}/htdocs/index.html.bak
cp /root/index.html.bak ${INSTALLDIR}/htdocs/index.html
#注意:/root/index.html.bak 这个文件要事先保存在root目录下,修改后支持中文显示
#配置变量环境
echo 'PATH='$INSTALLDIR'/bin:$PATH' > /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
#启动http
apachectl -k start
粗略的实现,没优化
查看httpd是否运行
[root@centos8 ~]# ps aux |grep httpd
root 29672 0.0 0.3 118996 5524 ? Ss 22:14 0:00 /apps/httpd/bin/httpd -k start
apache 29673 0.0 0.4 1339620 7668 ? Sl 22:14 0:00 /apps/httpd/bin/httpd -k start
apache 29674 0.0 0.6 1339620 11748 ? Sl 22:14 0:00 /apps/httpd/bin/httpd -k start
apache 29675 0.0 0.5 1339620 9708 ? Sl 22:14 0:00 /apps/httpd/bin/httpd -k start
root 29758 0.0 0.0 12136 1148 pts/0 S+ 22:15 0:00 grep --color=auto httpd
再去网页上验证