离线安装主要有两种方式:源码编译、rpm包安装。源码编译耗费时间长且缺乏编译环境,所以一般都选择使用离线 rpm 包安装。
有时候离线 rpm 包有比较难于收集齐全,但测试环境我们又可以通过 yum install XXX
完成某个软件的安装,那我们是否可以将
yum 方式安装的软件,通过某种方式收集该软件的rpm 包和它依赖的 rpm 包。
在离线的内网环境下进行安装一些软件的时候会出现依赖不完整的情况,一般情况下会使用如下方式进行下载依赖包
验证环境
Centos 7.6
查看依赖包
yum provides <value>
: 查看提供某个命令的rpm包
yum deplist <rpm包>
: 查看rpm包所需的全部依赖
可以使用“yum deplist”命令来查找 rpm 包的依赖列表。例如,要查找“skopeo”rpm的依赖包:
[root@gv213 test]# yum deplist skopeo
已加载插件:fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
- base: mirrors.aliyun.com
- extras: mirrors.aliyun.com
- updates: mirrors.aliyun.com
软件包:skopeo.x86_64 1:0.1.40-11.el7_8
依赖:containers-common = 1:0.1.40-11.el7_8
provider: containers-common.x86_64 1:0.1.40-11.el7_8
依赖:libassuan.so.0()(64bit)
provider: libassuan.x86_64 2.1.0-3.el7
依赖:libc.so.6(GLIBC_2.14)(64bit)
provider: glibc.x86_64 2.17-326.el7_9
依赖:libdevmapper.so.1.02()(64bit)
provider: device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5
依赖:libdevmapper.so.1.02(Base)(64bit)
provider: device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5
依赖:libdevmapper.so.1.02(DM_1_02_97)(64bit)
provider: device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5
依赖:libdl.so.2()(64bit)
provider: glibc.x86_64 2.17-326.el7_9
依赖:libdl.so.2(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-326.el7_9
依赖:libgio-2.0.so.0()(64bit)
provider: glib2.x86_64 2.56.1-9.el7_9
依赖:libglib-2.0.so.0()(64bit)
provider: glib2.x86_64 2.56.1-9.el7_9
依赖:libgobject-2.0.so.0()(64bit)
provider: glib2.x86_64 2.56.1-9.el7_9
依赖:libgpg-error.so.0()(64bit)
provider: libgpg-error.x86_64 1.12-3.el7
依赖:libgpgme-pthread.so.11()(64bit)
provider: gpgme.x86_64 1.3.2-5.el7
依赖:libgpgme.so.11()(64bit)
provider: gpgme.x86_64 1.3.2-5.el7
依赖:libgpgme.so.11(GPGME_1.0)(64bit)
provider: gpgme.x86_64 1.3.2-5.el7
依赖:libgpgme.so.11(GPGME_1.1)(64bit)
provider: gpgme.x86_64 1.3.2-5.el7
依赖:libostree-1.so.1()(64bit)
provider: ostree.x86_64 2019.1-2.el7
依赖:libostree-1.so.1(LIBOSTREE_2016.3)(64bit)
provider: ostree.x86_64 2019.1-2.el7
依赖:libostree-1.so.1(LIBOSTREE_2016.8)(64bit)
provider: ostree.x86_64 2019.1-2.el7
依赖:libpthread.so.0()(64bit)
provider: glibc.x86_64 2.17-326.el7_9
依赖:libpthread.so.0(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-326.el7_9
依赖:libpthread.so.0(GLIBC_2.3.2)(64bit)
provider: glibc.x86_64 2.17-326.el7_9
依赖:libselinux.so.1()(64bit)
provider: libselinux.x86_64 2.5-15.el7
依赖:rtld(GNU_HASH)
provider: glibc.x86_64 2.17-326.el7_9
provider: glibc.i686 2.17-326.el7_9
您在 /var/spool/mail/root 中有邮件
方案一(推荐):repotrack
首先使用
yum install yum-utils
安装repotrack
工具,然后使用repotrack <rpm包>
下载全量依赖包
# 安装yum-utils
$ yum -y install yum-utils
# 安装repotrack
yum provides repotrack
yum install -y -q yum-utils-1.1.31-54.el7_8.noarch
# 下载 skopeo 全量依赖包
$ repotrack -p /root/fly/test skopeo
repotrack 用法
[root test]# repotrack -h
Usage:
Repotrack: keep current on any given pkg and its deps. It will download the package(s) you
want to track and all of their dependencies
/usr/bin/repotrack <span class="token punctuation">[</span>options<span class="token punctuation">]</span> package1 <span class="token punctuation">[</span>package2<span class="token punctuation">]</span> <span class="token punctuation">[</span>package<span class="token punctuation">..</span><span class="token punctuation">]</span>
Options:
-h, --help show this help message and exit
-c CONFIG, --config=CONFIG
config file to use (defaults to /etc/yum.conf)
-a ARCH, --arch=ARCH check as if running the specified arch (default:
current arch)
-r REPOID, --repoid=REPOID
specify repo ids to query, can be specified multiple
times (default is all enabled)
--repofrompath=REPOFROMPATH
specify repoid & paths of additional repositories -
unique repoid and complete path required, can be
specified multiple times. Example:
--repofrompath=myrepo,/path/to/repo
-t, --tempcache Use a temp dir for storing/accessing yum-cache
-p DESTDIR, --download_path=DESTDIR
Path to download packages to
-u, --urls Just list urls of what would be downloaded, don't
download
-n, --newest Toggle downloading only the newest packages(defaults
to newest-only)
-q, --quiet Output as little as possible
方案二:yumdownloader
# 安装yum-utils
$ yum -y install yum-utils
# 下载 skopeo 依赖包
$ yumdownloader --resolve skopeo --downloaddir=/root/fly/test
参数说明:
- —destdir:指定 rpm 包下载目录(不指定时,默认为当前目录)
- —resolve:下载依赖的 rpm 包。
注意
仅会将主软件包和基于你现在的操作系统所缺少的依赖关系包一并下载。
- 1
方案三:yum 的 downloadonly 插件
使用
yum install --downloadonly --downloaddir=<指定下载目录> <rpm包>
# 安装插件
$ yum -y install yum-download
# 下载 skopeo 依赖包
$ yum -y install skopeo --downloadonly --downloaddir=/tmp
注意
与 yumdownloader 命令一样,也是仅会将主软件包和基于你现在的操作系统所缺少的依赖关系包一并下载。
离线安装 rpm
# 离线安装
$ rpm -Uvh --force --nodeps *.rpm
# 或者
$ yum localinstall -y *.rpm --nogpgcheck
参考资料
- https://serverfault.com/questions/470964/yumdownloader-vs-repotrack