如何从CentOS/RHEL 7/8下载整个存储库以供离线使用?

时间:2020-01-09 10:39:09  来源:igfitidea点击:

在本文中,将介绍"从CentOS/RHEL 7将整个存储库下载到本地Linux"节点的步骤。

要下载存储库,我们将需要一次有效的Internet访问。

一旦下载了rpm,就可以使用这些rpm配置本地存储库以供离线使用。

尽管将整个存储库内容下载(同步)到本地Linux节点可能会花费一些时间,具体取决于Internet速度和存储库的内容。

我有一个位于专用网络中并且无法访问Internet的节点,因此,如果必须安装一些具有多个依赖项的添加rpm,我总是会遇到很多麻烦。

使用这种方法,我在专用网络中创建了一个本地存储库,该存储库可帮助我无需Internet即可下载所需的rpm。

安装所需的软件包

首先在系统上安装将用于同步目的的yum-utilscreaterepo软件包:

说明:

在RHEL系统上,我们必须具有RHN的有效订阅,或者我们可以配置本地脱机存储库,通过该本地脱机存储库,yum软件包管理器可以安装提供的rpm及其依赖项。

# yum install yum-utils createrepo

从CentOS 7下载整个存储库

在CentOS上,与RHEL不同,我们不需要执行任何其他与订阅有关的活动就可以访问其存储库。
一旦安装了CentOS,我们将在下面的/etc/yum.repos.d下找到Repo文件列表。

[root@openstack yum.repos.d]# ll
total 40
-rw-r--r--. 1 root root 1664 Aug 30  2016 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Aug 30  2016 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Aug 30  2016 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Aug 30  2016 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Aug 30  2016 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Aug 30  2016 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 Aug 30  2016 CentOS-Vault.repo

并非所有这些存储库都将处于启用状态,其中一些可能处于禁用状态。
要检查当前活动的仓库,请使用以下命令

# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
repo id                                                                                      repo name                                                                                         status
base/7/x86_64                                                                                CentOS-7 - Base                                                                                   9,911
extras/7/x86_64                                                                              CentOS-7 - Extras                                                                                   432
openstack-pike/x86_64                                                                        OpenStack Pike Repository                                                                         2,812
rdo-qemu-ev/x86_64                                                                           RDO CentOS-7 - QEMU EV                                                                               59
updates/7/x86_64                                                                             CentOS-7 - Updates                                                                                1,540
repolist: 14,754

提示:

在RHEL 8中,reposync是dnf-plugins-core rpm的一部分。
在RHEL 8中下载整个存储库的新语法是

[root@rhel-8 ~]# dnf reposync  --repoid=<repo_id> -p=<download_path>

要在CentOS/RHEL 7上下载(或者同步)存储库,请使用以下命令

# reposync --gpgcheck -l --repoid=<repo_id> --download_path=<path>

其中将repo_id替换为我们希望本地同步的存储库的ID,例如,在下面的命令中,我正在同步Extras repo并将rpm下载到/tmp

# reposync --gpgcheck -l --repoid=extras --download_path=/tmp

说明:

在目标目录中,将有一个以存储库ID命名的新目录。
里面有所有的包

要访问新同步的仓库的组数据,请按以下方式运行createrepo命令:

# cd /tmp/<channel-id>
# createrepo -v /tmp/<channel-id>/

例如:

# cd /tmp/extras
# createrepo /tmp/extras

从RHEL 7下载整个存储库

首先,在RHEL 7上,我们必须首先将节点注册到Red Hat Network。

# subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: hynman
Password:
The system has been registered with ID: 04bbc67c-f45c-47e9-9bec-122e8cd10c9d

接下来检查ID的权利列表

# subscription-manager list --available --all

一旦知道哪种权利适合要求,然后为系统添加" POOL ID"

# subscription-manager attach --pool=<pool_id>

接下来,启用我们要使用的所有存储库。
我们可以使用以下命令检查所有已订阅的存储库

# yum repolist all

拥有要下载的RepoID后,请使用与CentOS 7相同的命令

语法:

# reposync --gpgcheck -l --repoid=<repo_id> --download_path=<path> --downloadcomps --download-metadata

其中将repo_id替换为我们希望在本地同步的存储库的ID,例如,在下面的命令中,我正在同步Extras repo并将rpm下载到/tmp

# reposync --gpgcheck -l --repoid=rhel-7-server-openstack-10-devtools-rpms --download_path=/tmp --downloadcomps --download-metadata

说明:

在目标目录中,将有一个以存储库ID命名的新目录。
里面有所有的包

要访问新同步的仓库的组数据,请按如下所示运行createrepo命令:

# cd /var/www/html/<channel-id>
# createrepo -v /var/www/html/<channel-id>/-g comps.xml

例如:

# cd /var/www/html/rhel-7-server-openstack-10-devtools-rpms
# createrepo -v /var/www/html/rhel-7-server-openstack-10-devtools-rpms/-g comps.xml
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 1 pkgs
Spawning worker 2 with 1 pkgs
Spawning worker 3 with 1 pkgs
Spawning worker 4 with 1 pkgs
Spawning worker 5 with 1 pkgs
Spawning worker 6 with 1 pkgs
Spawning worker 7 with 1 pkgs
Spawning worker 8 with 1 pkgs
Spawning worker 9 with 1 pkgs
Spawning worker 10 with 1 pkgs
Spawning worker 11 with 1 pkgs
Spawning worker 12 with 0 pkgs
Spawning worker 13 with 0 pkgs
Spawning worker 14 with 0 pkgs
Spawning worker 15 with 0 pkgs
Spawning worker 16 with 0 pkgs
Spawning worker 17 with 0 pkgs
Spawning worker 18 with 0 pkgs
Spawning worker 19 with 0 pkgs
Spawning worker 20 with 0 pkgs
Spawning worker 21 with 0 pkgs
Spawning worker 22 with 0 pkgs
Spawning worker 23 with 0 pkgs
Spawning worker 24 with 0 pkgs
Spawning worker 25 with 0 pkgs
Spawning worker 26 with 0 pkgs
Spawning worker 27 with 0 pkgs
Spawning worker 28 with 0 pkgs
Spawning worker 29 with 0 pkgs
Spawning worker 30 with 0 pkgs
Spawning worker 31 with 0 pkgs
Worker 0: reading Packages/dpdk-16.11-3.el7fdp.x86_64.rpm
Worker 1: reading Packages/openstack-packstack-9.0.0-3.el7ost.noarch.rpm
Worker 2: reading Packages/openstack-packstack-9.0.1-3.el7ost.noarch.rpm
Worker 3: reading Packages/openstack-packstack-9.0.3-4.el7ost.noarch.rpm
Worker 4: reading Packages/openstack-packstack-9.0.3-5.el7ost.noarch.rpm
Worker 5: reading Packages/openstack-packstack-puppet-9.0.0-3.el7ost.noarch.rpm
Worker 6: reading Packages/openstack-packstack-puppet-9.0.1-3.el7ost.noarch.rpm
Worker 7: reading Packages/openstack-packstack-puppet-9.0.3-4.el7ost.noarch.rpm
Worker 8: reading Packages/openstack-packstack-puppet-9.0.3-5.el7ost.noarch.rpm
Worker 9: reading Packages/openstack-utils-2015.1-1.el7ost.noarch.rpm
Worker 10: reading Packages/openvswitch-test-2.9.0-19.el7fdp.1.noarch.rpm
Worker 11: reading Packages/openvswitch-test-2.9.0-56.el7fdp.noarch.rpm
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Starting other db creation: Sun Oct 7 19:23:07 2016
Ending other db creation: Sun Oct 7 19:23:07 2016
Starting filelists db creation: Sun Oct 7 19:23:07 2016
Ending filelists db creation: Sun Oct 7 19:23:07 2016
Starting primary db creation: Sun Oct 7 19:23:07 2016
Ending primary db creation: Sun Oct 7 19:23:07 2016
Sqlite DBs complete

让我们验证我们的存储库

说明:

我已经使用以下内容配置了使用http服务器的"离线存储库"

[rhel-7-server-openstack-10-devtools-rpms]
name=rhel-7-server-openstack-10-devtools-rpms
baseurl=http://192.168.122.1/repo/rhel-7-server-openstack-10-devtools-rpms/
gpgcheck=0
enabled=1
# 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.
repo id                                                             repo name                                                            status
rhel-7-server-extras-rpms                                           rhel-7-server-extras-rpms                                            enabled:    814
rhel-7-server-openstack-10-devtools-rpms                            rhel-7-server-openstack-10-devtools-rpms                             enabled:     12
rhel-7-server-rh-common-rpms                                        rhel-7-server-rh-common-rpms                                         enabled:    231
rhel-7-server-rpms                                                  rhel-7-server-rpms                                                   enabled: 18,263
repolist: 19,320

现在,我可以开始离线使用此存储库了。