yum,是Yellow dog Updater, Modified 的简称,是杜克大学为了提高RPM 软件包安装性而开发的一种软件包管理器。yum 的理念是使用一个中心仓库(repository)管理一部分甚至一个distribution 的应用程序相互关系,根据计算出来的软件依赖关系进行相关的升级、安装、删除等等操作,减少了Linux 用户一直头痛的dependencies 的问题。这一点上,yum 和apt 相同。apt 原为debian 的deb 类型软件管理所使用,但是现在也能用到RedHat 门下的rpm 了。
yum 主要功能是更方便的添加/删除/更新RPM 包,自动解决包的倚赖性问题,便于管理大量系统的更新问题。
yum 可以同时配置多个资源库(Repository),简洁的配置文件(/etc/yum.conf),自动解决增加或删除rpm 包时遇到的依赖性问题,保持与RPM 数据库的一致性。
(一)yum的安装与卸载
1,查看该系统是否安装yum:
[root@localhost ~]# rpm -qa|grep yum yum-3.2.29-69.el6.centos.noarch yum-metadata-parser-1.1.2-16.el6.x86_64 yum-plugin-fastestmirror-1.1.30-30.el6.noarch
2,这表示已安装,如果没有安装的话,可以使用系统自带的ISO包来进行安装,一下操作为:
[root@localhost ~]# mount /dev/cdrom /mnt [root@localhost ~]# ll /mnt/Packages/ |grep yum* -r--r--r--. 3 root root 1019540 Feb 24 2013 yum-3.2.29-40.el6.centos.noarch.rpm -r--r--r--. 3 root root 27224 Sep 26 2011 yum-metadata-parser-1.1.2-16.el6.x86_64.rpm -r--r--r--. 3 root root 28220 Jun 25 2012 yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm rpm -ivh yum-3.2.29-40.el6.centos.noarch.rpm yum-metadata-parser-1.1.2-16.el6.x86_64.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm [root@localhost ~]# rpm -v
3,卸载的步骤为:
[root@localhost ~]# rpm -e yum-3.2.29-40.el6.centos.noarch.rpm | yum-metadata-parser-1.1.2-16.el6.x86_64.rpm | yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm [root@localhost ~]# rpm -qa|grep yum [root@localhost ~]#
(二)yum的配置文件的详解:
yum 的配置文件分为两部分:main 和repository
main 部分定义了全局配置选项,整个yum 配置文件应该只有一个main。常位于/etc/yum.conf 中。
repository 部分定义了每个源/服务器的具体配置,可以有一到多个。常位于/etc/yum.repo.d 目录下的各文件中。
[root@localhost ~]# cat /etc/yum.conf [main] cachedir=/var/cache/yum //yum 缓存的目录,yum 在此存储下载的rpm 包和数据库,默认设置为/var/cache/yum keepcache=0 //安装完成后是否保留软件包,0为不保留(默认为0),1为保留 debuglevel=2 //Debug 信息输出等级,范围为0-10,缺省为2 logfile=/var/log/yum.log //yum 日志文件位置。用户可以到/var/log/yum.log 文件去查询过去所做的更新。 pkgpolicy=newest //包的策略。一共有两个选项,newest 和last,这个作用是如果你设置了多个repository,而同一软件在不同的repository 中同时存在,yum 应该安装哪一个,如果是newest,则yum 会安装最新的那个版本。如果是last,则yum 会将服务器id 以字母表排序,并选择最后的那个服务器上的软件安装。一般都是选newest。 distroverpkg=redhat-release //指定一个软件包,yum 会根据这个包判断你的发行版本,默认是redhat-release,也可以是安装的任何针对自己发行版的rpm 包。 tolerant=1 //有1和0两个选项,表示yum 是否容忍命令行发生与软件包有关的错误,比如你要安装1,2,3三个包,而其中3此前已经安装了,如果你设为1,则yum 不会出现错误信息。默认是0。 exactarch=1 //有1和0两个选项,设置为1,则yum 只会安装和系统架构匹配的软件包,例如,yum 不会将i686的软件包安装在适合i386的系统中。默认为1。 retries=6 //网络连接发生错误后的重试次数,如果设为0,则会无限重试。默认值为6. obsoletes=1 //这是一个update 的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包。 plugins=1 //是否启用插件,默认1为允许,0表示不允许。我们一般会用yum-fastestmirror这个插件。 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum # Note: yum-RHN-plugin doesn‘t honor this. metadata_expire=1h installonly_limit = 5 # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
除了上述之外,还有一些可以添加的选项,如:
exclude=selinux* // 排除某些软件在升级名单之外,可以用通配符,列表中各个项目要用空格隔开,这个对于安装了诸如美化包,中文补丁的朋友特别有用。
gpgcheck=1 // 有1和0两个选择,分别代表是否是否进行gpg(GNU Private Guard) 校验,以确定rpm 包的来源是有效和安全的。这个选项如果设置在[main]部分,则对每个repository 都有效。默认值为0。
(三)配置本地的yum源
1,挂载安装光盘或ISO镜像
[root@localhost ~]# mount /dev/cdrom /mnt/ mount: block device /dev/sr0 is write-protected, mounting read-only mount: /dev/sr0 already mounted or /mnt/ busy mount: according to mtab, /dev/sr0 is already mounted on /mnt [root@localhost ~]# ll /mnt/ total 82 -r--r--r--. 1 root root 14 Nov 29 2013 CentOS_BuildTag dr-xr-xr-x. 3 root root 2048 Nov 29 2013 EFI -r--r--r--. 1 root root 212 Nov 28 2013 EULA -r--r--r--. 1 root root 18009 Nov 28 2013 GPL dr-xr-xr-x. 3 root root 2048 Nov 29 2013 images dr-xr-xr-x. 2 root root 2048 Nov 29 2013 isolinux dr-xr-xr-x. 2 root root 40960 Nov 29 2013 Packages -r--r--r--. 1 root root 1354 Nov 28 2013 RELEASE-NOTES-en-US.html dr-xr-xr-x. 2 root root 4096 Nov 29 2013 repodata -r--r--r--. 1 root root 1706 Nov 28 2013 RPM-GPG-KEY-CentOS-6 -r--r--r--. 1 root root 1730 Nov 28 2013 RPM-GPG-KEY-CentOS-Debug-6 -r--r--r--. 1 root root 1730 Nov 28 2013 RPM-GPG-KEY-CentOS-Security-6 -r--r--r--. 1 root root 1734 Nov 28 2013 RPM-GPG-KEY-CentOS-Testing-6 -r--r--r--. 1 root root 3380 Nov 29 2013 TRANS.TBL
2,配置本地的yum源:
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ll total 24 -rw-r--r--. 1 root root 1991 Aug 4 00:13 CentOS-Base.repo -rw-r--r--. 1 root root 647 Aug 4 00:13 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 289 Aug 4 00:13 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Aug 4 00:13 CentOS-Media.repo -rw-r--r--. 1 root root 6259 Aug 4 00:13 CentOS-Vault.repo [root@localhost yum.repos.d]# vim CentOS-Media.repo # CentOS-Media.repo # # This repo can be used with mounted DVD media, verify the mount point for # CentOS-6. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too: # yum --enablerepo=c6-media [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c6-media [command] [c6-media] name=CentOS-$releasever - Media baseurl=file:///mnt/Packages/ #####改成挂载的地址 file:///media/cdrom/ file:///media/cdrecorder/ gpgcheck=1 enabled=1 #####启用本地的yum源 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 -- INSERT --
3,禁用默认的yum网络源,否则会现在网络中寻找合适的包,改名后直接从本地源进行读取
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak [root@localhost yum.repos.d]#
4,执行yum源更新命令:
[root@localhost ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base c6-media extras updates Cleaning up Everything Cleaning up list of fastest mirrors [root@localhost ~]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.btte.net * c6-media: * extras: mirrors.btte.net * updates: mirrors.nwsuaf.edu.cn base | 3.7 kB 00:00 base/group_gz | 219 kB 00:00 base/filelists_db | 6.3 MB 00:00 base/primary_db | 4.6 MB 00:00 base/other_db | 2.8 MB 00:00 [root@localhost ~]# yum update Loaded plugins: fastestmirror Setting up Update Process Loading mirror speeds from cached hostfile * base: mirrors.btte.net * c6-media: * extras: mirrors.btte.net * updates: mirrors.nwsuaf.edu.cn [root@localhost ~]#
备注:关于repo 文件的格式
所有repository 服务器设置都应该遵循如下格式:
[serverid] name=Some name for this server baseurl=url://path/to/repository/
serverid 是用于区别各个不同的repository,必须有一个独一无二的名称;
name 是对repository 的描述,支持像$releasever $basearch这样的变量;
baseurl 是服务器设置中最重要的部分,只有设置正确,才能从上面获取软件。它的格式是:
baseurl=url://server1/path/to/repository/ url://server2/path/to/repository/ url://server3/path/to/repository/
其中url 支持的协议有 http:// ftp:// file:// 三种。baseurl 后可以跟多个url,你可以自己改为速度比较快的镜像站,但baseurl 只能有一个,也就是说不能像如下格式:
baseurl=url://server1/path/to/repository/ baseurl=url://server2/path/to/repository/ baseurl=url://server3/path/to/repository/
其中url 指向的目录必须是这个repository header 目录的上一级,它也支持$releasever $basearch 这样的变量。
url 之后可以加上多个选项,如gpgcheck、exclude、failovermethod 等,比如:
[updates-released] name=Fedora Core $releasever - $basearch - Released Updates baseurl=http://download.atrpms.net/mirrors/fedoracore/updates/$releasever/$basearch http://redhat.linux.ee/pub/fedora/linux/core/updates/$releasever/$basearch http://fr2.rpmfind.net/linux/fedora/core/updates/$releasever/$basearch gpgcheck=1 exclude=gaim failovermethod=priority
(四)配置国内yum源
系统默认的是国外的yum源,速度较慢,如何使用国内的yum源,以国内网易的163yum源为例:
1,下载repo文件
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost ~]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
2,备份并替换repo文件
[root@localhost ~]# mv CentOS-Base.repo CentOS-Base.repo.bak [root@localhost ~]# mv CentOS6-Base-163.repo CentOS-Base.repo
3,执行yum源更新命令
[root@localhost ~]# yum clean all root@localhost ~]# yum makecache [root@localhost ~]# yum update
4,导入GPG KEY
yum 可以使用gpg 对包进行校验,确保下载包的完整性,所以我们先要到各个repository 站点找到gpg key(由于我们使用的是163,可以在163官网上下载然后导入即可,下图),一般都会放在首页的醒目位置,一些名字诸如RPM-GPG-KEY-CentOS-5 之类的纯文本文件,把它们下载下来,然后用rpm --import RPM-GPG-KEY-CentOS-6 命令将key 导入
[root@localhost yum.repos.d]# wget http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6 --2015-12-24 13:59:16-- http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6 Resolving mirrors.163.com... 123.58.173.185, 123.58.173.186 Connecting to mirrors.163.com|123.58.173.185|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1706 (1.7K) [application/octet-stream] Saving to: “RPM-GPG-KEY-CentOS-6” 100%[==========================================================>] 1,706 --.-K/s in 0s 2015-12-24 13:59:23 (118 MB/s) - “RPM-GPG-KEY-CentOS-6” saved [1706/1706] [root@localhost yum.repos.d]# rpm --import RPM-GPG-KEY-CentOS-6 [root@localhost yum.repos.d]#
或者直接把该文件复制到/etc/pki/rpm-gpg/目录下即可
[root@localhost yum.repos.d]# cp RPM-GPG-KEY-CentOS-6 /etc/pki/rpm-gpg/
备注:以下是相关的配置文件的解释
[root@localhost yum.repos.d]# more CentOS-Base.repo # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base - 163.com baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-$releasever - Updates - 163.com baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - 163.com baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
关于变量
$releasever:代表发行版的版本,从[main]部分的distroverpkg获取,如果没有,则根据redhat-release包进行判断。
$arch:cpu体系,如i686,athlon等
$basearch:cpu的基本体系组,如i686和athlon同属i386,alpha和alphaev6同属alpha。
其他国内yum源列表如下:
1. 企业贡献:
搜狐开源镜像站:http://mirrors.sohu.com/
网易开源镜像站:http://mirrors.163.com/
2. 大学教学:
北京理工大学:
http://mirror.bit.edu.cn (IPv4 only)
http://mirror.bit6.edu.cn (IPv6 only)
北京交通大学:
http://mirror.bjtu.edu.cn (IPv4 only)
http://mirror6.bjtu.edu.cn (IPv6 only)
http://debian.bjtu.edu.cn (IPv4+IPv6)
兰州大学:http://mirror.lzu.edu.cn/
厦门大学:http://mirrors.xmu.edu.cn/
清华大学:
http://mirrors.tuna.tsinghua.edu.cn/ (IPv4+IPv6)
http://mirrors.6.tuna.tsinghua.edu.cn/ (IPv6 only)
http://mirrors.4.tuna.tsinghua.edu.cn/ (IPv4 only)
天津大学:http://mirror.tju.edu.cn/
中国科学技术大学:
http://mirrors.ustc.edu.cn/ (IPv4+IPv6)
http://mirrors4.ustc.edu.cn/
http://mirrors6.ustc.edu.cn/
东北大学:
http://mirror.neu.edu.cn/ (IPv4 only)
http://mirror.neu6.edu.cn/ (IPv6 only)
电子科技大学:http://ubuntu.uestc.edu.cn/
(五)使用第三方软件库
Centos/RHEL默认的yum软件仓库非常有限,仅仅限于发行版本那几张盘里面的常规包和一些软件包的更新,利用RpmForge,可以增加非常多的第三方rpm软件包。RpmForge库现在已经拥有超过10000种的CentOS的软件包,被CentOS社区认为是最安全也是最稳定的一个第三方软件库。
1、安装yum-priorities插件
这个插件是用来设置yum在调用软件源时的顺序的。因为官方提供的软件源,都是比较稳定和被推荐使用的。因此,官方源的顺序要高于第三方源的顺序。如何保证这个顺序,就需要安装yum-priorities这插件了。
[root@localhost yum.repos.d]# yum install yum-priorities Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package yum-plugin-priorities.noarch 0:1.1.30-30.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: yum-plugin-priorities noarch 1.1.30-30.el6 base 25 k Transaction Summary ==================================================================================================== Install 1 Package(s) Total download size: 25 k Installed size: 28 k Is this ok [y/N]: y Downloading Packages: yum-plugin-priorities-1.1.30-30.el6.noarch.rpm | 25 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : yum-plugin-priorities-1.1.30-30.el6.noarch 1/1 Verifying : yum-plugin-priorities-1.1.30-30.el6.noarch 1/1 Installed: yum-plugin-priorities.noarch 0:1.1.30-30.el6 Complete! [root@localhost yum.repos.d]#
2、安装完yum-priorities插件后需要设置/etc/yum.repos.d/ 目录下的.repo相关文件(如CentOS-Base.repo),在这些文件中插入顺序指令:priority=N (N为1到99的正整数,数值越小越优先)
一般配置[base], [addons], [updates], [extras] 的priority=1,[CentOSplus], [contrib] 的priority=2,其他第三的软件源为:priority=N (推荐N>10)
以CentOS-Base.repo 为例:
[base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 priority=1
3、下载与安装相应rpmforge的rpm文件包
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
[root@localhost yum.repos.d]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm Resolving tree.repoforge.org... 78.46.17.228 Connecting to tree.repoforge.org|78.46.17.228|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.i386.rpm [following] --2015-12-24 14:28:26-- http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.i386.rpm Resolving apt.sw.be... 193.1.193.67 Connecting to apt.sw.be|193.1.193.67|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 12680 (12K) [application/x-redhat-package-manager] Saving to: “rpmforge-release-0.5.2-2.el5.rf.i386.rpm” 100%[==========================================================>] 12,680 --.-K/s in 0s 2015-12-24 14:28:26 (400 MB/s) - “rpmforge-release-0.5.2-2.el5.rf.i386.rpm” saved [12680/12680]
[root@localhost yum.repos.d]# ll total 48 -rw-r--r--. 1 root root 2017 Dec 24 14:21 CentOS-Base.repo -rw-r--r--. 1 root root 1991 Aug 4 00:13 CentOS-Base.repo.bak -rw-r--r--. 1 root root 647 Aug 4 00:13 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 289 Aug 4 00:13 CentOS-fasttrack.repo -rw-r--r--. 1 root root 641 Dec 24 14:22 CentOS-Media.repo -rw-r--r--. 1 root root 6259 Aug 4 00:13 CentOS-Vault.repo -rw-r--r--. 1 root root 12680 Nov 13 2010 rpmforge-release-0.5.2-2.el5.rf.i386.rpm -rw-r--r--. 1 root root 1706 Jul 10 2011 RPM-GPG-KEY-CentOS-6
4、安装DAG的PGP Key
# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
[root@localhost yum.repos.d]# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt [root@localhost yum.repos.d]#
5、验证rpmforge的rpm文件包
# rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
[root@localhost yum.repos.d]# rpm -K rpmforge-release-0.5.2-2.el5.rf.i386.rpm rpmforge-release-0.5.2-2.el5.rf.i386.rpm: (sha1) dsa sha1 md5 gpg OK [root@localhost yum.repos.d]#
6、安装rpmforge的rpm文件包
# rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm
[root@localhost yum.repos.d]# rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm [root@localhost yum.repos.d]#
7、设置/etc/yum.repos.d/rpmforge.repo文件中源的级别
[root@localhost yum.repos.d]# cat /etc/yum.repos.d/rpmforge.repo ### Name: RPMforge RPM Repository for RHEL 5 - dag ### URL: http://rpmforge.net/ [rpmforge] name = RHEL $releasever - RPMforge.net - dag baseurl = http://apt.sw.be/redhat/el5/en/$basearch/rpmforge mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge #mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge enabled = 1 protect = 0 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag gpgcheck = 1 [rpmforge-extras] name = RHEL $releasever - RPMforge.net - extras baseurl = http://apt.sw.be/redhat/el5/en/$basearch/extras mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge-extras #mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-extras enabled = 0 protect = 0 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag gpgcheck = 1 [rpmforge-testing] name = RHEL $releasever - RPMforge.net - testing baseurl = http://apt.sw.be/redhat/el5/en/$basearch/testing mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge-testing #mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-testing enabled = 0 protect = 0 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag gpgcheck = 1 [root@localhost yum.repos.d]#
8、测试安装
# yum install htop
[root@localhost yum.repos.d]# yum install htop Loaded plugins: fastestmirror, priorities Setting up Install Process Loading mirror speeds from cached hostfile * rpmforge: ftp.riken.jp rpmforge | 1.9 kB 00:00 rpmforge/primary_db | 7.0 MB 00:01 2507 packages excluded due to repository priority protections Resolving Dependencies --> Running transaction check ---> Package htop.x86_64 0:1.0.3-1.el5.rf will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: htop x86_64 1.0.3-1.el5.rf rpmforge 97 k Transaction Summary ==================================================================================================== Install 1 Package(s) Total download size: 97 k Installed size: 207 k Is this ok [y/N]: y Downloading Packages: htop-1.0.3-1.el5.rf.x86_64.rpm | 97 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : htop-1.0.3-1.el5.rf.x86_64 1/1 Verifying : htop-1.0.3-1.el5.rf.x86_64 1/1 Installed: htop.x86_64 0:1.0.3-1.el5.rf Complete! [root@localhost yum.repos.d]#
(六)yum自建仓库
1, 准备材料: N个rpm包,比如我把CENTOS7安装镜像中的Packages目录复制到指定的目录
[root@localhost Packages]# mkdir /home/repo [root@localhost Packages]# cp de* /home/repo/ [root@localhost Packages]# ll /home/repo/ total 3284 -r--r--r--. 1 root root 168376 Dec 24 14:51 device-mapper-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 118268 Dec 24 14:51 device-mapper-event-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 112840 Dec 24 14:51 device-mapper-event-libs-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 199876 Dec 24 14:51 device-mapper-libs-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 118840 Dec 24 14:51 device-mapper-multipath-0.4.9-72.el6.x86_64.rpm -r--r--r--. 1 root root 184716 Dec 24 14:51 device-mapper-multipath-libs-0.4.9-72.el6.x86_64.rpm -r--r--r--. 1 root root 2444328 Dec 24 14:51 device-mapper-persistent-data-0.2.8-2.el6.x86_64.rpm
2,安装createrepo
[root@localhost yum.repos.d]# yum createrepo
3,使用createrepo命令创建yum仓库
[root@localhost Packages]# createrepo -o /home/repo/ /home/repo/ ###-o用于指定repodata生产的位置,最后的参数是rpm包所在的位置 Spawning worker 0 with 7 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete [root@localhost Packages]# ll /home/repo/ total 3288 -r--r--r--. 1 root root 168376 Dec 24 14:51 device-mapper-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 118268 Dec 24 14:51 device-mapper-event-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 112840 Dec 24 14:51 device-mapper-event-libs-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 199876 Dec 24 14:51 device-mapper-libs-1.02.79-8.el6.x86_64.rpm -r--r--r--. 1 root root 118840 Dec 24 14:51 device-mapper-multipath-0.4.9-72.el6.x86_64.rpm -r--r--r--. 1 root root 184716 Dec 24 14:51 device-mapper-multipath-libs-0.4.9-72.el6.x86_64.rpm -r--r--r--. 1 root root 2444328 Dec 24 14:51 device-mapper-persistent-data-0.2.8-2.el6.x86_64.rpm drwxr-xr-x. 2 root root 4096 Dec 24 14:55 repodata [root@localhost Packages]#
3,使用vim创建yum repo文件
[root@localhost yum.repos.d]# vim CentOS-My.repo [local] ###指定yum源名 name=my rpm base from local ###yum名字的描述 baseurl= ###指定URL或使用“file://”指定本地路径,注意“/”的数量; gpgcheck=0 ###不验证来源及package的完整性(由于是本地的文件) enable=1 ###启用此yum源
4, 清除缓存,并重新构建yum缓存
[root@localhost yum.repos.d]# yum clean all ###清除yum缓存 Loaded plugins: fastestmirror, priorities Cleaning repos: base extras local rpmforge updates Cleaning up Everything Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# yum repolist ###重建yum缓存 Determining fastest mirrors * rpmforge: mirror-fpt-telecom.fpt.net base | 3.7 kB 00:00 base/primary_db | 4.6 MB 00:05 extras | 2.9 kB 00:00 extras/primary_db | 33 kB 00:00 file://home/repo/repodata/repomd.xml: [Errno 14] Could not open/read file://home/repo/repodata/repomd.xml Trying other mirror. file://home/repo/repodata/repomd.xml: [Errno 14] Could not open/read file://home/repo/repodata/repomd.xml Trying other mirror. rpmforge | 1.9 kB 00:00 rpmforge/primary_db | 7.0 MB 00:14 updates | 3.4 kB 00:00 updates/primary_db | 3.3 MB 00:00 repo id repo name status base CentOS-6 - Base - 163.com 6,575 extras CentOS-6 - Extras - 163.com 48 local my rpm base from local ###local为自己创建的yum 源 0 rpmforge RHEL 6 - RPMforge.net - dag 11,403 updates CentOS-6 - Updates - 163.com 958 repolist: 18,984 [root@localhost yum.repos.d]#
至此yum的使用和配置完成可参考:参考 http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-5aabf02717d5b6b12d47edbc5811404998926a1b,
非常感谢David_Tang(http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html)
本文出自 “清风明月” 博客,请务必保留此出处http://liqingbiao.blog.51cto.com/3044896/1727894
原文地址:http://liqingbiao.blog.51cto.com/3044896/1727894