如何利用yum的缓存文件

$ su
# vi /etc/yum.conf


将keepcache的值由原来的0(表示安装后删除软件包)修改为1(表示安装后保留软件包)。如下内容:

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

# 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配置文件的内容可知,使用yum下载软件包的默认下载目录由cachedir指定,即是:
/var/cache/yum

详解

1.使用 yum 缓存

默​认​情​况​下​,当​前​版​本​的​  yum 在​成​功​下​载​和​安​装​软​件​包​后​,会​把​下​载​的​文​件​删​掉​。​这​样​可​以​减​少​  yum 占​用​的​磁​盘​空​间​。​你​可​以​打​开​缓​存​,这​样​  yum 将​在​缓​存​目​录​保​留​下​载​到​的​文​件​。​
缓​存​带​来​很​多​好​处​:
  • yum 的​性​能​可​以​提​高​
  • 你​可​以​离​线​运​行​  yum 操​作​,只​使​用​缓​存​
  • 你​可​以​复​制​缓​存​中​的​软​件​包​以​备​用​

默​认​情​况​下​, yum 在​  /var/cache/yum/ 目​录​保​存​临​时​文​件​,每​个​仓​库​都​有​自​己​的​子​目​录​。​仓​库​目​录​中​  packages/ 子​目​录​包​含​了​缓​存​的​软​件​包​。​例​如​,目​录​  /var/cache/yum/development/packages/ 包​含​从​  development 仓​库​下​载​的​软​件​包​。​

2. 启用 yum 缓存

要​配​置​ yum 保​留​已​下​载​的​文​件​而​不​是​删​除​,设​置​ /etc/yum.conf 中​的​ keepcache 选​项​为​ 1

keepcache=1
打​开​缓​存​后​,每​个​  yum 操​作​都​可​能​从​仓​库​下​载​软​件​包​数​据​。​要​保​证​缓​存​包​含​了​软​件​包​数​据​,在​启​用​缓​存​后​运​行​一​个​操​作​,例​如​  list 或​  search 来​下​载​软​件​包​数​据​而​不​影​响​系​统​。​

3.在​只​使​用​缓​存​的​模​式​下​使​用​ yum

要​在​没​有​网​络​的​情​况​下​执​行​ yum,只​要​启​用​了​缓​存​,就​可​以​用​ -C 选​项​。​这​样​ yum 就​不​会​检​查​网​络​上​的​仓​库​,只​使​用​缓​存​。​在​这​个​模​式​中​,yum 只​能​安​装​已​下​载​并​缓​存​的​软​件​包​。​

要​在​没​有​网​络​连​接​的​时​候​搜​索​软​件​包​  tsclient,输​入​命​令​:
su -c 'yum -C list tsclient'

4. 缓存带来的好处

如果你有多台机子 只须要一台机子从网上下载 软件包跟软件更新包 , 还有如果你想重装系统不想再下载的几个G的更新跟软件(前提缓存了你系统所有安装的软件的更新包).

在开启 缓存的状态下因为 yum 下载的软件包不会被删除,所以可以多次利用.(就是占硬盘空间而以, 呵呵几个G我不放在眼里,我硬盘有 1.2TB)

很简单的方法,把这台机子的 /var/cache/yum/ 目录下的所有文件包过目录. 复制到另一台机子下的相同目录. 执行.

# yum -C update

# yum -C install <软件包名>

5.清​空​ yum 缓​存​


from: http://blog.csdn.net/eyefamily/article/details/7021991

你可能感兴趣的:(如何利用yum的缓存文件)