RedHat配置YUM 从centos5源与光盘源更新软件

YUM顾名思义,Yellow Dog Updater,Modified.Yum为基于RPM系统做了相同的工作。它提供了一个简单的命令,可用于在首先安装和更新任何其他必要的软件包以满足所需的软件包依赖关系之后,自动化安装或更新一个软件包,类似Debian下apt-get的工具.
 
YUM的特点
可以同时配置多个资源库(Repository)
简洁的配置文件(/etc/yum.conf
自动解决增加或删除rpm包时遇到的倚赖性问题
使用方便
保持与RPM数据库的一致性
 
RHEL AS5可以通过Yum升级系统的功能,但默认rhel-debuginfo.repo 的设置是从RedHat的Yum源来升级系统,如果您没有购买Redhat的服务,Redhat5后面版本升级是收费,需要key才能升级,那么使用Yum是无法升级的。幸运的是,由于centos是免费的企业版本,可以借用centos yum源更新RHEL AS5系统.
 
配置YUM 从centos5源更新软件
 
安装那个ftp.twaren.netGPG,也可增加其他资源库,自己选择一个离自己地理位置近点
[root@clinet ~]# rpm -qa gpg-pubkey*
检查GPG Key
gpg-pubkey-e8562897-459f07a4
如果要删除Key,使用以下命令:
[root@clinet ~]# rpm -e gpg-pubkey-e8562897-459f07a4
 
[root@clinet ~]# vi /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/
baseurl是你的YUM源地址
enabled=0
是否启用这个仓库,1为起用,0为禁用
gpgcheck=1 
设置gpgcheck=1会让yum检查每个下载的RPMGnuPG签名。这么做是因为你需要适当的GnuPG key注册到您的RPM数据库。可以防止被欺骗,如:非法入侵发行版网站,木马导入软件包,使不知情用户下载
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
GPGKEY 的存放地址
 
以上默认有的,复制添加以下更新点插入到rhel-debuginfo.repo文本里后面
 [base]
name=Red Hat Enterprise Linux $releasever -Base
baseurl=http://ftp.twaren.net/Linux/CentOS/5/os/$basearch/
gpgcheck=1
[update]
name=Red Hat Enterprise Linux $releasever -Updates
baseurl=http://ftp.twaren.net/Linux/CentOS/5/updates/$basearch/
gpgcheck=1
[extras]
name=Red Hat Enterprise Linux $releasever -Extras
baseurl=http://ftp.twaren.net/Linux/CentOS/5/extras/$basearch/
gpgcheck=1
[addons]
name=Red Hat Enterprise Linux $releasever -Addons
baseurl=http://ftp.twaren.net/Linux/CentOS/5/addons/$basearch/
gpgcheck=1
[root@clinet ~]#yum clean all 清除缓存及旧的包
[root@clinet ~]# yum install httpd 测试是否能更新软件
 

注意:当第一次使用yumyum资源库有更新时,yum自动下载所有所需的headers放置于/var/cache/yum目录下,所需时间可能较长.请耐心等待,所以后面会显示一连串数据.

配置YUM 从本地光盘更新软件
[root@clinet ~]# mkdir /mnt/cdrom
创建挂载点
[root@clinet ~]# mount /dev/cdrom /mnt/cdrom
挂载光盘
mount: block device /dev/cdrom is write-protected, mounting read-only
 
[root@clinet /]# ll /etc/yum.repos.d/
total 4
-rw-r--r-- 1 root root 781 Feb 24 03:19 rhel-debuginfo.repo
[root@clinet /]# cd /etc/yum.repos.d/
[root@clinet yum.repos.d]# cp rhel-debuginfo.repo rhel-debuginfo.repo.bak
拷贝为rhel-debuginfo.repo.bak做备份
[root@clinet yum.repos.d]# ll
total 8
-rw-r--r-- 1 root root 781 Feb 24 03:19 rhel-debuginfo.repo
-rw-r--r-- 1 root root 781 Feb 25 00:34 rhel-debuginfo.repo.bak
[root@clinet yum.repos.d]# vi rhel-debuginfo.repo
编辑rhel-debuginfo.repo,插入以下代码
 
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
 
其实上面这样设置就已经ok,但是要更新xen.rpm,就更新不到,因为它在/mnt/cdrom/VT下面,为了比较完善,我们修改参数为以下配置
 
[Cluster]
name=Red Hat Enterprise Linux $releasever - $basearch - Cluster
baseurl= file:///mnt/cdrom/Cluster
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[ClusterStorage]
name=Red Hat Enterprise Linux $releasever - $basearch - ClusterStorage
baseurl= file:///mnt/cdrom/ClusterStorage
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[Server]
name=Red Hat Enterprise Linux $releasever - $basearch - Server
baseurl= file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[VT]
name=Red Hat Enterprise Linux $releasever - $basearch - VT
baseurl= file:///mnt/cdrom/VT
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
 
[root@clinet yum.repos.d]# yum clean all
清除缓存及旧的包
Loaded plugins: rhnplugin, security
Cleaning up Everything
[root@clinet yum.repos.d]# yum install httpd
测试是否能更新软件
yum常用的源
1) 自动选择最快的源
由於yum中有的mirror速度是非常慢的,如果yum选择了这个mirror,这时yum就会非常慢,对此,可以下载fastestmirror插件,它会自动选择最快的mirror:
#yum install yum-fastestmirror
配置文件:(一般不用改)/etc/yum/pluginconf.d/fastestmirror.conf
你的yum镜像的速度测试记录文件:/var/cache/yum/timedhosts.txt
2)使用图形界面的yum
如果觉得命令行的yum不方便,那么可以使用图形化的yumex,这看起来更方便,因为可以自由地选择软件仓库:
#yum install yumex
然後在系统工具中就可以看到yum extender了。实际上系统自带的“添加/删除程式“也可以实现图形化的软件,但有些yumex的功能它没有。

补充:
yum本地源的配置与使用

  a:挂载你的光盘到一个目录下:mount -t iso9660 /dev/cdrom /mnt/cdrom

  b:修改你的yum配置文件:编辑 /etc/yum.repos.d/rhel-debuginfo.repo 文件,里面有给

  [rhel-debuginfo]

  name=Red Hat Enterprise Linux $releasever - $basearch - Debug

  baseurl=file:///mnt/cdrom/Server

  enabled=1

  gpgcheck=0

  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

  主要是baseurl,enabled,gpgcheck字段的配置,本地就是要使用file://absolute path.

  保存并退出。

  c:yum update

  这里有想必大家有个疑问,光盘放进光驱后,如果能识别的话就已经自动挂载到了/media下为什么我们还要费事手动挂载呢?这个倒是必须的,因为你不挂载的话你yum需要的repodata文件是没有任何东西的,因为yum要去读这个文件才会自动给你解决依赖关系的。

还有一个想要与大家一起学习的就是,在你没有盘,只有iso文件时怎么办?很简单,一条命令解决 mount -o loop /xx/xx/xxx.iso /mnt/cdrom你可以继续了。
posted @ 2010-11-25 13:58  chinacloud  阅读(7312)  评论(0编辑  收藏  举报