$ 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
仓库下载的软件包。
keepcache=1
yum
操作都可能从仓库下载软件包数据。要保证缓存包含了软件包数据,在启用缓存后运行一个操作,例如
list
或
search
来下载软件包数据而不影响系统。
3.在只使用缓存的模式下使用 yum
要在没有网络的情况下执行 yum
,只要启用了缓存,就可以用 -C
选项。这样 yum
就不会检查网络上的仓库,只使用缓存。在这个模式中,yum
只能安装已下载并缓存的软件包。
tsclient
,输入命令:
su -c 'yum -C list tsclient
'
tsclient
'4. 缓存带来的好处
如果你有多台机子 只须要一台机子从网上下载 软件包跟软件更新包 , 还有如果你想重装系统不想再下载的几个G的更新跟软件(前提缓存了你系统所有安装的软件的更新包).
在开启 缓存的状态下因为 yum 下载的软件包不会被删除,所以可以多次利用.(就是占硬盘空间而以, 呵呵几个G我不放在眼里,我硬盘有 1.2TB)
很简单的方法,把这台机子的 /var/cache/yum/ 目录下的所有文件包过目录. 复制到另一台机子下的相同目录. 执行.
# yum -C update
# yum -C install <软件包名>