yum安装并保存依赖包
通常我们在liunx上安装软件时会通过yum或者其他的RPM包管理工具下载,能够方便的解决程序依赖问题,但是在很多情况下,我们在到一个项目环境时无法使用外网,因此没办法通过外网使用yum下载。
那么我们可以先在本地建立一个相同的OS环境,在本地通过yum安装,并且将yum安装时下载的所有依赖以及程序包保存下来,就可以直接在客户环境进行离线安装了。
方法一:修改yum源配置,开启依赖下载的依赖包缓存配置
第一步:修改yum源配置文件,vi /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=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
将cachedir、keepcache两项配置如下:
cachedir=/var/cache/yum #这是配置为/var/cache/yum是方便后续演示使用,避免不同系统默认保存路径不一致
keepcache=1
配置修改完成后通过yum 安装程序包时就会将下载和被更新的所有依赖以及程序包保存至我们配置的路径(/var/cache/yum)下。
配置项说明:
cachedir | yum下载的RPM包的缓存目录 |
keepcache | 缓存是否保存,1保存,0不保存 |
debuglevel | 调试级别(0-10),默认为2 |
logfile | yum的日志文件所在的位置,默认是/var/log/yum.log |
exactarch | 是否只升级和你安装软件包cpu体系一致的包 |
obsoletes | 是否允许更新陈旧的RPM包 |
gpgcheck | 是否检查GPG(GNU Private Guard) |
plugins | 是否允许使用插件,默认是0不允许 |
installonly_limit | 同时安装多少程序包 |
bugtracker_url | bug追踪路径 |
distroverpkg | 当前发行版版本号从哪儿获取 |
方法二:使用yum命令直接下载对应的依赖包
yum -y install --downloadonly --downloaddir=/home/yum_package wget
参数说明:
--downloadonly 仅下载依赖包不安装
--downloaddir 下载的依赖包保存的文件位置
wget 需要下载的依赖包,这里可以是多个