在本文中,将介绍在 RHEL/CentOS 7 中通过网络使用 DVD 和 HTTP 或者 Apache 服务器配置离线 yum 存储库的步骤
我们需要一个基本的 http 服务器,因此安装所有与 http 相关的包。
在创建基于 http 的 yum 存储库之前,使用 RHEL/CentOS dvd 创建一个离线存储库。
使用 yum 安装 httpd rpm 及其依赖项
# yum install httpd -y
配置我们http服务器
编辑主要配置文件,例如:“/etc/httpd/conf/httpd.conf”并在文件末尾添加以下内容
注意:这里我将使用 /var/www/html 作为我的源路径,其中 RHEL/CentOS dvd 将被挂载。
我们可以根据需要相应地更改路径
Alias /web "/var/www/html/" <VirtualHost 192.168.1.6:80> ServerAdmin root@server.onitroad.com ServerName onitroad-server DocumentRoot /var/www/html ErrorLog logs/error_log <Directory "/var/www/html/"> Options Indexes MultiViews AllowOverride All Require all granted </Directory> </VirtualHost>
如果系统上运行了 firewalld,那么我们可以运行以下命令为 httpd 添加 firewalld 规则
# firewall-cmd --permanent --add-service=http success # firewall-cmd --reload success
重启你的 httpd 服务
# systemctl restart httpd
确保 RHEL/CentOS dvd 安装在源目录中,例如:/var/www/html
# mount /tmp/rhel-server-7.4-x86_64-dvd.iso /var/www/html/ mount: /dev/loop0 is write-protected, mounting read-only # ls /var/www/html/ addons EFI EULA extra_files.json GPL images isolinux LiveOS media.repo Packages repodata RPM-GPG-KEY-redhat-beta RPM-GPG-KEY-redhat-release TRANS.TBL
接下来尝试在浏览器上使用 http://192.168.1.6/web/访问 http 服务器
注意:将主机 IP (192.168.1.6) 替换为节点 IP
如果一切正常,请继续下一步,否则如果我们遇到任何问题,请关注“/etc/httpd/logs/error_log”以获取有关该问题的更多信息
是时候重新配置我们的 repo 文件了,“/etc/yum.repos.d/rhel.repo”,内容如下
[RHEL_Repo] name=Red Hat Enterprise Linux 7.4 baseurl=http://192.168.1.6/web/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
注意:默认情况下,gpg 密钥由 Red Hat 发行包安装在系统上,适用于安装类型,因此我们可以使用上述路径并确保它存在
如我们所见, baseurl 是我的 http 服务器,其中包含来自 rhel dvd 的 rpm。
接下来保存并退出文件。
接下来让我们清理缓存
# yum clean all Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Cleaning repos: RHEL_Repo Cleaning up everything Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos # rm -rf /var/cache/yum
现在让我们看看我们的新仓库是否按预期工作
# yum repolist all Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. RHEL_Repo | 4.1 kB 00:00:00 (1/2): RHEL_Repo/group_gz | 137 kB 00:00:00 (2/2): RHEL_Repo/primary_db | 4.0 MB 00:00:00 repo id repo name status RHEL_Repo Red Hat Enterprise Linux 7.4 enabled: 4,986 repolist: 4,986
如我们所见,我的存储库“RHEL_Repo”已启用并拥有 4,986 rpms。
现在,我们可以在网络中使用相同的 repo 文件并使用此离线存储库。