一键源码编译安装httpd

一键源码编译安装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

再去网页上验证
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值