1.1 YUM概述
YUM: Yellowdog Update Modified , 存储了众多rpm包,以及包的相关元数据文件(放置在特定目录下:repodata);
1.2 YUM客户端配置文件:
/etc/yum.conf 为所有仓库提供公共配置;
/etc/yum.repos.d/*.repo 为仓库的指向提供路径;
/etc/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=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum 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
仓库指向的定义:
——————–
[repositoryID] name=Some name for this repository baseurl=url://server1/path/to/repository/ url://server2/path/to/repository/ url://server3/path/to/repository/ enabled={1|0} gpgcheck={1|0} gpgkey=URL enablegroups={1|0} 是否允许此仓库使用组来管理程序包;默认开启此功能; failovermethod={roundrobin|priority} 故障转移方法;当'baseurl'有多个路径时,此选项需要启用;'roundrobin'参数表示随机选一个路径,此参数是默认值;'priority'参数表示按优先级,第一个URL如果安装程序包失败,就转到第二额URL,依次类推; cost=NUMBER 开销值,默认值为1000;多个仓库时,设置此参数,值小优先;
1.3 YUM命令:
yum – Yellowdog Updater Modified
yum [options] [command] [package …]
command is one of:
—————————–
* install package1 [package2] [...] * update [package1] [package2] [...] * update-to [package1] [package2] [...] * update-minimal [package1] [package2] [...] * check-update * upgrade [package1] [package2] [...] * upgrade-to [package1] [package2] [...] * distribution-synchronization [package1] [package2] [...] * remove | erase package1 [package2] [...] * autoremove [package1] [...] * list [...] * info [...] * provides | whatprovides feature1 [feature2] [...] * clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] * makecache [fast] * groups [...] * search string1 [string2] [...] * shell [filename] * resolvedep dep1 [dep2] [...] (maintained for legacy reasons only - use repoquery or yum provides) * localinstall rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use install) * localupdate rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use update) * reinstall package1 [package2] [...] * downgrade package1 [package2] [...] * deplist package1 [package2] [...] * repolist [all|enabled|disabled] * repoinfo [all|enabled|disabled] * repository-packages <enabled-repoid> <install|remove|remove-or-reinstall|remove-or-distribution-synchronization> [package2] [...] * version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ] * history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats] * load-transaction [txfile] * updateinfo [summary | list | info | remove-pkgs-ts | exclude-updates | exclude-all | check-running-kernel] * fssnapshot [summary | list | have-space | create | delete] * fs [filters | refilter | refilter-cleanup | du] * check * help [command]
**************** part 1 显示仓库列表 ****************** 显示仓库列表: yum repolist [all|enabled|disabled] **************** part 2 列出程序包 ****************** 列出所有可用的尚未安装的包、所有已安装的包: yum list [all | glob_exp1] [glob_exp2] [...] 列出所有可用的尚未安装的包: yum list available [glob_exp1] [...] 列出所有可用的更新包: yum list updates [glob_exp1] [...] 列出所有可用的尚未安装的包: yum list installed [glob_exp1] [...] 列出所有已经安装,但不包含在repository中包: yum list extras [glob_exp1] [...] **************** part 3 安装与重新安装 ****************** 安装程序包,如果仓库中有多个版本的程序包,默认安装最新版本: yum install package1 [package2] [...] 重新安装: yum reinstall package1 [package2] [...] **************** part 4 升级与降级 ****************** 升级程序包: yum update [package1] [package2] [...] 检查有哪些升级包可用: yum check-update 降级程序包: yum downgrade package1 [package2] [...] **************** part 5 卸载 ****************** 卸载指定程序包: yum {remove | erase} package1 [package2] [...] **************** part 6 查看包相关信息 ****************** 查看程序包的信息(information): 后面接软件包名称,可接多个; yum info [...] 查看指定的特性或文件是由哪个程序包所提供的: yum provides | whatprovides feature1 [feature2] [...] 列出指定程序包的依赖关系,以及显示提供依赖关系的程序包: yum deplist package1 [package2] [...] **************** part 7 YUM缓存操作 ****************** 清理YUM缓存目录: yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] 构建YUM缓存: yum makecache **************** part 8 search操作 ****************** 根据指定程序包名(包的名称拼写可以不完整,但不支持使用正则表达式的模糊匹配)来搜索相关信息: yum search [all] string1 [string2] [...] 没有'all'选项,表示仅搜索程序包名字、摘要信息; 'all'选项,表示显示所有信息; **************** part 9 YUM事务 ****************** 查看YUM事务信息: yum history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats] **************** part 10 安装或升级本地程序包 ****************** 安装或升级下载到本地的rpm包: yum localinstall rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use install) yum localupdate rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use update) Centos 6/7 开始,'localinstall','localupdate'可省略: yum install PACKGE_NAME.rpm 使用YUM安装下载到本地的rpm包,可以解决此rpm包的依赖关系; **************** part 11 包组管理 ****************** yum groupinstall group1 [group2] [...] yum groupupdate group1 [group2] [...] yum grouplist [hidden] [groupwildcard] [...] yum groupremove group1 [group2] [...] yum groupinfo group1 [group2] [...] 例如:~]# yum groupinstall "Development Tools" 包组名要用双引号括起来; ~]# yum grouplist 不带其他参数,隐藏的组列表不显示; ~]# yum grouplist hidden 显示所有组列表,包括隐藏的;
1.4 yum的命令行选项(通用选项)
-y, –assumeyes 安装过程不需要交互,自动回答’yes’;
-q, –quiet 静默模式,安装过程不会输出任何信息;
–enablerepo=repoidglob 临时启用指定的repo;Enables specific repositories by id or glob that have been disabled in the configuration file using the enabled=0 option.
–disablerepo=repoidglob 临时禁用指定的repo;
–nogpgcheck 禁止进行gpg check;
–noplugins 禁用所有插件;
–skip-broken 忽略依赖关系;Resolve depsolve problems by removing packages that are causing problems from the transaction.
1.5 yum的repo配置文件中可用的变量:
$releasever : 当前OS的发行版本的主版本号;
$arch : CPU平台;
$basearch : 基础平台;
举例:
baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
1.6 创建yum仓库
使用命令’createrepo’命令;如果系统没有此命令,可先手动安装:~]# yum install createrepo
指定存放rpm包的目录路径:/yum/packages;
把rpm包放置在目录’/yum/packages’中;
在’/yum/packages’目录下,创建yum仓库:~]# createrepo ../
上面命令,表示创建的’repodata’目录放置在与’packages’目录同级别的目录下面;
即,’/yum’目录下会有2个目录存在:’/yum/packages’,’/yum/repodata’;
也可把’repodata’目录放置在’/yum/packages’目录下面,创建的时候使用此命令:~]# createrepo ./
举例创建过程:
————-
[root@kouyuushinn ~]# [root@kouyuushinn ~]# cd /yum/packages/ [root@kouyuushinn packages]# [root@kouyuushinn packages]# createrepo ../ Spawning worker 0 with 1 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete [root@kouyuushinn packages]# cd .. [root@kouyuushinn yum]# ll total 4 drwxr-xr-x 2 root root 41 May 12 01:19 packages drwxr-xr-x 2 root root 4096 May 12 01:26 repodata [root@kouyuushinn yum]# ll repodata/ total 36 -rw-r--r-- 1 root root 6170 May 12 01:26 0331f119800c7e5f24138c0ce5ac5a393511a7ca6e5c17cd4657092e5722e85b-filelists.xml.gz -rw-r--r-- 1 root root 2582 May 12 01:26 2dd1f5365369c600582c459d4060dc65ac80f50aaff8919e121433cd5b3b0605-primary.sqlite.bz2 -rw-r--r-- 1 root root 6544 May 12 01:26 a108ed0f896c67bfb514191045fbfef3fa1207ca1281b1fb74bab4bd0a3c4bca-filelists.sqlite.bz2 -rw-r--r-- 1 root root 1047 May 12 01:26 b83ca1e134f58c1c799e3f1b90c8981c8e4a5e17c52fafbac3d8cc16894a4368-primary.xml.gz -rw-r--r-- 1 root root 802 May 12 01:26 ed8a8f748e9fca43bc06c96c3f74cc7a38618201b1475e95ad174056ba55d65d-other.xml.gz -rw-r--r-- 1 root root 1451 May 12 01:26 ff2ea9dfe00ff635f29c82bc176e504227d75e79f025a451addbe3dc675ca54f-other.sqlite.bz2 -rw-r--r-- 1 root root 2971 May 12 01:26 repomd.xml [root@kouyuushinn yum]# [root@kouyuushinn yum]# ll packages/ total 3328 -rw-r--r-- 1 root root 3404440 May 12 01:19 zsh-5.1-1.gf.el7.x86_64.rpm [root@kouyuushinn yum]#