[root@localhost ~]# ls /var/ftp/
pub  rhel5  rhel6
[root@localhost ~]#
YUM仓库有两个rhel5、rhel6

 YUM客户端的配置如下:

[root@s2 ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum
keepcache=0

debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
metadata_expire=1800

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

[root@s2 ~]# cat /etc/yum.repos.d/rhel.repo
[rhel]
name=Red Hat
baseurl=ftp://192.168.1.29/rhel5
enabled=1
gpgcheck=0

1.使用 yum 缓存

 默认情况下,yum客户端在成功下载和安装软包后会把下载的文件删掉而不进行缓存。这样可以减少磁盘空间的占用。需要时可以启用缓存功能,这样yum可以将rpm数据缓存到YUM的缓存目录中。

缓存的好处:提高YUM的性能;可以离线运行YUM操作,只使用缓存;也可以复制缓存中的软件包以备用。

 

存放下载的软件包、仓库信息等数据

§位于/var/cache/yum/$basearch/$releasever

 

 

2. 启用 yum 缓存 客户端的/etc/yum.conf中的keepcache=1

打​开​缓​存​后​,每​个​ yum 操​作​都​可​​从​仓​库​下​载​软​件​包​数​据​。​要​保​证​缓​存​包​含​了​软​件​包​数​据​,在​启​用​缓​存​后需要​运​行​一​个​操​作​,例​如​ list 或​ search 来​下​载​软​件​包​数​据​而​不​影​响​系​统​。​
修改keepcache=1后:
[root@s2 ~]# ls /var/cache/yum/
[root@s2 ~]#
[root@s2 ~]# yum -y install httpd
……
[root@s2 ~]# ls /var/cache/yum/
rhel
[root@s2 ~]# ls /var/cache/yum/rhel/
cachecookie  headers  packages  primary.xml.gz  primary.xml.gz.sqlite  repomd.xml
[root@s2 ~]# ls /var/cache/yum/rhel/packages/
httpd-2.2.3-6.el5.i386.rpm
[root@s2 ~]#
[root@s2 ~]# ls /var/cache/yum/rhel/headers/
httpd-2.2.3-6.el5.i386.hdr[root@s2 ~]# du -sh /var/cache/yum/rhel/packages/httpd-2.2.3-6.el5.i386.rpm
1.1M    /var/cache/yum/rhel/packages/httpd-2.2.3-6.el5.i386.rpm

 

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

要​在​没​有​网​络​的​情​况​下​执​行​ yum,只​要​启​用​了​缓​存​,就​可​以​用​ -C 选​项​。​这​样​ yum 就​不​会​检​查​网​络​上​的​仓​库​,只​使​用​缓​存​。​在​这​个​模​式​中​,yum 只​能​安​装​已​下​载​并​缓​存​的​软​件​包​。​[root@localhost ~]# service vsftpd stop
Shutting down vsftpd:                                      [  OK  ]
[root@localhost ~]# 

因为客户端缓存的有httpd的rpm包,所以[root@s2 ~]# yum -y remove httpd可以执行成功。缓存中没有dhcp的rpm包,所以[root@s2 ~]# yum -y install dhcp这条命令不能正确执行。

 

4.清空yum缓存

[root@s2 ~]# ls /var/cache/yum/rhel/headers/
dhcp-3.0.5-3.el5.i386.hdr  httpd-2.2.3-6.el5.i386.hdr
[root@s2 ~]# yum clean headers
Loading "installonlyn" plugin
Loading "rhnplugin" plugin
This system is not registered with RHN.
RHN support will be disabled.
2 headers removed
[root@s2 ~]# ls /var/cache/yum/rhel/headers/
[root@s2 ~]#
[root@s2 ~]# ls /var/cache/yum/rhel/packages/
dhcp-3.0.5-3.el5.i386.rpm  httpd-2.2.3-6.el5.i386.rpm
[root@s2 ~]# yum clean packages
Loading "installonlyn" plugin
Loading "rhnplugin" plugin
This system is not registered with RHN.
RHN support will be disabled.
2 packages removed
[root@s2 ~]# ls /var/cache/yum/rhel/packages/
[root@s2 ~]#