yum 是一个 RPM 包的前端管理工具, 在 rpm 包的依赖关系已经被建成数据库的前提下它能够实现自动查找相互依赖的人 rpm 包, 并从 repository 中下载互相依赖的 rpm 包到本地.
YUM 的工作原理并不复杂, 每一个 RPM 软件的头 (header) 里面都会纪录该软件的依赖关系, 那么如果可以将该头的内容纪录下来并且进行分析, 可以知道每个软件在安装之前需要额外安装 哪些基础软件. 也就是说, 在服务器上面先以分析工具将所有的 RPM 档案进行分析, 然后将该分析纪录下来, 只要在进行安装或升级时先查询该纪录的文件, 就可以知道所有相关联的软件. 所以 YUM 的基本工作流程如下:
服务器端: 在服务器上面存放了所有的 RPM 软件包, 然后以相关的功能去分析每个 RPM 文件的依赖性关系, 将这些数据记录成文件存放在服务器的某特定目录内.
客户端: 如果需要安装某个软件时, 先下载服务器上面记录的依赖性关系文件(可通过 WWW 或 FTP 方式), 通过对服务器端下载的纪录数据进行分析, 然后取得所有相关的软件, 一次全部下载下来进行安装. client 每次调用 yum install 或者 search 的时候, 都会去解析 / etc/yum.repos.d 下面所有以. repo 结尾的配置文件, 这些配置文件指定了 yum 服务器的地址. yum 会定期去 "更新"yum 服务器上的 rpm 包 "清单", 然后把 "清单" 下载保存到 yum 自己的 cache 里面, 根据 / etc/yum.conf 里配置(默认是在 / var/cache/yum 下面), 每次调用 yum 装包的时候都会去这个 cache 目录下去找 "清单", 根据 "清单" 里的 rpm 包描述从而来确定安装包的名字, 版本号, 所需要的依赖包等, 然后再去 yum 服务器下载 rpm 包安装.(前提是不存在 rpm 包的 cache)
yum 的一切信息都存储在一个叫 yum.reops.d 目录下的配置文件中, 通常位于 / etc/yum.reops.d 目录下:
该目录下有许多. repo 文件, 其都为 yum 源 (软件仓库) 的配置文件, 通常一个 repo 文件定义了一个或多个软件仓库的细节内容, 例如我们将从哪里下载需要安装或升级的软件包, repo 文件中的设置内容将被 yum 读取和应用.
- cat /etc/yum.repos.d/CentOS-Base.repo
- [base]
- name=CentOS-$releasever
- enabled=1
- failovermethod=priority
- baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
- gpgcheck=1
- gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-7
- [updates]
- name=CentOS-$releasever
- enabled=1
- failovermethod=priority
- baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
- gpgcheck=1
- gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-7
- [extras]
- name=CentOS-$releasever
- enabled=1
- failovermethod=priority
- baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
- gpgcheck=1
- gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-7
- cat /etc/yum.conf
- [main]
- cachedir=/var/cache/yum/$basearch/$releasever #yum 下载的 rpm 包的缓存目录
- keepcache=0 #缓存是否保存, 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
来源: http://www.bubuko.com/infodetail-3028372.html