前言
参考文章:https://linux.cn/article-7937-1.html
在参考文章的基础上进行总结。
使用download-only插件实现
首先我们可以使用downloadonly插件来实现这个目标,但是前提我们需要先安装这个插件:
yum install yum-plugin-downloadonly
备注:安装这个插件的时候,请注意CentOS-Base.repo不要移除,如果将CentOS-Base.repo移除,使用CentOS-Media.repo这个挂载的镜像仓库文件,那么就会无法搜索到这个插件,因为这个插件应该是从网络上下载下来的。
接下来就可以使用如下命令下载rpm包而不安装:
yum install --downloadonly <package-name>
使用上述命令,会默认将rpm下载到/var/cache/yum/目录下,具体参数参见/etc/yum.conf文件:
[root@ambari1 hzhiping]# cat /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever # 默认保存rpm的地址 keepcache=1 # 是否开启保存?1为开启,0为关闭 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
当然,可以指定目录,如下所示:
yum install --downloadonly --downloaddir=/tmp <package-name>
这样子在/tmp目录下就会看到了,如果不加/表示的是相对路径,会在当前目录创建一个tmp目录,然后保存在tmp目录下。
另外也可以一次性下载多个包,格式如下:
yum install --downloadonly --downloaddir=/tmp <package-name> <package-name>
使用yumdownloader实现
“yumdownloader” 是一款简单,但是却十分有用的命令行工具,它可以一次性下载任何 RPM 软件包及其所有依赖包。
要使用这款工具,首先我们需要安装yum-utils,命令如下:
yum install -y yum-utils
一旦下载好了,我们就能够使用yumdownloader命令去下载相关的rpm包了,以下是yumdownloader命令的帮助文档:
[root@ambari1 hzhiping]# yumdownloader --help Loaded plugins: fastestmirror Usage: "yumdownloader [options] package1 [package2] [package..] Options: Plugin Options: Yum Base Options: -h, --help show this help message and exit -t, --tolerant be tolerant of errors -C, --cacheonly run entirely from system cache, don't update cache -c [config file], --config=[config file] config file location -R [minutes], --randomwait=[minutes] maximum command wait time -d [debug level], --debuglevel=[debug level] debugging output level --showduplicates show duplicates, in repos, in list/search commands -e [error level], --errorlevel=[error level] error output level --rpmverbosity=[debug level name] debugging output level for rpm -q, --quiet quiet operation -v, --verbose verbose operation -y, --assumeyes answer yes for all questions --assumeno answer no for all questions --version show Yum version and exit --installroot=[path] set install root --enablerepo=[repo] enable one or more repositories (wildcards allowed) --disablerepo=[repo] disable one or more repositories (wildcards allowed) -x [package], --exclude=[package] exclude package(s) by name or glob --disableexcludes=[repo] disable exclude from main, for a repo or for everything --disableincludes=[repo] disable includepkgs for a repo or for everything --obsoletes enable obsoletes processing during updates --noplugins disable Yum plugins --nogpgcheck disable gpg signature checking --disableplugin=[plugin] disable plugins by name --enableplugin=[plugin] enable plugins by name --skip-broken skip packages with depsolving problems --color=COLOR control whether color is used --releasever=RELEASEVER set value of $releasever in yum config and repo files --downloadonly don't update, just download --downloaddir=DLDIR specifies an alternate directory to store packages --setopt=SETOPTS set arbitrary config and repo options --bugfix Include bugfix relevant packages, in updates --security Include security relevant packages, in updates --advisory=ADVS, --advisories=ADVS Include packages needed to fix the given advisory, in updates --bzs=BZS Include packages needed to fix the given BZ, in updates --cves=CVES Include packages needed to fix the given CVE, in updates --sec-severity=SEVS, --secseverity=SEVS Include security relevant packages matching the severity, in updates yumdownloader options: --destdir=DESTDIR destination directory (defaults to current directory) # 指定下载的目录 --urls just list the urls it would download instead of downloading --resolve resolve dependencies and download required packages # 下载该rpm相关的依赖包 --source operate on source packages --archlist=ARCHLIST only download packages of certain architecture(s) [root@ambari1 hzhiping]#
比如我们下载vim-enhanced及其依赖包:
坚壁清野