1. 程式人生 > >yum源配置與詳解

yum源配置與詳解

gpgkey med mode metadata 查看 grep arch ever manager

一、yum簡介

yum是解決rpm軟件包的依賴性而開發的一種軟件包管理器。yum 的宗旨是自動化地升級,安裝/移除rpm 包,收集rpm 包的相關信息,檢查依賴性並自動提示用戶解決。yum 的關鍵之處是要有可靠的repository,顧名思義,這是軟件的倉庫,它可以是http 或ftp 站點。

二、yum安裝

CentOS 默認已經安裝了yum,不需要另外安裝

1、查看系統默認安裝的yum

[root@localhost ~]# rpm -qa |grep yum
yum-utils-1.1.31-45.el7.noarch
yum-plugin-fastestmirror-1.1.31-45.el7.noarch
PackageKit-yum-1.1.5-1.el7.centos.x86_64
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-langpacks-0.4.2-7.el7.noarch
yum-3.4.3-158.el7.centos.noarch

三、yum配置文件

yum客戶端配置文件:

/etc/yum.conf:為所有倉庫提供公共配置

[root@localhost ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=
http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum


distroverpkg=centos-release

/etc/yum.repos.d/*.repo:為倉庫的指向提供配置

[repoid] 倉庫的名稱,不能重復,獨一無二
name= 倉庫的描述,可以不寫,將會用repoid當作name
enabled=1|0 激活或禁用倉庫,若不寫該行,則默認啟用
gpgcheck=1|0 是否在安裝包是檢測gpg簽名,默認檢測,即為1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 指定gpg key的路徑

[root@localhost rpm-gpg]# ls
RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Debug-7 RPM-GPG-KEY-CentOS-Testing-7
[root@localhost rpm-gpg]# pwd
/etc/pki/rpm-gpg

四、yum倉庫的創建

yum的repo配置文件中可用的變量:

$releasever: 當前OS的發行版的主版本號

$arch: 平臺,i386,i486,i586,x86_64等

$basearch:基礎平臺;i386, x86_64

$YUM0-$YUM9:自定義變量

? 實例:

http://server/centos/$releasever/$basearch/

http://server/centos/7/x86_64

http://server/centos/6/i384

[root@localhost ~]# vim /etc/yum.repos.d/fhj.repo
[root@localhost ~]# cat /etc/yum.repos.d/fhj.repo
[base]
name=Red Hat Enterprise Linux $releasever Repo
baseurl=
http://172.18.0.1/centos/$releasever
enabled=1 #教師機yum源鏡像
gpgcheck=0
[base]
name=Red Hat Enterprise Linux $releasever Repo
baseurl=file:///media #本地yum源鏡像
enabled=1
gpgcheck=0
[epel]
name=mage epel $releasever
baseurl=
http://172.18.0.1/fedora-epel/$releasever/$basearch
enabled=1
gpgcheck=0 #第三方庫文件
使用在線epel
[epel]
name=mage epel
baseurl=
https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
enabled=1
gpgcheck=0

自動生成倉庫

[root@localhost ~]# yum-config-manager --add "https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/"
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
adding repo from:
https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/

[mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_]
name=added from:
https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
enabled=1

五、yum命令

用法:yum 選項 命令 包名

yum clean all 清空yum緩存
yum makecache 重建緩存,(沒有緩存時,首次使用yum的任何命令都會自動重建)

顯示倉庫列表

[root@localhost ~]# yum repolist all
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
repo id repo name status
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base disabled
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus disabled
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras disabled
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus disabled
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates disabled
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base disabled
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus disabled
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras disabled
C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus disabled
C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates disabled
C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base disabled
C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus disabled
C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras disabled

[root@localhost ~]# yum repolist enabled
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base 9,911
epel/7/x86_64 mage epel 7 11,349
extras/7/x86_64 CentOS-7 - Extras 368
updates/7/x86_64 CentOS-7 - Updates 1,041
repolist: 22,669

顯示程序包

yum list

base 未安裝的包,來自於base
epel 未安裝的包,來自於epel
@base 該包已經安裝,且是從base安裝的
@anaconda 該包已經安裝,且是從操作系統的安裝程序anaconda安裝的

all 默認 表示列出所有包
updates 列出可更新的包
installed 列出已安裝的包
@repoid 表示該包安裝自指定的倉庫
installed 表示該包由rpm命令手工安裝

安裝程序包:

[root@localhost ~]# yum install samba

重新安裝

[root@localhost ~]# yum reinstall tree

檢查可用升級

[root@localhost ~]# yum check-update

升級程序包

[root@localhost ~]# yum update sudo

卸載程序包

[root@localhost ~]# yum remove sudo 卸載時不會連同依賴包一同卸載

查看指定包的詳細信息

[root@localhost ~]# yum info tree

搜索一個文件來自於哪個rpm包,可以是未安裝的包
yum provides "*/rz"

[root@localhost ~]# yum provides "*/rz"
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ | 3.2 kB 00:00:00
(1/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/group_gz | 88 kB 00:00:00
(2/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/updateinfo | 932 kB 00:00:00
(3/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/primary | 3.6 MB 00:00:00
mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ 12629/12629
base/7/x86_64/filelists_db | 6.9 MB 00:00:00
epel/7/x86_64/filelists_db | 7.6 MB 00:00:00
extras/7/x86_64/filelists_db | 588 kB 00:00:00
mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/filelists | 10 MB 00:00:01
updates/7/x86_64/filelists_db | 2.4 MB 00:00:00
lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
Repo : base
Matched from:
Filename : /usr/bin/rz

lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
Repo : @anaconda
Matched from:
Filename : /usr/bin/rz

模糊搜索 軟件包和描述

yum search 關鍵字

[root@localhost ~]# yum search samba

列出指定包所依賴的所有包

yum deplist php

yum history 列出所有的yum歷史
info # 查看某條歷史的詳細信息
redo # 重做某條歷史
undo # 撤消某條歷史
如果該歷史為install,則undo 是remove
如果該歷史為remove,則undo 是install

註意:撤銷某條歷史(某個包的安裝),安裝的包會連同它的依賴包一同刪除

安裝本地的包
yum [local]install /path/*.rpm

[root@localhost ~]# yum install /media/Packages/php-5.4.16-45.el7.x86_64.rpm


yum源配置與詳解