
6.7 基于HTTP构建YUM网络源
YUM光盘源默认只能本机使用,局域网其他服务器无法使用YUM光盘源,如果想使用的话,需要在每台服务器上构建YUM本地源,该方案在企业中不可取,所以需要构建HTTP局域网YUM源解决。可以通过createrepo创建本地YUM源端,repo即为repository。
构建HTTP局域网YUM源方法及步骤如下:
(1)挂载光盘镜像文件至/mnt。

(2)复制/mnt/Packages目录下所有软件包至/var/www/html/centos/。

(3)使用createrepo创建本地源,执行如下命令会在CentOS目录生成repodata目录,目录内容如图6-16所示。

图6-16 createrepo生成repodata目录

(4)利用HTTP发布YUM本地源。
本地YUM源通过createrepo搭建完毕,需要借助HTTP Web服务器发布/var/www/ html/centos/中所有软件,YUM或者RPM安装HTTP Web服务器,并启动httpd服务。详细步骤如下:
□yum install httpd httpd-devel -y:安装HTTP Web服务。
□useradd apache -g apache:创建Apache用户和组。
□systemctl restart httpd.service:重启httpd服务。
□setenforce 0:临时关闭SELinux应用级安全策略。
□systemctl stop firewalld.service:停止防火墙。
□ps -ef|grep httpd:查看httpd进程是否启动。
(5)在YUM客户端,创建/etc/yum.repos.d/http.repo文件,输入如下内容:

(6)在YUM客户端上执行以下命令,详解如下,结果如图6-17所示。

图6-17 HTTP YUM源客户端验证
□yum clean all:清空YUM cache。
□yum install ntpdate -y:安装ntpdate软件。