Some of you might share the following use case: You need (or want) to mirror repos to provide packages for the hosts on your LAN that are not connected to the internet, and therefore cannot access the upstream repos directly. In this article, I explain how to accomplish this task easily by using reposync, which is shipped with your Red Hat Enterprise Linux (RHEL) 7 or Red Hat Enterprise Linux 8 subscription.

Before we get started, I would like to point out the important requirements. You need a valid subscription for every repo you would like to mirror because your mirror server can only sync those repos that are included in its own subscription. All of your other hosts that will use this mirror need to have a valid subscription, too.

If you have any questions about subscriptions, please take a look at the following URLs: the Red Hat subscription model FAQ and the Red Hat subscription service overview.

Setting up mirrored repos for Red Hat Enterprise Linux 7

To start, you’ll need to choose the web server that will serve the mirrored repos to your LAN. Then, if you’re using Red Hat Enterprise Linux 7, then to create a basic repo you have to start by installing createrepo. Don’t worry, this tool is included in your subscription, too. Install it on your web server with the following:

# yum install yum-utils createrepo

Next, you need the repository ID for the repo you would like to sync. Run yum repolist, and you’ll find the repo ID in the output’s first column:

$ yum repolist
Loaded plugins: langpacks, nvidia, product-id, search-disabled-repos, subscription-
              : manager
repo id                                    repo name                             status
rhel-7-server-optional-rpms/7Server/x86_64 Red Hat Enterprise Linux 7 Server - O 19.490
rhel-7-server-rpms/7Server/x86_64          Red Hat Enterprise Linux 7 Server (RP 26.766
virtualbox/7Server/x86_64                  Oracle Linux / RHEL / CentOS-7Server      77

In this case, rhel-7-server-rpms is the ID for the standard Red Hat Enterprise Linux 7 repo. You can get a complete list of repos your subscription has access to with the command:

$ sudo subscription-manager repos --list

You’ll find the repo ID in there, too.

For example, to sync the packages from the rhel-7-server-rpms repo and create a basic local repository, execute the following commands:

# reposync --gpgcheck -l --repoid=rhel-7-server-rpms --download_path=/var/www/html  # Sync RPMS
# cd /var/www/html/rhel-7-server-rpms
# createrepo -v /var/www/html/rhel-7-server-rpms  # Create the repo

Setting up mirrored repos for Red Hat Enterprise Linux 8

For Red Hat Enterprise Linux 8, this process is even easier. You only need the reposync command:

# reposync -p <download-path> --download-metadata --repo=<repo id>

The createrepo command is not needed anymore because reposync downloads everything, including the repodata.

Sharing the local repository

Once the packages are fetched and the local repo is created using either of these methods, the local repository can be distributed among the offline/disconnected systems using a simple web server, FTP, or NFS. The following knowledgebase articles provide the necessary information regarding your choice of distribution:

For more sophisticated setup than described in this article, consider using Red Hat Satellite.

[ Want to try out Red Hat Enterprise Linux? Download it now for free. ]


关于作者

Jörg has been a Sysadmin for over ten years now. His fields of operation include Virtualization (VMware), Linux System Administration and Automation (RHEL), Firewalling (Forcepoint), and Loadbalancing (F5). He is a member of the Red Hat Accelerators Community and author of his personal blog at https://www.my-it-brain.de.

UI_Icon-Red_Hat-Close-A-Black-RGB

按频道浏览

automation icon

自动化

有关技术、团队和环境 IT 自动化的最新信息

AI icon

人工智能

平台更新使客户可以在任何地方运行人工智能工作负载

open hybrid cloud icon

开放混合云

了解我们如何利用混合云构建更灵活的未来

security icon

安全防护

有关我们如何跨环境和技术减少风险的最新信息

edge icon

边缘计算

简化边缘运维的平台更新

Infrastructure icon

基础架构

全球领先企业 Linux 平台的最新动态

application development icon

应用领域

我们针对最严峻的应用挑战的解决方案

Virtualization icon

虚拟化

适用于您的本地或跨云工作负载的企业虚拟化的未来