分享

Linux下使用Yum管理本地软件包(repository)

 lchjczw 2013-03-10

在Linux系统的维护中,Linux软件包之间的依赖性是一件令人十分头痛的事情。比如你要安装软件包A,但是安装的时候提示你在安装A前得先安装软件包B;而当你去安装软件包B时,又提示你得先安装C库... 为了解决此问题,我们得使用Linxu下的yum(Yellow dog Updater,Modified) 工具。yum工具能根据repository(软件仓库)中rpm包的各种header信息,自动安装依赖的包,解决依赖性问题。在linux下使用yum的添加/删除/更改rpm包十分方便!此文来自:http://www./


下面是linux下一个简单的yum配置和使用过程:
1. 实验环境
操作系统:Red Hat Enterprise Linux AS 5
内核版本:2.6.18-8.el5
 CPU构架:i386 SMP
附件软件:Red Hat Enterprise Linux AS 5 DVD ISO文件


2. 在linux下安装yum并建立repository(软件仓库)

  1. #在linux系统下挂载rhel 5.0 dvd iso文件  
  2. mkdir -p /mnt/iso  
  3. mount -o loop /opt/rhel5.0.iso /mnt/iso  
  4.  
  5. #在linux系统下安装yum,createrepo包  
  6. rpm -ivh /mnt/ISO/Server/yum-3.0.1-5.el5.noarch.rpm  
  7. rpm -ivh /mnt/ISO/Server/yum-metadata-parser-1.0-8.fc6.i386.rpm  
  8. rpm -ivh /mnt/ISO/Server/yum-rhn-plugin-0.4.3-1.el5.noarch.rpm  
  9. rpm -ivh /mnt/ISO/Server/yum-updatesd-3.0.1-5.el5.noarch.rpm  
  10. rpm -ivh /mnt/ISO/Server/createrepo-0.4.4-2.fc6.noarch.rpm  
  11.  
  12. #将挂载的iso中的文件复制到/opt/rhel5.0目录中  
  13. mkdir /opt/rhel5.0 
  14. cp -R /mnt/ISO/* /opt/rhel5.0 
  15.  
  16. #重新生成repository(软件仓库)相关文件,生成的文件在当前目录的“repodata”文件夹下。
  17. cd /opt/rhel5.0/Server/  
  18. rm -rf repodata  
  19. createrepo -g /mnt/ISO/Server/repodata/comps-rhel5-server-core.xml ./  


3. 在linux配置yum
在/etc/yum.repos.d/目录下建立一个后缀为.repo的配置文件,如:rhel_yum.repo(该目录下的其他文件可以删除),rhel_yum.repo内容如下:此文来自:http://www./

  1. [Server]  
  2. name=Server  
  3. baseurl=file:///opt/rhel5.0/Server/
  4. #注意baseurl指向我们的repository(软件仓库)/opt/rhel5.0/Server目录  
  5. enable=1  
  6. gpgcheck=0 

此文来自:http://www./
4. 测试rhel5.0 linux下的yum

  1. #清除yum设置缓存      
  2. yum clean all     
  3.  
  4. #查看已安装的和未安装的软件包组    
  5. yum grouplist    
  6.  
  7. #安装Web Server包组    
  8. yum groupinstall "Web Server" 
  9.  
  10. #查看组信息   
  11. yum groupinfo "Web Server" 
  12. 此文来自:http://www./
  13. #删除"MySQL Database"  
  14. yum groupremove "MySQL Database" 
  15.  
  16. #升级"MySQL Database"  
  17. yum groupupdate "MySQL Database" 

 

5. linux下yum安装的常见问题

①. 问:为什么要把挂载的ISO镜像中的文件复制到本地磁盘上,而不直接在挂载的iso文件系统中使用?
  答:因为我们必须重新生成repository的相关配置文件,而挂载的iso文件系统是不可写的,所以必须复制到本地磁盘中去。
②. 问:当我们配置好后执行 "yum groupinstall 'MySQL Database' " 安装时报如下错误,是怎么回事?

  1. yum groupinstall "MySQL Database" 
  2. Loading "installonlyn" plugin  
  3. Loading "rhnplugin" plugin  
  4. This system is not registered with RHN.  
  5. RHN support will be disabled.  
  6. Setting up Group Process  此文来自:http://www./
  7. Setting up repositories  
  8. Setting up repositories  
  9. Reading repository metadata in from local files  
  10. primary.xml.gz            100% |=========================| 663 kB    00:00 
  11. ################################################## 2113/2113  
  12. Resolving Dependencies  
  13. --> Populating transaction set with selected packages. Please wait.  
  14. ---> Downloading header for mysql to pack into transaction set.  
  15. media://1170972069.396645%232/mysql-5.0.22-2.1.i386.rpm: [Errno 4] IOError:   
  16.  此文来自:http://www./
  17. <urlopen error unknown url type: media>  
  18. Trying other mirror.  
  19. Error: failed to retrieve mysql-5.0.22-2.1.i386.rpm from s  
  20. error was [Errno 4] IOError: <urlopen error unknown url type: media> 

  答:请确定"/etc/yum.repos.d/rhel_yum.repo"文件中的"baseurl"指向的不是挂载的iso文件系统路径,而是本地磁盘文件系统路径,如此文的第三步的中的第三行。并且确定使用了第二步的第九行重新生成了repository配置文件。其实"media://1170972069.396645#1"就是rhel 5.0 dvd iso 中的Server/repodata/repomd.xml文件的配置值。此文来自:http://www./
③. 问:为什么我执行"yum grouplist"命令后没有列出任何包组信息?如下:

  1. #yum grouplist  
  2. Loading "installonlyn" plugin  
  3. Loading "rhnplugin" plugin  
  4. This system is not registered with RHN.  
  5. RHN support will be disabled.  
  6. Setting up Group Process  
  7. Setting up repositories  
  8. Server                    100% |=========================|  951 B    00:00 
  9. Done 

答:请确定执行了createrepo命令重新生成repository配置文件,并且命令带了 "-g"选项,如第二步第19行所示。rhel 5.0 dvd iso中的"Server/repodata/comps-rhel5-serer-core.xml"即包含了rpm包的分组信息。此文来自:http://www./

好了,Linux下使用Yum管理本地软件包就写到此了,有什么问题欢迎随时给我留言。

此文章由 Admin 于 2010-06-29 22:51:29 编辑

本日志由 Admin 于 2010-06-26 18:29:14 发表,目前已经被浏览 1421 次,评论 5 次;

作者添加了以下标签: LinuxYumRepositoryRhel

引用通告:http://www./Article/26/Trackback.ashx

评论订阅:http://www./Article/26/Feeds.ashx

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多