yum简介
yum - Yellowdog Updater Mlodified.
yum is an interactive, rpm based,package manager.
yum is similar to other high level package managers like apt-get and smart.
SYNOPSIS
yum [options] [command] [package …]
yum客户端配置文件
/etc/yum.conf 所有仓库的公共配置文件
配置项说明:
cachedir=/var/cache/yum/\$basearch/\$releasever
#指yum元数据存放的缓存目录,yum在此存储下载的rpm包和相关元数据的仓库数据库
keepcache=0
#是否保留安装过程中相关的软件包,0表示安装后删除软件包,1表示安装后保留软件包
debuglevel=2
#debug日志记录的级别,0-10,默认是2
logfile=/var/log/yum.log
#指定记录利用yum更新过的软件的日志文件。
exactarch=1
#指是否只升级和你cpu架构一致的软件包,如果设为1,则表示你安装的软件包为x86_64的包,yum不会用i686的包来升级
obsoletes=1
#此选项在进行发行版跨版本升级的时候会用到,指在升级时是否包含废弃的包。*gpgcheck=1**指安装包时是否需要进行gpg校验,0表示不检查。
plugins=1
#指是否支持插件,1表示支持。
installonly_limit=5
#表示可以同时安装的软件包数量
distroverpkg=centos-release
#用来确定变量$releasever表示的版本来源于那个配置文件
yum仓库配置:
配置文件路径:/etc/yum.repos.d/
[base] #仓库的名字
name=aliyun #相当于注释,说明仓库的作用
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ #仓库URL地址,支持file、http、ftp,$releasever、$basearch为yum配置文件专用变量
enabled=1 #是否启用仓库
gpgcheck=0 #是否启用公钥认证
gpgkey=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-7 #公钥认证的地址
yum常见用法
yum命令的用法:
yum [options] [command] [package …]
安装与卸载
yum install package1 [package2] […]
yum reinstall package1 [package2] […] (重新安装)
yum remove | erase package1 [package2] […]
说明:此方式不会卸载安装过程中安装的依赖包。
仓库管理
生成misc_cd.repo
yum-config-manager --add-repo=file:///misc/cd
yum-config-manager --disable “仓库名" 禁用仓库
yum-config-manager --enable “仓库名”启用仓库
yum查看命令
显示仓库列表
yum repolist [all|enabled|disabled]
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
base CD 3,971
epel/7/x86_64 ali epel 13,470
mariadb MariaDB 97
misc_cd added from: file:///misc/cd 3,971
repolist: 21,509
说明: repo name 对应仓库配置文件中 name
列出程序包
yum list
yum list [all | glob_exp1] [glob_exp2] […]
yum list {available|installed|updates} [glob_exp1] […]
查看
yun info […]
查看包的信息,是否被安装等。
[root@localhost ~]# yum info httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
Name : httpd
Arch : x86_64
Version : 2.4.6
Release : 80.el7.centos
Size : 9.4 M
Repo : installed
From repo : base
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
查看指定的特性(可以是某文件)是由哪个程序包所提供
yum provides | whatprovides feature1 [feature2] […]
查看指定包所依赖的capabilities
yum deplist package1 [package2] […]
yum事务历史管理
yum history [info|list|redo|undo]
查看历史事务
[root@localhost ~]# yum history
Loaded plugins: fastestmirror, langpacks
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
12 | System <unset> | 2020-11-21 17:50 | Install | 1
11 | System <unset> | 2020-11-19 14:50 | Install | 5
10 | System <unset> | 2020-11-18 10:23 | Install | 1
9 | System <unset> | 2020-11-16 16:15 | Erase | 1
8 | System <unset> | 2020-11-16 15:50 | Install | 1
7 | System <unset> | 2020-11-10 15:04 | Install | 1
6 | System <unset> | 2020-11-10 14:57 | Erase | 1
5 | System <unset> | 2020-10-31 15:19 | Install | 1
4 | System <unset> | 2020-10-31 10:17 | Install | 1 <
3 | root <root> | 2020-08-21 22:56 | Install | 1 >
2 | root <root> | 2020-08-09 16:24 | I, O | 4
1 | System <unset> | 2020-06-02 10:49 | Install | 1362
history list
yum history info 12
可以查看历史事务12的信息
yum history redo 12
重做历史事务12
yum history undo 12
反向做历史事务12,比如:历史事务12为安装,执行此命令是卸载,并且可以把依赖包也可以卸载掉
缓存管理
清理本地缓存:
清除/var/cache/yum/
b
a
s
e
a
r
c
h
/
basearch/
basearch/releasever缓存
yum clean [ packages | metadata | expire-cache | rpmdb | plugins |
all ]
构建缓存:
yum makecache
yum命令
yum的命令行选项:
–nogpgcheck:禁止进行gpg check
-y: 自动回答为“yes”
-q:静默模式
–disablerepo=repoidglob:临时禁用此处指定的repo
–enablerepo=repoidglob:临时启用此处指定的repo
–noplugins:禁用所有插件
常用yum源
阿里云repo文件
http://mirrors.aliyun.com/repo/
CentOS系统的yum源
阿里云:https://mirrors.aliyun.com/centos/
r
e
l
e
a
s
e
v
e
r
/
o
s
/
x
8
6
6
4
/
清华大学:
h
t
t
p
s
:
/
/
m
i
r
r
o
r
s
.
t
u
n
a
.
t
s
i
n
g
h
u
a
.
e
d
u
.
c
n
/
c
e
n
t
o
s
/
releasever/os/x86_64/ 清华大学:https://mirrors.tuna.tsinghua.edu.cn/centos/
releasever/os/x8664/清华大学:https://mirrors.tuna.tsinghua.edu.cn/centos/releasever/os/x86_64/
EPEL的yum源
阿里云:https://mirrors.aliyun.com/epel/$releasever/x86_64
阿里巴巴开源软件
https://opsx.alibaba.com/
最佳实践
下载yum仓库配置文件
#清空或备份系统自带yum仓库配置文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#下载阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#清理缓存
yum clean all
#运行yum makecache生成缓存
yum makecache
#构建epel-release仓库
yum install -y epel-release
#构建Nux Dextop仓库,依赖epel仓库
wget http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
rpm -Uvh nux-dextop-release-0-5.el7.nux.noarch.rpm