createrepo 是一个对rpm 文件进行索引建立的工具

createrepo 是一个对rpm 文件进行索引建立的工具。
大体功能就是对指定目录下的rpm文件进行检索,把每个rpm文件的信息存储到指定的索引文件中,这样方便远程yum命令在安装更新时进行检索。
看下createrepo支持的几个参数:
-u --baseurl

                Optional base url location for all files. (not used by any clientsat this time) 

    -o --outputdir <url> 
                  Optional output directory (useful for read only media). 

    -x --exclude <package> 
                  File globs to exclude, can be specified multiple times. 

    -i --pkglist <filename> 
                  specify a text file which contains the complete list of filesto  include  in  the  repository 
                  from  the  set  found  in  the directory. File format is onepackage per line, no wildcards or 
                  globs. 

    -q --quiet 
                  Run quietly. 

    -g --groupfile <groupfile> 
                  A precreated xml filename to point to for group information. 
                  See examples section below for further explanation. 

    -v --verbose 
                  Run verbosely. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-c --cachedir
Specify a directory to use as a cachedir. This allows createrepo tocreate a cache of check-
sums of packages in the repository. In consecutive runs ofcreaterepo over the same repository
of files that do not have a complete change out of all packagesthis decreases the processing
time dramatically.

    --update 
                  If  metadata  already  exists in the outputdir and an rpmis unchanged (based on file size and 
                  mtime) since the metadata was generated, reuse the existingmetadata rather than recalculating 
                  it.  In  the caseof a large repository with only a few new or modified rpms this cansignifi- 
                  cantly reduce I/O and processing time. 

    -C --checkts 
                  Don’t generate repo metadata, if theirtimestamps  are  newer  than  its  rpms.    This  option 
                  decreases  the  processing  time  drastically  again, if you happen to run iton an unmodified 
                  repo, but it is (currently) mutual exclusive with the --splitoption. 

    --split 
                  Run in split media mode. Rather than pass a single directory, takea set of directories corre- 
                  sponding to different volumes in a media set. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-p --pretty
Output xml files in pretty format.

    -V --version 
                  Output version. 

    -h --help 
                  Show help menu. 

    -d --database 
                  Generate sqlite databases for use with yum. 

1
2
3
4
5
6
7
8
createrepo生成四个文件:
repodata/filelists.xml.gz
repodata/other.xml.gz
repodata/primary.xml.gz
repodata/repomd.xml
关于这几个文件的描述是:
repomd.xml this is the file that describes theother metadata files. It is like an index file to point to theother files. It contains timestamps and checksums for the otherfiles. This lets a client download this one, small file and know ifanything else has changed. This also means that cryptographically(ex: gpg) signing this one file can ensure repositoryintegrity.
primary.xml.[gz] this file stores the primarymetadata information. This includes information such as:
name, epoch, version, release, architecture
file size, file location, description, summary, format,checksums header byte-ranges, etc.
dependencies, provides, conflicts, obsoletes, suggests,recommends
file lists for the package for CERTAIN files - specificallyfiles matching: /etc*, bin/, /usr/lib/sendmail [1]
filelists.xml.[gz] this file stores thecomplete file and directory listings for the packages. The packageis identified by: name, epoch, version, release, architecture andpackage checksum id.
other.xml.[gz] this file currently onlystores the changelog data from packages. However, this file couldbe used for any other additional metadata that could be useful forclients.
groups.xml.[gz] this file is tentativelydescribed. The intention is for a common package-groupsspecification as well. There is still some sections for this formatthat need to be fleshed out.
其实我们需要记住的就是primary.xml.gz存储的是包列表,而filelist.xml存储的是所有包的目录和文件列表。

也就是说如果createrepo成功创建索引后,包的信息和每个包的文件信息都会存储在这两个文件中。

当然,如果你在执行createrepo时添加了-d 参数的话,createrepo会对

filelist.xml.gz,primary.xml.gz和other.xml.gz各自生成一个sqlite的文件(或者压缩文件)。

其中用sqlite格式存储了对应xml文件中的信息。

然后当你在客户端执行 yum clean all ,yum list 之后,这些索引文件就会下载到客户端。

默认的cache目录是:/var/cache/yum,里面按照不同的repo再分目录了,比如 rhel,test等等。

createrepo默认会生成的文件有:

filelists.xml.gz other.xml.gz primary.xml.gz repomd.xml

经过索引下载后,在客户端的cache中会生成索引文件:

cachecookie primary.xml.gz primary.xml.gz.sqlite repomd.xml
如果采用了 -d 参数的话,createrepo会生成的文件有:

filelists.sqlite.bz2 filelists.xml.gz other.sqlite.bz2 other.xml.gz primary.sqlite.bz2 primary.xml.gz repomd.xml

客户端更新后,索引文件有:

cachecookie primary.sqlite repomd.xml
我们可以看到,如果采用sqlite的db来存储的话,yum会把filelist,primary和other文件的信息都存储到

Sqlite的db文件primary.sqlite中。

查看primary.sqlite文件:

sqlite3 /var/cache/yum/ops.5Server.x86_64/primary.sqlite

运行 ".table"命令,查看表列表:

sqlite> .table
conflicts db_info files obsoletes packages provides requires
可以看到包的所有信息都存储在这几个表当中了。

我们可以做个测试,查询下packages表中的信息:

select * from packages where name =‘tops-cmos’ and version =‘1.1.0’;

输出如下:

155|ece7d2540f36adec0b098c2202601f1d1c5021a6|tops-cmos|x86_64|1.1.0|20|101|Unifiedplatform of agent program for configuration managment by TAOBAOSA|Unified platform of agent program for configuration managment byTAOBAO SA||1337054204|1337054201|©2011 System AdministrationTools Licence|System Administration Department, TaobaoInc.|Tops|v132074.sqa.cm4.tbsite.net|tops-cmos-1.1.0-101.src.rpm|280|4315|SysAdminPackertaobao-sre-sys-sa@list.alibaba-inc.com|47174|119349|121752|tops-cmos-1.1.0-101.x86_64.rpm||sha

继续以packages表为例,能够看到这个表的字段有:

.schema packages

CREATE TABLE packages ( pkgKey INTEGERPRIMARY KEY, pkgIdTEXT, name TEXT, arch TEXT, versionTEXT, epoch TEXT, release TEXT, summaryTEXT, descriptionTEXT, url TEXT, time_file INTEGER, time_buildINTEGER, rpm_licenseTEXT, rpm_vendorTEXT, rpm_groupTEXT, rpm_buildhostTEXT, rpm_sourcerpmTEXT, rpm_header_startINTEGER, rpm_header_endINTEGER, rpm_packagerTEXT, size_packageINTEGER, size_installedINTEGER, size_archiveINTEGER, location_hrefTEXT, location_baseTEXT, checksum_type TEXT);

看到了这个表的所有字段,这些字段描述了一个rpm文件的主要信息。然后你就可以根据这些字段做条件查询了。

.schema files
CREATE TABLE files ( nameTEXT, type TEXT, pkgKey INTEGER);

也能够看到file与pkg的关联关系,有个外键是pkgKey.

.schema conflicts
CREATE TABLE conflicts ( nameTEXT, flags TEXT, epoch TEXT, versionTEXT, releaseTEXT, pkgKey INTEGER );

conflicts表的信息.

.schema obsoletes
CREATE TABLE obsoletes ( nameTEXT, flags TEXT, epoch TEXT, versionTEXT, releaseTEXT, pkgKey INTEGER );

包废除表的信息.

.schema provides
CREATE TABLE provides ( nameTEXT, flags TEXT, epoch TEXT, versionTEXT, releaseTEXT, pkgKey INTEGER );
CREATE INDEX pkgprovides on provides (pkgKey);
CREATE INDEX providesname ON provides (name);

provides表的信息。

.schema requires
CREATE TABLE requires ( nameTEXT, flags TEXT, epoch TEXT, versionTEXT, releaseTEXT, pkgKey INTEGER , pre BOOLEAN DEFAULTFALSE);
CREATE INDEX pkgrequires on requires (pkgKey);
CREATE INDEX requiresname ON requires (name);

requires表的信息。

其余这几个表都是以packages表为基础,来补充存储rpm包的信息,比如prides,require,obsolete等信息。

如果你做一个程序,能够生成同样的数据文件,基本上就实现了createrepo在带-d参数时的效果。

知道了这些信息,当你的yum服务出现问题时,比如包不能更新,版本不对等问题时,就能通过这些文件来查找问题的原因。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值