yum
yum全称为Yellow dog Updater, Modified,是RPM包的前端管理工具,它的出现解决了RPM包安装时依赖性关系的问题,一次性安装所需要的依赖包,大大方便了软件安装。
yum repository
yum仓库,存储了众多rpm包,以及包的相关的元数据文件(放置于特定目录下:repodata)。可以通俗点理解为软件管家,但不是很准确,yum仓库既可以指定互联网的某台服务器上,也可以本地创建。
以下提供的是国内常见的软件的安装源镜像站:
http://mirrors.aliyun.com/
http://mirrors.163.com/
http://mirrors.sohu.com/
yum配置文件:
/etc/yum.conf:为所有仓库提供公共配置,默认一般不不需要改动
/etc/yum.repos.d/*.repo:为仓库的指向提供配置
我使用的是CentOS6.5,这里我们来看看默认的配置都有哪些:
yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
[main]
cachedir:yum的缓存目录,用于存储下载的rpm包等相关数据
keepcache:是否保存缓存,0为不保存,1为保存
debuglevel:错误级别,用于日志记录
logfile:yum日志文件存储位置
exactarch:是否精确匹配软件包的平台,1为精确匹配,0为不开启(则允许将x86软件包安装x86_64系统中)
obsoletes:是否允许更新陈旧的软件包,1为允许,0为不允许
gpgcheck:是否检测GPG(数字签名),1为检查,0为不检测
plugins:是否允许使用插件,1为允许,0为不允许
installonly_limit:同时安装多少程序包
bugtracker_url:bug追踪路径
distroverpkg:将变量$releasever设置为centos-release这个rpm包的版本号
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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[base]:仓库名称
name:仓库简介
baseurl:获取软件包的路径
gpgcheck:是否检测GPG(数字签名),1为检查,0为不检测
enabled:是否启用此仓库,1为启用,0为关闭
gpgkey:GPG(数字签名)的key文件所在路径
Tip:
几个变量需要注意下:
$releasever: 当前OS的发行版的主版本号;
$arch: 平台;
$basearch:基础平台;
$YUM0-$YUM9
详情可以参考man 5 yum.conf
yum的使用
使用网络上的yum源:
使用光盘作本地yum仓库:
(2) 创建配置文件
# 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:///media/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6