一、 Yum 的简介
Yum (全称为 Yellow dog Updater, Modified )是一个在 Fedora RedHat 以及 SUSE CentOS 中的 Shell 前端软件包管理器。基於 RPM 包管理,能够从指定的服务器自动下载 RPM 包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
yum 的宗旨是自动化地升级,安装 / 移除 rpm 包,收集 rpm 包的相关信息,检查依赖性并自动提示用户解决 yum 的关键之处是要有可靠的 repository ,顾名思义,这是软件的仓库,它可以是 http ftp 站点,也可以是本地软件池,但必须包含 rpm header header 包括了 rpm 包的各种信息,包括描述,功能,提供的文件,依赖性等 . 正是收集了这些 header 并加以分析,才能自动化地完成余下的任务。
Yum 常用的命令
 
二、配置网络 yum
服务器端配置,服务器的 ip 地址为 192.168.10.10 ,可以再 yum 服务器采用 http ftp 服务器两种方式
ftp 方式实现 yum
案例图

挂载光盘
[root@localhost ~]# mkdir /mnt/cdrom/
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
安装 vsftp 的软件包
[root@localhost Server]# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm
[root@localhost Server]# service vsftpd start                  ## 启动 ftp 服务器
[root@localhost Server]# chkconfig vsftpd on                 ## 开机启动
[root@localhost ~]# cp -r /mnt/cdrom/. /var/ftp/pub/ ## 把光盘文件拷贝到 ftp 服务器的目录下
[root@localhost ~]# cd /var/ftp/pub/           
[root@localhost pub]# du -sh
2.9G     
yum 客户端配置

vim /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-server]                            ## 描述光盘上的仓库
name=Red Hat Enterprise Linux server      ## 仓库的名字
baseurl=ftp://192.168.10.10/pub/Server      ## 网络 yum 源的位置
enabled=1                             ## 启用该仓库
gpgcheck=1                                    ## 启用签名检测
gpgkey=ftp://192.168.10.10/pub/RPM-GPG-KEY-redhat-release## 检测钥匙文件
[rhel-vt]
name=Red Hat Enterprise Linux vt
baseurl=ftp://192.168.10.10/pub/VT       ## 虚拟化
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.10.10/pub/RPM-GPG-KEY-redhat-release
[rhel-cluster]
name=Red Hat Enterprise Linux cluster       ## 集群
baseurl=ftp://192.168.10.10/pub/Cluster
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.10.10/pub/RPM-GPG-KEY-redhat-release
[rhel-clusterstorage]
name=Red Hat Enterprise Linux clusterstorage   ## 存储
baseurl=ftp://192.168.10.10/pub/ClusterStorage
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.10.10/pub/RPM-GPG-KEY-redhat-release
yum 常用的命令
查看仓库列表
[root@station yum.repos.d]# yum repolist
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
repo id                repo name                                  status
rhel-cluster           Red Hat Enterprise Linux cluster           enabled:    32
rhel-clusterstorage    Red Hat Enterprise Linux clusterstorage    enabled:    39
rhel-server            Red Hat Enterprise Linux server            enabled: 2,292
rhel-vt                Red Hat Enterprise Linux vt                enabled:    36
repolist: 2,399
查看未安装的软件包
[root@station yum.repos.d]# yum list available
查看已安装的软件包
[root@station ~]# yum list installed
查看 httpd 的进本信息
[root@station ~]# yum info httpd <package_name>
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Available Packages
Name       : httpd
Arch       : i386
Version    : 2.2.3
Release    : 31.el5
Size       : 1.2 M
Repo       : rhel-server
Summary    : Apache HTTP 服务器
URL        : http://httpd.apache.org/
License    : Apache Software License
Description: The Apache HTTP Server is a powerful, efficient, and extensible
           : web server.
安装软件包
[root@station ~]# yum -y install httpd ## 显示 Complete!时 表示安装成功                          
卸载软件包
[root@station ~]# yum -y remove httpd  ## 当显示 Complete! 时表示成功卸载
查找某个软件包
[root@station ~]# yum search httpd
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
================================ Matched: httpd ================================
mod_ssl.i386 : Apache HTTP 服务器的 SSL/TLS 模块
system-config-httpd.noarch : Apache 配置工具。
httpd.i386 : Apache HTTP 服务器
httpd-devel.i386 : Apache HTTP 服务器的开发工具。
httpd-manual.i386 : Apache HTTP 服务器的文档。
mod_dav_svn.i386 : Subversion 服务器的 Apache 服务器模块。
列出所有或者某个可更新的软件清单
[root@station ~]# yum check-update  <pack-name>
安装所有或者某个更新的软件包
[root@station ~]# yum update  <package_name>
仅更新指定的软件  yum update <package_name>
安装一个或者多个软件组  yum groupinstall group1 group2
更新软件组               yum groupupdate group1
卸载一个软件组           yum groupremove group1
查看一个软件组信息       yum groupinfo    group1
列出软件组               yum grouplist    all
假设 yum 服务器端上传了一个新的软件包 php-4.2.6-3.e15.i386.rpm ,我们在 yum 客户端可以找到么?
在客户端执行 yum list |grep php-4.2 ,系统给出如下提示没有找到
[root@station ~]# yum list | php-4.2
This system is not registered with RHN.
RHN support will be disabled.
这是为什么呢?我们清空一下缓存再来看看,依然没有找到
[root@station ~]# yum clean all
Loaded plugins: rhnplugin, security
Cleaning up Everything
[root@station ~]# yum list |grep php-4.2
This system is not registered with RHN.
RHN support will be disabled.
这是因为所有文件的信息都保存在每一个仓库的 primary.xml.gz 文件,现在放进去一个新的包,但是 primary.xml.gz 文件没有变化,必须重新产生,重新产生前需要在服务器上装一个名字为 createrepo-0.4.11-3.el5.noarch.rpm 的软件包
[root@localhost Server]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
执行 createrepo -g 表示组文件放在 repodata 文件 ./ 表示组文件针对当前仓库 Server
[root@localhost Server]# createrepo -g ./repodata/comps-rhel5-server-core.xml ./
primary.xml.gz 文件的产生依赖 /comps-rhel5-server-core.xml 这个文件,仓库没有变化时无需外来的软件包加到仓库里边
Saving Primary metadata
Saving file lists metadata
Saving other metadata
表示 primary.xml.gz 文件已经重新生成
在客户端重新查找
[root@station ~]# yum list all |grep php-4.2
This system is not registered with RHN.
RHN support will be disabled.
php.i386                           4.2.6-3.e15           rhel-server   
假如在本地有一个软件包 zsh-html.4.26-3.e15.i386.rpm 想利用网络 yum 服务器的 yum 实现依赖关系可以在客户端上使用下列命令,实现软件包的安装
yum localinstall zsh-html.4.26-3.e15.i386.rpm –nogpgcheck  ## 不做签名检测
http 上实现 yum 服务器
案例图

1 、挂载光盘
[root@localhost ~]# mkdir /mnt/cdrom/
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
2 、安装 http 服务器
[root@localhost Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm
3 、启动 http 服务器
[root@localhost Server]#service httpd start
4 、拷贝光盘文件到 /var/www/html/
[root@localhost cdrom]# cp -r . /var/www/html/
[root@localhost cdrom]# cd /var/www/html/
[root@localhost html]# du -sh
2.9G     
客户端的配置与 ftp 下的客户端配置很相近
vim /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=http://192.168.10.10/Server             ## 网络 yum 源的位置
enabled=1
gpgcheck=1
gpgkey=http://192.168.10.10/RPM-GPG-KEY-redhat-release
[rhel-vt]
name=Red Hat Enterprise Linux vt
baseurl=http://192.168.10.10/VT
enabled=1
gpgcheck=1
gpgkey=http://192.168.10.10/RPM-GPG-KEY-redhat-release
[rhel-cluster]
name=Red Hat Enterprise Linux cluster
baseurl=http://192.168.10.10/Cluster
enabled=1
gpgcheck=1
gpgkey=http://192.168.10.10/RPM-GPG-KEY-redhat-release
[rhel-clusterstorage]
name=Red Hat Enterprise Linux clusterstorage
baseurl=http://192.168.10.10/ClusterStorage
enabled=1
gpgcheck=1
gpgkey=http://192.168.10.10/RPM-GPG-KEY-redhat-release
客户端 yum 测试

 

三、本地yum

假如在企业中安装liunx系统的机器比较少,或者要求yum的速度很快的时候也可以选择本地yum的配置,来解决安装软件包的依赖关系

本地yum的配置就更简单了

1、挂载光盘

[root@localhost ~]# mkdir /mnt/cdrom/

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/

2编辑文件

vim /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-server]

name=Red Hat Enterprise Linux server

baseurl=file:///mnt/cdrom/Server              ##本地yum源的位置

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

 

[rhel-vt]

name=Red Hat Enterprise Linux vt

baseurl=file:///mnt/cdrom/VT

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

 

[rhel-cluster]

name=Red Hat Enterprise Linux cluster

baseurl=file:///mnt/cdrom/Cluster

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

 

[rhel-clusterstorage]

name=Red Hat Enterprise Linux clusterstorage

baseurl=file:///mnt/cdrom/ClusterStorage

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

测试yum是否可用