YUM(Yellowdog Updater Modified)是一個基于RPM(Redhat Package Manager紅帽包管理器)包的前端軟件管理工具,是C/S架構下的一種rpm的前端工具,YUM通過分析rpm header數(shù)據(jù),自動處理依賴關系,從指定的repositories倉庫源一次性自動下載安裝所有依賴的rpm包,無須繁瑣地一次次下載、安裝。
repo就是repositories(倉庫)的縮寫,repositories其實就是存放rpm包的路徑,比如file://本地路徑或ftp://服務器路徑或http://網(wǎng)站url路徑
我們要使用YUM,必須要先找到存放rpm包的Repository倉庫源,這些Repository倉庫源的信息存放在目錄為/etc/yum.repos.d/下的文件擴展名為repo的配置文件中,通常一個repo配置文件定義了一個或者多個Repository倉庫源的細節(jié)內(nèi)容,其中可能會多個repo配置文件,每一個repo配置文件中都可以配置一個或多個Repository,但是最終所有Repository倉庫源會被合并為一個交給系統(tǒng)(可以通過yum repolist all顯示出來),所以多個repo配置文件只是為了方便管理。repo配置文件中的設置內(nèi)容將被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
區(qū)別:yum upgrade會刪除舊版本的package,而yum update則會保留(obsoletes=0),建議使用yum update,防止舊版本包被刪除從而導致其他舊的軟件包依賴出現(xiàn)問題。
repo配置文件內(nèi)容的解釋,示例如下
[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根據(jù)使用者客戶端的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/文件夾下,發(fā)現(xiàn) $basearch 其實就是 x86_64,$releasever就是7,然后代入mirrorlist中發(fā)現(xiàn)mirrorlist就是http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=$infra網(wǎng)頁,該網(wǎng)頁下面一堆的url,代入baseurl發(fā)現(xiàn)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:數(shù)字證書公鑰文件所在位置,用戶下載安裝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添加內(nèi)容[centosplus],如下,該內(nèi)容和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內(nèi)容,把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添加內(nèi)容[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內(nèi)容中的[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內(nèi)容中的,再增加一個repo id 為updates,但是repo name為name=CentOS-$releasever - Updates1文章來源:http://www.zghlxwxcb.cn/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的出現(xiàn)時,其中的一個可能會不顯示文章來源地址http://www.zghlxwxcb.cn/news/detail-755891.html
到了這里,關于Linux之Yum_rpm_repo詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!