点滴记忆---观雨亭
深入理解yum工作原理[转]
2015-10-24 eehello

前言

转载自:http://www.firefoxbug.com/index.php/archives/2777/


在前面一篇rpm包制作描述了rpm的打包过程,这篇文章主要讲述yum的工作原理。

yum 运行原理

yum的工作需要两部分来合作,一部分是yum服务器,还有就是client的yum工具。下面分别介绍两部分工作原理。

搭建yum服务器

1. 安装工具createrepo
$ yum install createrepo

2. 建立repo发布目录
$ mkdir /var/www/yum/centos/5/{i386,x86_64}
$ mkdir /var/www/yum/centos/6/{i386,x86_64}

3. 用rpmbuild生成两个rpm包,比如说下面几个包,版本号不一样,包名字不一样
rpm_test-0.0.1-3.noarch.rpm
rpm_test-0.0.2-3.noarch.rpm
rpm_test2-0.0.2-3.noarch.rpm

4. copy rpm包到发布目录下
$ cp rpm_test-0.0.* /var/www/yum/centos/5/i386/

5. 用createrepo生成meta信息
$ createrepo -o /var/www/yum/centos/5/i386/ /var/www/yum/centos/5/i386
3/3 - rpm_test-0.0.1-3.noarch.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata

6. 配置apache或者nginx到发布目录

在createrepo之后会在/var/www/yum/centos/5/i386/生成下面的目录和文件

$ tree repodata/
repodata/
|-- filelists.xml.gz
|-- other.xml.gz
|-- primary.xml.gz
`-- repomd.xml

$ gunzip filelists.xml.gz
$ gunzip primary.xml.gz

filelists.xml里面记录了所有rpm包列表,版本号,配置文件等

<package pkgid="19c82aa653a394ee1f7dbc7b694fbf0221bc1848" 
name="rpm_test" arch="noarch"><version epoch="0" ver="0.0.1" 
rel="3"/><file>/usr/local/rpm_test/conf/test.conf</file><file>/usr/local/rpm_test/test.py</file><file
 type="dir">/usr/local/rpm_test/conf</file></package>
...


primary.xml里面记录描述了rpm包的依赖等信息

配置客户端

$ vim /etc/yum.repos.d/firefoxbug.repo

[firefoxbug]
name=firefoxbug
baseurl=http://42.120.7.71/centos/5/i386/
enabled=1
gpgcheck=0
gpgkey=

查看本地yum cache

默认是在/var/cache/yum下这里记录着每个repo对应的cache

/var/cache/yum/
|-- base
|   |-- cachecookie
|   |-- mirrorlist.txt
|   |-- packages
|   |-- primary.xml.gz
|   |-- primary.xml.gz.sqlite
|   `-- repomd.xml
|-- epel
|   |-- 76c4dcbfaf075e55d5876839eb11c4f33b3a2495-primary.sqlite
|   |-- cachecookie
|   |-- mirrorlist.txt
|   |-- packages
|   `-- repomd.xml
|-- firefoxbug
|   |-- cachecookie
|   |-- packages
|   |-- primary.xml.gz
|   |-- primary.xml.gz.sqlite
|   `-- repomd.xml
|-- timedhosts.txt
|-- updates
|   |-- cachecookie
|   |-- mirrorlist.txt
|   |-- packages
|   |-- primary.sqlite
|   `-- repomd.xml
$ sqlite3 primary.xml.gz.sqlite
sqlite> .table
conflicts  db_info    files      obsoletes  packages   provides   requires
sqlite> select * from packages;
1|896712eb4b4af2d61745dd30e0a6f6513043fd69|rpm_test|noarch|0.0.2|0|3|rpm_test|rpm_test by Wanghua||1406360629|1406360561|Commercial||tools|firefoxbug|rpm_test-0.0.2-3.src.rpm|280|2402||2734|268|816|rpm_test-0.0.2-3.noarch.rpm||sha
2|3ad546bd3ce28b0a82a1387f438f456349e20c78|rpm_test2|noarch|0.0.2|0|3|rpm_test|rpm_test by Wanghua||1406363739|1406363674|Commercial||tools|firefoxbug|rpm_test2-0.0.2-3.src.rpm|280|2406||2738|268|816|rpm_test2-0.0.2-3.noarch.rpm||sha
3|19c82aa653a394ee1f7dbc7b694fbf0221bc1848|rpm_test|noarch|0.0.1|0|3|rpm_test|rpm_test by Wanghua||1406360629|1406356964|Commercial||tools|firefoxbug|rpm_test-0.0.1-3.src.rpm|280|2402||2733|268|816|rpm_test-0.0.1-3.noarch.rpm||sha
sqlite> select * from requires;
/bin/sh|||||1|TRUE
python|GE|0|2.4.3||1|FALSE
/bin/sh|||||2|TRUE
python|GE|0|2.4.3||2|FALSE
/bin/sh|||||3|TRUE
python|GE|0|2.4.3||3|FALSE

调用sudo yum clean会把这份"清单""全都清除,下次调用yum install等操作又会重新生成。

$ sudo yum clean

/var/cache/yum/
|-- base
|   |-- packages
|-- epel
|   |-- packages
|-- firefoxbug
|   |-- packages
|-- updates
|   |-- packages


发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容