yum的配置和使用

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源:

首先备份/etc/yum.repos.d/CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo .bak
使用的阿里云的yum源
    CentOS 6 下载
        http://mirrors.aliyun.com/repo/Centos-6.repo
    CentOS 7 下载
        http://mirrors.aliyun.com/repo/Centos-7.repo
下载对应版本repo文件, 放入/etc/yum.repos.d/,即可。当然也用默认配置为参考,自己新建以.repo结尾的文件

使用光盘作本地yum仓库:

(1) 挂载光盘至某目录,例如/media/cdrom
    # mount -r-t iso9660 /dev/cdrom /media/cdrom
(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

yum常用命令

    显示仓库列表
        yum  repolist [all|enabled|disabled]

     显示程序包
         yum  list
            # yum list [all | glob_exp1] [glob_exp2] [...]
            # yum list {available|installed|updates} [glob_exp1] [...]

     安装程序包
         yum  install package1 [package2] [...]

         yum  reinstall package1 [package2] [...]  (重新安装)

     升级程序包
         yum  update [package1] [package2] [...]

         yum  downgrade package1 [package2] [...] (降级)

     检查可用升级
         yum  check-update

     卸载程序包
         yum  remove | erase package1 [package2] [...]

     查看程序包information:
         yum  info [...]

     查看指定的特性(可以是某文件)是由哪个程序包所提供:
        yum  provides | whatprovides feature1 [feature2] [...]

     清理本地缓存
         yum  clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

     构建缓存
         yum  makecache
    
     搜索
         yum  search string1 [string2] [...]

        以指定的关键字搜索程序包名及summary信息;

     查看指定包所依赖的capabilities
         yum  deplist package1 [package2] [...]

     查看yum事务历史
         yum  history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值