[转]rpm与yum(本地yum源的安装)

来源:互联网 发布:法国达索软件 待遇 编辑:程序博客网 时间:2024/06/08 17:58
给一个理由--为什么要构建本地源
      在Linux主机中使用YUM工具在线升级、安装软件时,往往受到网络连接速度、带宽的限制,导致软件安装耗时过长甚至失败。特别是当有大量服务器、大量软件包需要升级时,更新的缓慢程度可能令人难以忍受。
相比较而言,本地YUM源服务器最大的优点---在于局域网的快速网络连接和稳定性。有了局域网中的YUM源服务器,即便在Internet连接中断的情况下,也不会影响其他YUM客户端的软件升级和安装。
那么,如何构建本地源呢?

通过从DVD光盘、YUM客户端缓存目录(/var/cache/yum /)以及Internet下载等途径获取需要的rpm包,可以组建基于本地文件系统的rpm软件包仓库。进一步结合使用HTTP或FTP协议的服务软件,即可构建一个位于本地局域网的高速YUM“源”服务器。
以下案例中使用RHEL5安装光盘(DVD)中的软件包组成软件仓库,并结合VSFTPD服务,提供基于FTP方式的简易YUM源。实现的主要步骤如下。
安装vsftpd、createrepo软件包

createrepo工具主要用于收集目录中rpm包文件的头信息,以创建repodata软件仓库数据(经gzip压缩的xml文件)。
[root@www ~]# mkdir /media/mnt/
[root@www ~]# mount /dev/cdrom /media/mnt/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@www ~]# cd /media/mnt/Server/
[root@www Server]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
        package createrepo-0.4.11-3.el5.noarch is already installed
[root@www Server]# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm
warning: vsftpd-2.0.5-16.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
   1:vsftpd                 ########################################### [100%]
准备软件库目录
注意要保证/var/ftp/rhel5目录有足够的可用空间(在本例中最好大于3GB),以便存放复制的软件包。必要时可以使用单独的硬盘分区(挂载到/var/ftp/rhel5目录中)。
[root@www Server]# mkdir -p /var/ftp/rhel5
[root@www Server]# cp -prf /media/mnt/* /var/ftp/rhel5/    //这个时间有点长

查看复制好的目录结构:Cluster、ClusterStorage、Server、VT——主要是光盘中包含rpm软件包的几个文件夹)。
[root@www Server]# ls -lh /var/ftp/rhel5/ | grep ^d
dr-xr-xr-x 3 root root 4.0K 2009-08-19 Cluster
dr-xr-xr-x 3 root root 4.0K 2009-08-19 ClusterStorage
dr-xr-xr-x 4 root root 4.0K 2009-08-19 images
dr-xr-xr-x 2 root root 4.0K 2009-08-19 isolinux
dr-xr-xr-x 3 root root 140K 2009-08-19 Server
dr-xr-xr-x 3 root root 4.0K 2009-08-19 VT
创建repository仓库信息文件
在各个软件包目录中分别执行createrepo命令,生成当前目录下的repodata数据。使用-g选项可以指定用于创建组信息的xml文件模板。
[root@www Server]# cd /var/ftp/rhel5/Cluster
[root@www Cluster]# createrepo -g repodata/comps-rhel5-cluster.xml ./
[root@www Cluster]# cd /var/ftp/rhel5/ClusterStorage/
[root@www ClusterStorage]# createrepo -g repodata/comps-rhel5-cluster-st.xml ./
[root@www ClusterStorage]# cd /var/ftp/rhel5/Server/
[root@www Server]# createrepo -g repodata/comps-rhel5-server-core.xml ./

[root@www Server]# cd /var/ftp/rhel5/VT/
[root@www VT]# createrepo -g repodata/comps-rhel5-vt.xml ./
[root@www VT]# rm -rf /var/ftp/rhel5/*/.olddata/   //清除旧的数据文件

配置启动vsftpd服务(开启默认的匿名FTP服务即可)
[root@www ~]# chkconfig --level 2345 vsftpd on
[root@www ~]# service vsftpd start
为 vsftpd 启动 vsftpd:                                    [确定]

若FTP服务无法访问,请参考以下配置重新启动vsftpd服务:
[root@www ~]# vi /etc/vsftpd/vsftpd.conf
使用yum工具安装软件
最常用的YUM客户端工具是字符模式下的yum命令,在RHEL5系统中由默认安装的yum-3.0.1-5.el5软件包提供。RHEL5系统还提供了一个图形YUM工具pirut,该工具只是yum工具的一个X图形前端。
设置YUM源位置
使用YUM源服务器之前,必须为客户端建立指定的配置文件,设置好源服务器的位置和可用目录等选项。
[root@client ~]# cd /etc/yum.repos.d/
[root@client yum.repos.d]# vi rhel5-pkgs-yumsvr.repo //新建配置文件,名称自定
[Cluster]
name=Cluster Directory
baseurl=ftp://192.168.0.11/rhel5/Cluster
enabled=1 //启用该目录
gpgcheck=0 //不检查gpg key
[ClusterStorage]
name=ClusterStorage Directory
baseurl=ftp://192.168.0.11/rhel5/ClusterStorage
enabled=1
gpgcheck=0
[Server]
name=Server Directory
baseurl=ftp://192.168.0.11/rhel5/Server
enabled=1
gpgcheck=0
[VT]
name=VT Directory
baseurl=ftp://192.168.0.11/rhel5/VT
enabled=1
gpgcheck=0
[root@client yum.repos.d]# yum clean all //更新缓存

使用yum命令
列表查看软件包信息
可以使用list选项查看软件包相关的各项信息。
[root@client ~]# yum list updates //查看有哪些可用于升级的软件包
[root@client ~]# yum list installed //查看本机已安装的软件包
[root@client ~]# yum list available //查看yum源中所有可用的软件包
[root@client ~]# yum list available lynx* //查看yum源中以lynx开头的软件包
[root@client ~]# yum info installed bind //查看已安装的bind软件包的信息

软件包升级、卸载、安装
升级(update)、卸载(remove)、安装(install)软件包时,系统会自动检查并解决软件包之间的依赖关系。开始各项操作前,系统会提示用户按y键进行确认(如果希望系统自动回答为y,可以在yum命令后增加-y选项)。
[root@client ~]# yum -y update //升级所有可用的软件包,由系统自动确认
[root@client ~]# yum update bind //升级bind软件包
[root@client ~]# yum remove net-snmp-utils //卸载net-snmp-utils软件包
[root@client ~]# yum install lynx //安装lynx软件包

使用图形工具“添加删除程序”
在RHEL5系统中,进入X-Windows图形模式以后,可以使用系统自带的“添加删除程序”工具(pirut)进行软件包的升级、安装、卸载等管理。
点击GNOME面板菜单组“应用程序”中的“添加删除程序”,或者运行“pirut”就可以打开该工具(如图1.1所示)。运行RHEL5提供的系统配置链接“system-config-packages”也可以打开该工具。

 

原创粉丝点击