YUM(Yellowdog Updater Modified)是一个基于RPM(Redhat Package Manager红帽包管理器)包的前端软件管理工具,是C/S架构下的一种rpm的前端工具,YUM通过分析rpm header数据,自动处理依赖关系,从指定的repositories仓库源一次性自动下载安装所有依赖的rpm包,无须繁琐地一次次下载、安装。
repo就是repositories(仓库)的缩写,repositories其实就是存放rpm包的路径,比如file://本地路径或ftp://服务器路径或http://网站url路径
我们要使用YUM,必须要先找到存放rpm包的Repository仓库源,这些Repository仓库源的信息存放在目录为/etc/yum.repos.d/下的文件扩展名为repo的配置文件中,通常一个repo配置文件定义了一个或者多个Repository仓库源的细节内容,其中可能会多个repo配置文件,每一个repo配置文件中都可以配置一个或多个Repository,但是最终所有Repository仓库源会被合并为一个交给系统(可以通过yum repolist all显示出来),所以多个repo配置文件只是为了方便管理。repo配置文件中的设置内容将被yum命令读取和应用,这样yum命令就从这些Repository仓库源下载需要安装或者升级的rpm包
查看拥有的repo仓库列表:yum repolist all
列出含有关键字XX的软件包:yum list |grep XX
查询软件XX:yum info xx
搜索软件XX:yum search xx
安装软件包xx.rpm:yum install xx.rpm
删除软件包xx.rpm:yum erase xx.rpm
升级软件XX:yum upgrade xx或者yum update xx
区别:yum upgrade会删除旧版本的package,而yum update则会保留(obsoletes=0),建议使用yum update,防止旧版本包被删除从而导致其他旧的软件包依赖出现问题。
repo配置文件内容的解释,示例如下
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[base]:repo的id,必须是独一无二的,不能和其他源文件冲突,一旦冲突,可能这个repo id对应的repo name就不显示了
name:repo的名称
mirrorlist:为rpm包对应的一大堆路径或baseurl,yum根据使用者客户端的IP地址和mirrorlist中信息来选取在地理位置上靠近客户端的repo仓库源,如mirrorlist不工作时可以使用baseurl。
baseurl:为rpm包对应的目录或路径,如果我们想把挂载在本地光盘/mnt为rpm路径,可以使用baseurl来配置成baseurl=file:///mnt/Server,如果我们想把阿里云rpm仓库为rpm路径,可以使用baseurl来配置成baseurl=http://mirrors.aliyun.com/centos/6/os/x86_64
示例中,我们确定repo配置文件中$releasever和$basearch变量的值的方法:使用cat命令打开/etc/yum.conf文件中看到一行信息cachedir=/var/cache/yum/$basearch/$releasever,我们可以进入/var/cache/yum/文件夹下,发现 $basearch 其实就是 x86_64,$releasever就是7,然后代入mirrorlist中发现mirrorlist就是http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=$infra网页,该网页下面一堆的url,代入baseurl发现baseurl就是http://mirror.centos.org/centos/7/os/x86_64/
enabled=0/1:只有1和0两个值,为1时表示repo可以获取,0表示关闭,默认是1
gpgcheck=0/1:只有1和0两个值,为1时表示进行gpg校验,默认是1
gpgkey:数字证书公钥文件所在位置,用户下载安装RPM包时,可以通过这个公钥来验证RPM包是不是官方签名的,示例中我们可以打开/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7文件看看这个公钥信息
实验1
[root@FRSPGSQLDEV3]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 633 Feb 9 21:46 CentOS-Base.repo
-rw-r--r--. 1 root root 213 Feb 9 21:47 pgdg-redhat-all.repo
[root@FRSPGSQLDEV3]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@FRSPGSQLDEV3]# cat /etc/yum.repos.d/pgdg-redhat-all.repo
[pgdg12]
name=PostgreSQL 12 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
[root@FRSPGSQLDEV3]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: la.mirrors.clouvider.net
repo id repo name status
base/7/x86_64 CentOS-7 - Base enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus disabled
pgdg12/7/x86_64 PostgreSQL 12 7 - x86_64 disabled
repolist: 10,072
结果:只显示了/etc/yum.repos.d/CentOS-Base.repo中的repo id为的base有些,其他的repo id都是无效,因为其他的repo id对应的enabled=0
实验2
pgdg-redhat-all.repo添加内容[centosplus],如下,该内容和CentOS-Base.repo中[centosplus]一样
[root@FRSPGSQLDEV3]# vim /etc/yum.repos.d/pgdg-redhat-all.repo
[root@FRSPGSQLDEV3]# cat /etc/yum.repos.d/pgdg-redhat-all.repo
[pgdg12]
name=PostgreSQL 12 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@FRSPGSQLDEV3]# yum repolist all
Loaded plugins: fastestmirror
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: la.mirrors.clouvider.net
repo id repo name status
base/7/x86_64 CentOS-7 - Base enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus disabled
pgdg12/7/x86_64 PostgreSQL 12 7 - x86_64 disabled
repolist: 10,072
结果:只显示了/etc/yum.repos.d/CentOS-Base.repo中的repo id为的base有些,其他的repo id都是无效,因为其他的repo id对应的enabled=0
实验3
需要改实验2中pgdg-redhat-all.repo内容,把centosplus修改成pgdg12
[root@FRSPGSQLDEV3]# vim /etc/yum.repos.d/pgdg-redhat-all.repo
[root@FRSPGSQLDEV3]# cat /etc/yum.repos.d/pgdg-redhat-all.repo
[pgdg12]
name=PostgreSQL 12 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
[pgdg12]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@FRSPGSQLDEV3]# yum repolist all
Loaded plugins: fastestmirror
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: la.mirrors.clouvider.net
repo id repo name status
base/7/x86_64 CentOS-7 - Base enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus disabled
pgdg12/7/x86_64 PostgreSQL 12 7 - x86_64 disabled
repolist: 10,072
结果:只显示了/etc/yum.repos.d/CentOS-Base.repo中的repo id为的base有些,其他的repo id都是无效,因为其他的repo id对应的enabled=0
实验4
pgdg-redhat-all.repo添加内容[updates],如下
[root@FRSPGSQLDEV3]# vim /etc/yum.repos.d/pgdg-redhat-all.repo
[root@FRSPGSQLDEV3]# cat /etc/yum.repos.d/pgdg-redhat-all.repo
[pgdg12]
name=PostgreSQL 12 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
[pgdg12]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@FRSPGSQLDEV3]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: repos.lax.layerhost.com
* updates: mirror.sfo12.us.leaseweb.net
repo id repo name status
base/7/x86_64 CentOS-7 - Base enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus disabled
pgdg12/7/x86_64 PostgreSQL 12 7 - x86_64 disabled
updates/7/x86_64 CentOS-7 - Updates enabled: 4,691
repolist: 14,763
结果:只显示了/etc/yum.repos.d/CentOS-Base.repo中的repo id为的base有效和/etc/yum.repos.d/pgdg-redhat-all.repo中的updates有效,其他的repo id都是无效,因为其他的repo id对应的enabled=0
实验5,修改pgdg-redhat-all.repo内容中的[pgdg12]中两个enable=1
[root@FRSPGSQLDEV3]# vim /etc/yum.repos.d/pgdg-redhat-all.repo
[root@FRSPGSQLDEV3]# cat /etc/yum.repos.d/pgdg-redhat-all.repo
[pgdg12]
name=PostgreSQL 12 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
[pgdg12]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@FRSPGSQLDEV3]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ocf.berkeley.edu
* pgdg12: repos.lax.layerhost.com
* updates: mirrors.oit.uci.edu
repo id repo name status
base/7/x86_64 CentOS-7 - Base enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus disabled
pgdg12/7/x86_64 CentOS-7 - Plus enabled: 255
updates/7/x86_64 CentOS-7 - Updates enabled: 4,691
repolist: 15,018
结果:
/etc/yum.repos.d/CentOS-Base.repo中的repo id为的base有效
/etc/yum.repos.d/pgdg-redhat-all.repo中的updates有效
/etc/yum.repos.d/pgdg-redhat-all.repo中的repo id为pgdg12但是repo name为CentOS-7 - Plus有效
/etc/yum.repos.d/pgdg-redhat-all.repo中的repo id为pgdg12但是repo name为PostgreSQL 12 7 - x86_64没显示
/etc/yum.repos.d/CentOS-Base.repo中的repo id为的centosplus无效,因为enable=0
实验6,修改pgdg-redhat-all.repo内容中的,再增加一个repo id 为updates,但是repo name为name=CentOS-$releasever - Updates1文章来源:https://www.toymoban.com/news/detail-755891.html
[root@FRSPGSQLDEV3]# vim /etc/yum.repos.d/pgdg-redhat-all.repo
[root@FRSPGSQLDEV3]# cat /etc/yum.repos.d/pgdg-redhat-all.repo
[pgdg12]
name=PostgreSQL 12 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
[pgdg12]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates1
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@FRSPGSQLDEV3 yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ocf.berkeley.edu
* pgdg12: centos.mirror.ndchost.com
* updates: centos.mirror.ndchost.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus disabled
pgdg12/7/x86_64 CentOS-7 - Plus enabled: 255
updates/7/x86_64 CentOS-7 - Updates1 enabled: 4,691
repolist: 15,018
结果:
/etc/yum.repos.d/CentOS-Base.repo中的repo id为的base有效
/etc/yum.repos.d/pgdg-redhat-all.repo中的repo id为updates但是repo name为CentOS-7 - Updates1的有效
/etc/yum.repos.d/pgdg-redhat-all.repo中的repo id为updates但是repo name为CentOS-7 - Updates的没有显示
/etc/yum.repos.d/pgdg-redhat-all.repo中的repo id为pgdg12但是repo name为CentOS-7 - Plus有效
/etc/yum.repos.d/pgdg-redhat-all.repo中的repo id为pgdg12但是repo name为PostgreSQL 12 7 - x86_64没显示
/etc/yum.repos.d/CentOS-Base.repo中的repo id为的centosplus无效,因为enable=0
结论:当两个同样的repo id的出现时,其中的一个可能会不显示文章来源地址https://www.toymoban.com/news/detail-755891.html
到了这里,关于Linux之Yum_rpm_repo详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!