https://onitroad.com 更多教程

在 RHEL 8 上配置本地 YUM/DNF 存储库

将 RHEL 8 ISO 文件复制到我们的 rhel-8-server.onitroad.com 。

[root@rhel-8-server ~]# ls
anaconda-ks.cfg  rhel-8.0-x86_64-dvd.iso

创建一个目录来挂载 rhel-8.0-x86_64-dvd.iso 文件。

[root@rhel-8-server ~]# mkdir /mnt/iso

在 /mnt/iso 目录中持久挂载 rhel-8.0-x86_64-dvd.iso。

[root@rhel-8-server ~]# echo "/root/rhel-8.0-x86_64-dvd.iso /mnt/iso iso9660 defaults 0 0" >> /etc/fstab
[root@rhel-8-server ~]# mount -a
mount: /mnt/iso: WARNING: device write-protected, mounted read-only.

在 RHEL 8 中,yum 存储库已分为两部分。

  • BaseOS - 它提供了分发的部分,为我们提供在物理硬件、虚拟机、云实例或者容器上运行的用户空间。
  • AppStream - 它提供了我们可能希望在给定用户空间中运行的所有应用程序。

为我们的本地 yum 存储库添加 BaseOS 部分。

[root@rhel-8-server ~]# cat > /etc/yum.repos.d/localyum.repo << EOF
> [localyum_BaseOS]
> name=localyum_BaseOS
> baseurl=file:///mnt/iso/BaseOS
> enabled=1
> gpgcheck=1
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
> EOF

为我们的本地 yum 存储库添加 AppStream 部分。

[root@rhel-8-server ~]# cat >> /etc/yum.repos.d/localyum.repo << EOF
>
> [localyum_AppStream]
> name=localyum_AppStream
> baseurl=file:///mnt/iso/AppStream
> enabled=1
> gpgcheck=1
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
> EOF

为我们的本地 yum 存储库构建缓存。

[root@rhel-8-server ~]# dnf makecache
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
localyum_AppStream                               13 MB/s | 5.3 MB     00:00
localyum_BaseOS                                  13 MB/s | 2.2 MB     00:00
Metadata cache created.

使用 dnf 命令安装 Apache HTTP Server。

[root@rhel-8-server ~]# dnf install -y httpd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

我们的本地 yum 存储库工作正常。
现在,我们要将同一个本地 yum 存储库共享给我们的网络 RHEL 8 客户端。

为此,我们需要 Apache HTTP 服务器(我们已经安装)和我们本地 yum 存储库的配置中的一些修改。

将 SELinux 置于许可模式,因此我们可以将 ISO 文件挂载到 /var/www/html 中,并且网络客户端可以访问该文件。

[root@rhel-8-server ~]# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/sysconfig/selinux
[root@rhel-8-server ~]# setenforce permissive

启用并启动 Apache HTTP 服务。

[root@rhel-8-server ~]# systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service -> /usr/lib/systemd/system/httpd.service.
[root@rhel-8-server ~]# systemctl start httpd.service

在 Linux 防火墙中允许 HTTP 服务。

[root@rhel-8-server ~]# firewall-cmd --permanent --add-service=http
success
[root@rhel-8-server ~]# firewall-cmd --reload
success

在 /var/www/html 中创建一个目录以挂载 RHEL 8 ISO。

[root@rhel-8-server ~]# mkdir /var/www/html/rhel8

编辑 /etc/fstab 文件以更改 /dev/cdrom 的挂载点。

/root/rhel-8.0-x86_64-dvd.iso /var/www/html/rhel8 iso9660 defaults 0 0

重新挂载 ISO 文件。

[root@rhel-8-server ~]# mount -a
mount: /var/www/html/rhel8: WARNING: device write-protected, mounted read-only.

编辑 localyum.repo 文件并更新 baseurls,如下所示。

[localyum_BaseOS]
name=localyum_BaseOS
baseurl=http://192.168.1.165/rhel8/BaseOS
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[localyum_AppStream]
name=localyum_AppStream
baseurl=http://192.168.1.165/rhel8/AppStream
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

重建 YUM/DNF 缓存。

[root@rhel-8-server ~]# dnf clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 files removed
[root@rhel-8-server ~]# dnf makecache
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
localyum_AppStream                               24 MB/s | 5.3 MB     00:00
localyum_BaseOS                                  76 MB/s | 2.2 MB     00:00
Metadata cache created.

检查我们的 RHEL 8 服务器上的存储库列表。

[root@rhel-8-server ~]# dnf repolist
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:22:17 ago on Fri 05 Jul 2019 12:51:12 AM PKT.
repo id                              repo name                            status
localyum_AppStream                   localyum_AppStream                   4,672
localyum_BaseOS                      localyum_BaseOS                      1,658
在 RHEL 8 中配置本地 YUM/DNF 存储库

在 Red Hat Enterprise Linux (RHEL) 8 的最新版本中,旧版 yum(Yellowdog Updater Modifier)已被 Fedora 包管理器取代,例如:dnf(Dandified yum)。
虽然,yum 命令仍然可以向后兼容,但它实际上是重定向到 dnf 命令的别名。

在本文中,我们将在 Red hat Enterprise Linux (RHEL) 8 服务器上配置本地 YUM/DNF 存储库。

日期:2020-09-17 00:12:49 来源:oir作者:oir