CentOS-yum基本使用

时间:2021-08-31 12:35:00

CentOS: yum

URL: ftp://172.16.0.1/pub/

YUM: yellow dog, Yellowdog Update Modifier

yum repository: yum repo
存储了众多rpm包,以及包的相关的元数据文件(放置于特定目录下:repodata);

文件服务器:
ftp://
http://
nfs://
file:///

yum客户端:
配置文件:
/etc/yum.conf:为所有仓库提供公共配置
/etc/yum.repos.d/*.repo:为仓库的指向提供配置

仓库指向的定义:
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority}
默认为:roundrobin,意为随机挑选;
cost=
默认为1000

教室里的yum源:http://172.16.0.1/cobbler/ks_mirror/CentOS-6.6-x86_64/
CentOS 6.6 X84_64 epel: http://172.16.0.1/fedora-epel/6/x86_64/

yum命令的用法:
yum [options] [command] [package ...]

command is one of:
* install package1 [package2] [...]
* update [package1] [package2] [...]
* update-to [package1] [package2] [...]
* check-update
* upgrade [package1] [package2] [...]
* upgrade-to [package1] [package2] [...]
* distribution-synchronization [package1] [package2] [...]
* remove | erase package1 [package2] [...]
* list [...]
* info [...]
* provides | whatprovides feature1 [feature2] [...]
* clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
* makecache
* groupinstall group1 [group2] [...]
* groupupdate group1 [group2] [...]
* grouplist [hidden] [groupwildcard] [...]
* groupremove group1 [group2] [...]
* groupinfo group1 [...]
* search string1 [string2] [...]
* shell [filename]
* resolvedep dep1 [dep2] [...]
* 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]
* version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ]
* history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
* check
* help [command]

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

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

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

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

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

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

检查可用升级:
check-update

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

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

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

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

构建缓存:
makecache

搜索:
search string1 [string2] [...]

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

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

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

安装及升级本地程序包:
* localinstall rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use install)
* localupdate rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use update)

包组管理的相关命令:
* groupinstall group1 [group2] [...]
* groupupdate group1 [group2] [...]
* grouplist [hidden] [groupwildcard] [...]
* groupremove group1 [group2] [...]
* groupinfo group1 [...]

如何使用光盘当作本地yum仓库:
(1) 挂载光盘至某目录,例如/media/cdrom
# mount -r -t iso9660 /dev/cdrom /media/cdrom
(2) 创建配置文件
[CentOS7]
name=
baseurl=
gpgcheck=
enabled=

yum的命令行选项:
--nogpgcheck:禁止进行gpg check;
-y: 自动回答为“yes”;
-q:静默模式;
--disablerepo=repoidglob:临时禁用此处指定的repo;
--enablerepo=repoidglob:临时启用此处指定的repo;
--noplugins:禁用所有插件;

yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号;
$arch: 平台;
$basearch:基础平台;
$YUM0-$YUM9

http://mirrors.magedu.com/centos/$releasever/$basearch/os

创建yum仓库:
createrepo [options] <directory>