yum repository的理解和创建自定义repository

一、yum的工作原理

    yum是一个RPM包的前端管理工具,在rpm包的依赖关系已经被建成数据库的前提下,它能够实现自动查找相互依赖的rpm包,并从repository中下载互相依赖的rpm包到本地。

bubuko.com,布布扣


二、如何建立yum的仓库repository

如果yumrepository不在同一台主机上,那么能够为yum提供repository仓库服务的远程服务器协议通常有两类:(1ftp://2http://

如果yumrepository在同一台主机上,那么yum就可以直接到某个目录中提取rpm包,而为了和远程服务器形成统一的风格,也会使用一个传输协议:file:///,因此如果仓库建在根目录/下,那么就可以使用file:///yum/这个路径来提取文件。


yum仓库的建立,需要分成服务端和客户端两部分:

A.服务端

 将所有需要用到的rpm包存放于某个目录之下,该目录可以是远程的(采用ftphttp协议),也可以是本地的(采用file协议)。目录建立好了之后,使用createrpo命令来提取目录下所有rpm包的元数据和依赖关系,生成一些xml格式的文件,这些xml文件会存放在repodata目录下,至此,服务器端repository就建立好了。注意repodata所在的位置,就是yum仓库的位置(主要针对红帽6,红帽5repository会分成4个目录,每个目录下都有一个repodata)。

扫描二维码关注公众号,回复: 2562492 查看本文章


B. 客户端

 客户端的配置非常简单,只需要使用yum及其子命令installreinstallremove即可。不过使用yum及其子命令之前,需要编辑配置文件,以告知yum命令仓库repository在什么地方。这个配置文件为:/etc/yum.conf。此外/etc/yum.repos.d/*.repo都被视为/etc/yum/conf的组成部分。

下面来查看一下/etc/yum.conf

 

[root@localhost ~]# vim/etc/yum

yum/         yum.conf     yum.repos.d/

 

观察yum.conf文件,其中中括号是用来做仓库定义的,中括号里的内容,即为仓库的名称,但是main除外,main是为其他仓库提供默认配置的。仓库可以有多个,但是main(全局配置)只有一个

 

[root@localhost ~]# vim/etc/yum.conf

[main]
# 全局配置,为其他仓库定义默认值
cachedir=/var/cache/yum/$basearch/$releasever
# 缓存目录为/var/cache/yum/$basearch/$releasever
keepcache=0
# rpm包是否需要在本地长久保存
debuglevel=2
# 调试级别,运行过程中的信息是否需要显示
logfile=/var/log/yum.log
# 日志文件,记录yum命令安装过的文件,执行过的操作等等,供以后检索使用
exactarch=1
# 下载的软件包是否需要和本地平台完全匹配(1表示是,0表示否)
obsoletes=1
gpgcheck=1
# 下载rpm包之前是否需要自动进行来源(签名)合法性检测,1表示要检查。
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&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 soyou‘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 oldpackages around. If you don‘t like this 
# checking interupting your command lineusage, it‘s much better to have 
# something manually check the metadataonce an hour (yum-updatesd will 
# do this). metadata_expire=90m  
# PUT YOUR REPOS HERE OR INseparate files named file.repo
# in /etc/yum.repos.d

 

如果要定义yum的仓库,可以在/etc/yum.repos.d下新建一个以repo结尾的文件:

 

[root@localhost ~]# cd/etc/yum.repos.d/

[root@localhost yum.repos.d]#ls

CentOS-Base.repo  CentOS-Debuginfo.repo  
CentOS-Media.repo  CentOS-Vault.repo
# CentOS-Base.repo是最终会生效的配置文件,建议先备份,然后对其进行修改


 配置文件的主要内容有:

[Repository_ID]    ——仓库的ID,可以取任意名字,只要不和其他的ID冲突即可

name=...               ——仓库的描述信息,长短不限,可以有空格,但是必不可少

baseurl=url           ——告诉yum客户端,通过哪种路径可以访问到

enabled={1|0}       ——是否启用这个仓库0表示不启用,1表示启用,默认是启用的

gpgcheck=1{1|0}  ——是否进行签名合法性检测,0表示不启用,1表示启用,默认启用。

                     如果选择启用gpg检查,则需要告知其key是什么。

gpgkey=url            ——如果启用gpg检测,则需要指定gpgkey的路径,即使导入过gpgkey

                     这里仍然需要手动为其指定路径,这个路径可以是远程服务器上的,

                     也可以是本地的,只要让本地客户端访问到即可。

cost=1000             ——访问的代价,定义了cost的,且数字较小的,会被优先访问。


如果两个仓库里的RPM包是一样的,一个在远程服务器上,另一个在本地光盘上,那么本地光盘的访问速度通常会快于远程服务器上。在配置文件中,我们可以定义这样的两个仓库,为其中一个设定优先级

 

下面来配置一个仓库。为了避免其他的仓库扰乱当前要定义的仓库,在配置之前,先编辑一下原有的CentOS-Base.repo文件:

[root@localhost yum.repos.d]#vim CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=0
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=0
# 将这个仓库禁用即可

 

[root@localhost yum.repos.d]#vim base.repo

[base]
name=CentOS 6.4 x86_64
baseurl=http://mirror.centos.org/centos/6.5/os/x86_64/
enabled=1
gpgcheck=0

 

下面来检测已经配置好的repository是否可以正常使用:


[root@localhost yum.repos.d]#yum list all | less
# list命令可以用来查看仓库里的程序包,后文会详解,这里只做检测用
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Repository base is listed more than once in theconfiguration
Loading mirror speeds from cached hostfile
Installed Packages
ConsoleKit.x86_64   0.4.1-3.el6 @anaconda-CentOS-201311272149.x86_64/6.5
# 软件包名称.平台版本  版本号-发行号 @anaconda表示系统已经安装了,来自于那个yum仓库
ConsoleKit-libs.x86_64 0.4.1-3.el6 @anaconda-CentOS-201311272149.x86_64/6.5
ConsoleKit-x11.x86_64  0.4.1-3.el6 @anaconda-CentOS-201311272149.x86_64/6.5
apr.i686                 1.3.9-5.el6_2                    base
                                       # base表示该程序在base仓库中,还没有安装
apr-devel.i686           1.3.9-5.el6_2                    base
apr-devel.x86_64         1.3.9-5.el6_2                    base
apr-util.i686            1.3.9-3.el6_0.1                  base

 

可以使用yum命令查看repository里的包,说明仓库已经建好了。

猜你喜欢

转载自blog.csdn.net/xfxfxfxfxf666/article/details/80632417