您的位置:首页 > 其它

智慧凝集 经典语录

2012-07-13 19:36 405 查看
一、yum简介
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
yum 的理念是使用一个中心仓库(repository)管理一部分甚至一个distribution 的应用程序相互关系,根据计算出来的软件依赖关系进行相关的升级、安装、删除等等操作,减少了Linux 用户一直头痛的dependencies 的问题。
yum 主要功能是更方便的添加/删除/更新RPM 包,自动解决包的倚赖性问题,便于管理大量系统的更新问题。
yum 可以同时配置多个资源库(Repository)。

二、yum的配置

yum的配置文件分为两种:主配置文件和辅配置文件
1、主配置文件又称全局配置文件:/etc/yum.conf
2、辅配置文件是/etc/yum.repos.d/目录下所有以.repo结尾的文件,该配置文件定义了每个源/服务器的具体配置,可以有一个或多个。

主配置文件/etc/yum.conf详解:

#cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
//yum 缓存的目录,yum 在此存储下载的rpm 包和数据库,默认设置为/var/cache/yum
keepcache=0     //安装完成后是否保留软件包,0为不保留(默认为0),1为保留
debuglevel=2    //Debug 信息输出等级,范围为0-10,缺省为2(类似于rpm -v  |-vv )
logfile=/var/log/yum.log    //yum 日志文件位置。用户可以到/var/log/yum.log 文件去查询过去所做的更新。
exactarch=1    //是否只安装与当前平台架构匹配的软件包
obsoletes=1    //这是一个update 的参数,允许更新陈旧的RPM包。
gpgcheck=1    ///程序包安装之前检查其合法性与包完整性
plugins=1    //是否启用插件,默认1为启用,0表示不启用。
installonly_limit=5    //一次安装程序包个数限定
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_page.php?category=yum
//bug追踪路径
distroverpkg=centos-release    //发行版本程序包应该以什么为例
#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
更多信息请参考man yum.conf 来获取

yum 变量:
$basearch: 自动切换至yum仓库所适用的平台 如i686和athlon同属i386,alpha和alphaev6同属alpha。
$arch:cpu体系,如i686,athlon等
$releasever :发行版版本  自动切换成yum发行版本的版本号
-----------------------------------------
eg:
baseurl=http://mirrors.163.com/centos/$releasever/$basearch
如果当前系统为CentOS 6.6 x86_64
现实结果为:http://mirrors.163.com/centos/6/x86_64


辅配置文件/etc/yum.repo.d/*.repo仓库配置

[repositoryid]
//对于当前系统的yum来讲,此repositoryid用于唯一标识此repository指向,因此,其必须唯一;
name=        // 当前仓库描述信息;
baseurl=url://path/to/repository/
//指明repository的访问路径,通常为一个文件服务器输出的某repository;
baseurl格式如下:
ftp服务 ftp://SERVER/PATH/TO/REPOSITORY http服务: http://SERVER/PATH/TO/REPOSITORY 本地目录:
file:///PATH/TO/REPOSITORY    //注意此处有三个“/”
enabled={1|0}    //此仓库是否可被使用   不写默认是启用
gpgcheck={1|0|}    // 是否对程序包做校验
gpgkey=url://path/to/keyfile    //指明gpgkey文件路径;
cost=#    //用于指明当前repository的访问开销,默认为100


注:上述baseurl可以指向多个url,格式如下
baseurl=url://server1/path/to/repository/
url://server2/path/to/repository/   //注意:此url不能顶格写
url://server3/path/to/repository/


三、创建国内yum源
===========制作国内163yum源==========

[163]
name=CentOS-$releasever-$basearch-mirrors.163
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[163-SCL]
name=CentOS-$releasever-$basearch-SCL-mirrors.163
baseurl=http://mirrors.163.com/centos/$releasever/SCL/$basearch
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[updates]
name=CentOS-$releasever-$basearch-updates-mirrors.163
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[163-OS]
name=CentOS-$releasever-$basearch-OS-mirrors.163
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[extras]
name=CentOS-$releasever-$basearch-extras-mirrors.163
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[centosplus]
name=CentOS-$releasever-$basearch-centosplus-mirrors.163
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
验证:
[root@linux yum.repos.d]# yum repolist
repo id                                  repo name                                                            status
163                                      CentOS-6-x86_64-mirrors.163                                              0
163-OS                                   CentOS-6-x86_64-OS-mirrors.163                                       6,518
163-SCL                                  CentOS-6-x86_64-SCL-mirrors.163                                        676
centosplus                               CentOS-6-x86_64-centosplus-mirrors.163                                  50
extras                                   CentOS-6-x86_64-extras-mirrors.163                                      37
updates                                  CentOS-6-x86_64-updates-mirrors.163                                    993
repolist: 8,274
[root@linux yum.repos.d]#
利用已做好的yum源安装tree命令包
[root@linux yum.repos.d]# yum -y install tree
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
Package      Arch          Version          Repository                 Size
====================================================================================================================
Installing:
tree         x86_64       1.5.3-2.el6         163-OS                36 k
......
验证是否安装成功

[root@linux yum.repos.d]# rpm -q tree
tree-1.5.3-2.el6.x86_64
[root@linux yum.repos.d]#

四、其他国内yum源列表如下:

1. 企业贡献:
搜狐开源镜像站:http://mirrors.sohu.com/
网易开源镜像站:http://mirrors.163.com/
2. 大学教学:
北京理工大学: http://mirror.bit.edu.cn (IPv4 only) http://mirror.bit6.edu.cn (IPv6 only)
北京交通大学: http://mirror.bjtu.edu.cn (IPv4 only) http://mirror6.bjtu.edu.cn (IPv6 only) http://debian.bjtu.edu.cn (IPv4+IPv6)
兰州大学:http://mirror.lzu.edu.cn/
厦门大学:http://mirrors.xmu.edu.cn/
清华大学: http://mirrors.tuna.tsinghua.edu.cn/ (IPv4+IPv6) http://mirrors.6.tuna.tsinghua.edu.cn/ (IPv6 only) http://mirrors.4.tuna.tsinghua.edu.cn/ (IPv4 only)
天津大学:http://mirror.tju.edu.cn/
中国科学技术大学: http://mirrors.ustc.edu.cn/ (IPv4+IPv6) http://mirrors4.ustc.edu.cn/ http://mirrors6.ustc.edu.cn/
东北大学: http://mirror.neu.edu.cn/ (IPv4 only) http://mirror.neu6.edu.cn/ (IPv6 only)
电子科技大学:http://ubuntu.uestc.edu.cn
五、常用命令

1、语法格式:
yum [options] [command] [package ...]
2、常用选项
-y :自动回答为“yes"
--disablerepo=:临时禁用在配置文件中配置并启用的某repository;
--enablerepo=: 临时启用指定的某repo:
--nogpgcheck: 禁止做包效验;
3、常用命令
仓库管理:
repolist:列出已经配置的所有可用仓库
repolist [all|enabled|disabled]
缓存管理:
clean: 清理缓存
clean [ packages | metadata | expire-cache | rpmdb | plugins | all]
[root@linux yum.repos.d]# yum clean all
Cleaning repos: 163 163-OS 163-SCL centosplus extras updates
Cleaning up Everything
[root@linux yum.repos]
-------------
注:为了彻底清除缓存还应删除/var/cache/yum/目录下的所有文件:
[root@linux yum.repos.d]# rm -rf /var/cache/yum/*
makecache:缓存创建
自动连接至每一个可用仓库,下载其元数据,将其创建为缓存;
程序包查看:
list [...]
yum list [all | glob_exp1] [glob_exp2] [...]
eg : yum list php*
yum list {available|updates|installed|extras|obsoletes|recent} [glob_exp1] [...]
available:可安装尚未安装的包
updates:可用于升级的包
installed:安装过额包
extras:仓库内未提供,但已经安装了
obsoletes:
recent:新包
grouplist [hidden] [groupwildcard] [...]

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

Note:只需要提供包名:
如果某包有在不同仓库中有多个不同版本,默认会安装最新版本
如果要安装指定版本 :install PACKAGE-VERSION

重新安装(覆盖安装)
reinstall package1 [package2] [...]
程序包升级:
update [package1] [package2] [...]

如果只想升级指定版本使用:update PACKAGE-VERSION
程序包降级:
downgrade package1 [package2] [...]

检查有哪些升级可用:
check-update

卸载:
remove | erase package1 [package2] [...]
所有依赖于正卸载的程序包的程序包会被一并卸载
eg: yum remove php-common

查询:
查询程序的相关简要信息: info [...]

eg:
[root@linux yum.repos.d]# yum info tree
Installed Packages
Name        : tree
Arch        : x86_64
Version     : 1.5.3
Release     : 2.el6
Size        : 65 k
Repo        : installed
From repo   : 163-OS
Summary     : File system tree viewer
URL         : http://mama.indstate.edu/users/ice/tree/ License     : GPLv2+
Description : The tree utility recursively displays the contents of directories in a
: tree-like format.  Tree is basically a UNIX port of the DOS tree
: utility.

search KEYWORD ...
在包名和简要(sumary)信息中搜索指定的关键字:
provides | whatprovides /PATH/TO/SOMEFILE
查询指定文件由哪个程序包安装生成:

[root@linux yum.repos.d]# yum provides /usr/bin/tree  //查询/usr/bin/tree文件由哪个程序包安装所生成
tree-1.5.3-2.el6.x86_64 : File system tree viewer
Repo        : 163-OS
Matched from:
Filename    : /usr/bin/tree

tree-1.5.3-2.el6.x86_64 : File system tree viewer
Repo        : installed
Matched from:
Other       : Provides-match: /usr/bin/tree


包组管理:
列出所有包组:grouplist
显示指定包组详情:groupinfo group1 [...]

安装:groupinstall group1 [group2] [...]
卸载:groupremove group1 [group2] [...]
升级:groupupdate group1 [group2] [...]

eg:列出yum源中的所有包组:
[root@linux yum.repos.d]# yum grouplist
Setting up Group Process
Installed Groups:
Additional Development
Base
Desktop
Dial-up Networking Support
Directory Client
E-mail server
Emacs
Fonts
General Purpose Desktop
Graphical Administration Tools
Hardware monitoring utilities
Input Methods
Internet Browser
Legacy UNIX compatibility
Legacy X Window System compatibility
Network Infrastructure Server
Network file system client
Networking Tools
Performance Tools
Perl Support
Print Server
Printing client
SNMP Support
Security Tools
Server Platform
System administration tools
X Window System
Installed Language Groups:
Arabic Support [ar]
......


OK 有关yum的讲解到此就告一段落了,有不足之处还请各位看官斧正........

参考博文:http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html

本文出自 “无常” 博客,请务必保留此出处http://1inux.blog.51cto.com/10037358/1635518
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: