36-1、yum 三大源
YUM介绍
学习YUM 软件仓库,可以完成安装、卸载、自动升级 rpm 软件包等任务,能够自动 查找并解决 rpm 包之间的依赖关系,而无须管理员逐个、手工地去安装每个 rpm 包,使管 理员在维护大量 Linux 服务器时更加轻松自如。特别是在拥有大量 Linux 主机的本地网络中, 构建一台“源”服务器可以大大缓解软件安装、升级等对 Internet 的依赖。
YUM 的前身是 YUP(Yellow dog Updater,Yellow dog Linux 的软件更新器),最初由 TSS 公司(Terra Soft Solutions,INC.)使用 Python 语言开发而成,后来由杜克大学(Duck University)的 Linux 开发队伍进行改进,命名为 YUM(Yellow dog Updater,Modified)。 要成功使用 YUM 机制来更新系统和软件,需要有一个包含各种 rpm 安装包文件及其依 赖软件的软件仓库(repository),提供软件仓库的服务器也称为“源”服务器。在客户机中只 要正确指定软件仓库的地址等信息,就可以通过对应的“源”服务器来安装或更新软件
YUM源的提供方式
1.#配置本地源仓库
cd /etc/yum.repos.d/
vim local.repo
[local] #仓库类别
name=local #仓库名称
baseurl=file:///mnt #指定URL 访问路径为光盘挂载目录
enabled=1 #开启此yum源,此为默认项,可省略
gpgcheck=0 #不验证软件包的签名
mount /dev/sr0 /mnt #把光盘挂载到/mnt目录下(前提虚拟机是光盘挂载)
##清理yum缓存并更新
yum clean all && yum makecache
###检查
yum repolist
2、配置ftp源
主要是思路
服务器配置:
1)安装vsftpd服务端软件
2)创建并制作yum远程ftp站点的源
3)启动ftp服务
rpm -qa|grep vsftpd
yum -y install vsftpd
mkdir /var/ftp/centos7 #创建挂盘挂载目录
mount /dev/sr0 /mnt #镜像挂载
cp -rf /mnt/* /var/ftp/centos7/ &
mkdir /var/ftp/other # 创建目录repodata 数据文件
cd /var/ftp/other/
createrepo -g /mnt/repodata/repomd.xml ./ #工具建立仓库数据文件
systemctl start vsftpd
客户端配置:
1)创建远程yum源的配置文件
2)yum安装软件验证结果
客户端配置:
vi /etc/yum.repos.d/centos7.repo
[root@kgc14 yum.repos.d]# cat centos7.repo
[centos7] #仓库类别
name=centos7 #仓库名称(说明)
baseurl=ftp://192.168.10.17/centos7 #URL 访问路径
enabled=1 #启用此软件仓库
gpgcheck=1 #验证软件包的签名
gpgkey=ftp://192.168.10.17/centos/RPM-GPG-KEY-CentOS-7 #GPG 公钥文件的位置
[other]
name=centos7
baseurl=ftp://192.168.10.17/other
enabled=1 #启用此软件仓库
gpgcheck=0 #验证软件包的签名
3.#网络源
① centOS7 清华源
vim CentOS7-Base-tsinghua.repo
[base]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
B
a
s
e
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
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 - Base baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/
releasever−Basebaseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
U
p
d
a
t
e
s
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
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 - Updates baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/
releasever−Updatesbaseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
E
x
t
r
a
s
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
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 - Extras baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/
releasever−Extrasbaseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
P
l
u
s
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
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 - Plus baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/
releasever−Plusbaseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
② 163 yum 源
下载链接:wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
vim CentOS7-Base-163.repo #编辑163 yum 网络源
[base]
name=CentOS-KaTeX parse error: Expected 'EOF', got '#' at position 29: …Base - 163.com #̲mirrorlist=http…releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=os baseurl…releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-KaTeX parse error: Expected 'EOF', got '#' at position 32: …ates - 163.com #̲mirrorlist=http…releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=updates ba…releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-KaTeX parse error: Expected 'EOF', got '#' at position 31: …tras - 163.com #̲mirrorlist=http…releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=extras bas…releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
P
l
u
s
−
163.
c
o
m
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
163.
c
o
m
/
c
e
n
t
o
s
/
releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/
releasever−Plus−163.combaseurl=http://mirrors.163.com/centos/releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
③ 阿里云源
下载地址:wget http://mirrors.aliyun.com/repo/Centos-7.repo
vim CentOS7-Base-aliyun.repo #编辑阿里云yum 网络源
[base]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
B
a
s
e
−
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
f
a
i
l
o
v
e
r
m
e
t
h
o
d
=
p
r
i
o
r
i
t
y
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/
releasever−Base−mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/os/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.aliyuncs.com/centos/
basearch/http://mirrors.aliyuncs.com/centos/releasever/os/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
c
l
o
u
d
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.cloud.aliyuncs.com/centos/
basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
U
p
d
a
t
e
s
−
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
f
a
i
l
o
v
e
r
m
e
t
h
o
d
=
p
r
i
o
r
i
t
y
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/
releasever−Updates−mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/updates/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.aliyuncs.com/centos/
basearch/http://mirrors.aliyuncs.com/centos/releasever/updates/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
c
l
o
u
d
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.cloud.aliyuncs.com/centos/
basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
E
x
t
r
a
s
−
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
f
a
i
l
o
v
e
r
m
e
t
h
o
d
=
p
r
i
o
r
i
t
y
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/
releasever−Extras−mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/extras/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.aliyuncs.com/centos/
basearch/http://mirrors.aliyuncs.com/centos/releasever/extras/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
c
l
o
u
d
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.cloud.aliyuncs.com/centos/
basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
P
l
u
s
−
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
f
a
i
l
o
v
e
r
m
e
t
h
o
d
=
p
r
i
o
r
i
t
y
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/
releasever−Plus−mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/centosplus/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.aliyuncs.com/centos/
basearch/http://mirrors.aliyuncs.com/centos/releasever/centosplus/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
c
l
o
u
d
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.cloud.aliyuncs.com/centos/
basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
C
o
n
t
r
i
b
−
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
f
a
i
l
o
v
e
r
m
e
t
h
o
d
=
p
r
i
o
r
i
t
y
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/
releasever−Contrib−mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/contrib/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.aliyuncs.com/centos/
basearch/http://mirrors.aliyuncs.com/centos/releasever/contrib/
b
a
s
e
a
r
c
h
/
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
c
l
o
u
d
.
a
l
i
y
u
n
c
s
.
c
o
m
/
c
e
n
t
o
s
/
basearch/ http://mirrors.cloud.aliyuncs.com/centos/
basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
注:其他网络源
1)http://ftp.sjtu.edu.cn/centos #上海交大,但服务器位于北京,中国教育网网络中心,我看像是朝阳区那边的IP,以前在那边上过 班,下载速度高达十M。 北方用户与教育网用户推荐,速度飞快。
2)http://centos.ustc.edu.cn,#中国科技大学,服务器位于合肥。 南方用户推荐。
3)http://mirrors.sohu.com/,sohu的开源镜像服务器,服务器位于山东省联通。 速度飞快,全国用户推荐,经常用FireFox下载CD镜像
yum 命令
yum常用的操作命令:
yum -y install 软件名 #安装、升级软件包,“-y”选项表示自动确认
yum -y remove 软件名 #卸载软件包,可自动解决其依赖关系
yum -y update 软件名 #升级软件包
yum list #查询软件包列表
yum list installed #查询系统中已安装的软件包
yum list available #查询仓库中尚未安装的软件包
yum list updates #查询可以升级版本的软件包
案列搜索RPM包(两种方法)
yum search vim
yum list|grep “vim”
yum info 软件名 #查询软件包的描述信息
yum info httpd
yum search [all] 关键词 #根据某个关键词来查找相关的软件包
yum search all httpd
yum whatprovides 命令 #查询命令属于哪个软件包
yum whatprovides netstat
下载RPM包而不安装
yum install 包名 -y --downloadonly
yum reinstall -y bash --downloadonly #下载已安装过的rpm包
yum install 包名 -y --downloadonly --downloaddir=/tmp/ #下载RPM包到指定目录
yum history 查看历史记录来找到它所依赖的包,然后删除,
如:yum history list 列出最近的历史
yum history info id 列出某次的详细信息,
yum history undo id 撤销某次更改
yum history help 查看帮助
yum history redo加入序号重新执行序号里的操作
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)