一、编译安装httpd

1.下载相关包

wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.5.tar.gz
wget  https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz

2.安装依赖

yum install gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config  expat-devel

3.编译apr和apr-util

#编译apr
tar zxf apr-1.6.5.tar.gz
cd  apr-1.6.5
./configure --prefix=/usr/local/apr
make -j && make install
cd ../

#编译apr-util(依赖apr,需先编译apr)
tar zxf apr-util-1.6.1.tar.gz
 cd apr-util-1.6.1/
./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr

make -j 
#报错
libtool: warning: library '/usr/local/apr/lib/libapr-1.la' was moved.
vim /usr/local/apr/lib/libapr-1.la
解决:
vim /usr/local/apr/lib/libapr-1.la
修改最后一行为自定义的安装路径
libdir='/usr/local/apr/lib'

make -j  && make install

4.编译httpd,搭建本地base仓库

cd ../
tar zxf httpd-2.4.46.tar.gz
cd  httpd-2.4.46/

./configure --prefix=/usr/local/httpd  \
--sysconfdir=/etc/httpd  \
--enable-ssl  \
--with-apr=/usr/local/apr  \
--with-apr-util=/usr/local/apr-util

make -j
#报错
libtool:   error: cannot find the library '/usr/local/apr1.6.5/lib/libapr-1.la' or unhandled argument '/usr/local/apr1.6.5/lib/libapr-1.la'

#解决,修改文件把路径修改为自定义的安装路径
vim /usr/local/apr-util/lib/libaprutil-1.la
dependency_libs=' -lexpat /usr/local/apr/lib/libapr-1.la -lrt -lcrypt -lpthread -ldl'

make -j && make install

#配置环境变量
echo 'export PATH=/usr/local/httpd/bin:$PATH' >> /etc/profile
. /etc/profile

#修改站点目录
 vim /etc/httpd/httpd.conf
![图片说明](https://uploadfiles.nowcoder.com/images/20210729/498282651_1627570307126/8B45C8FFEE54C0152E1E45F98FACCC9A "图片标题") 
DocumentRoot "/www"
<Directory "/www">

mkdir  /www/base
mount /dev/sr0  /www/base
#启动
apachectl start

#客户端配置base源
cat > base.repo <<EO
[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.88.11/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EO

yum clean all
yum makecache
yum repolist

5.搭建本地epel仓库

#配置网络epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

#下载网络epel仓库的包和元数据
yum install yum-utils -y
reposync  -r  epel  --download-metadata   -p   /www/
#下载key
wget  -P /www/epel/   https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7

#客户端配置epel源
cat >/etc/yum.repo.d/epel.repo <<EOF
[epel]
name=epel
baseurl=http://192.168.88.11/epel/
gpgkey=http://192.168.88.11/epel/RPM-GPG-KEY-EPEL-7
EOF

yum clean all
yum makecache
yum repolist