yum、dnf能够解决rpm包的依赖关系,无需手动一个一个通过rpm进行安装依赖包,yum和dnf的底层逻辑还是通过rpm命令安装包,会自动查找依赖关系,然后自动使用rpm进行安装,yum使用的是python2语言编写,dnf是python3语言编写
yum/dnf工作原理
yum/dnf是基于C/S架构
yum服务器:存放rpm包和相关包的元数据;yum服务器只要提供简单的下载就可以了,ftp或者http协议。yum服务器有一个最重要的环节就是整理出每个rpm包的基本信息,包括rpm包对应的版本号,conf文件,binary信息,以及很关键的依赖信息。
yun客户端:访问yum服务器查询或安装等,客户端进行安装时,首先会去解析/etc/yum.repos.d下面所有以.repo结尾的配置文件(即yum源),这些配置文件指定了yum服务器的地址。yum会定期去"更新"yum服务器上的rpm包"清单",然后把"清单"下载保存到yum自己的cache里面,根据/etc/yum.conf里配置(默认是在/var/cache/yum下面),每次调用yum装包的时候都会去这个cache目录下去找"清单",根据"清单"里的rpm包描述从而来确定安装包的名字,版本号,所需要的依赖包等,然后再去yum服务器下载rpm包安装。(前提是不存在rpm包的cache)。
yum服务器的仓库地址:file://(本地光盘等) http:// https:// ftp://
注意:yum仓库的地址一定是repodata的目录所在的地址
yum客户端配置
配置文件:/etc/yum.conf 公共配置文件,为所有仓库提供公共配置 /etc/yum.repos.d/*.repo每个仓库提供配置
配置文件定义:
/etc/yum.conf
[main]
gpgcheck=1 #安装包前要做包的合法和完整性校验
installonly_limit=3 #同时可以安装3个包,最小值为2,如设为0或1,为不限制
clean_requirements_on_remove=True #删除包时,是否将不再使用的包删除
best=True #升级时,自动选择安装最新版,即使缺少包的依赖
/etc/yum.repos.d/*.repo
[base]:代表容器名称,名称可以随意取
name:描述容器含义
mirrorlist:列出这个容器可以使用的镜像站点,如果不想使用,可以注释
baseurl:后面接容器地址,mirrorlist是由yum程序自行找镜像站点,baseurl则是指定一个固定容器地址
gpgcheck:是否需要查阅RPM文件内数字证书
gpgkey:数字证书公钥文件所在位置,使用默认值
$releasever: 当前OS的发行版的主版本号,如:8,7,6
$arch: CPU架构,如:aarch64, i586, i686,x86_64等
$basearch:系统基础平台;i386, x86_64
$contentdir:表示目录,比如:centos-8,centos-7
enablegroups={1|0}
failovermethod={roundrobin|priority}
roundrobin:意为随机挑选,默认值 priority:按顺序访问
cost= 默认为1000
使用其他第三方的yum源
09:44:42root@LGW-Linux-7yum.repos.d]#touch Base.repo[09:44:59root@LGW-Linux-7yum.repos.d]#vim Base.repo
[14:00:57root@LGW-Linux-7yum.repos.d]#mv CentOS-Base.repo CentOS-Base.repo.bak
[Base]
name=centos base
baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
enabled=1
~
[14:01:08root@LGW-Linux-7yum.repos.d]#yum repolist 查看yum源列表
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Base | 3.6 kB 00:00:00
(1/2): Base/group_gz | 153 kB 00:00:00
(2/2): Base/primary_db | 6.1 MB 00:00:07
repo id repo name status
Base centos base 10,072
repolist: 10,072
[14:01:25root@LGW-Linux-7yum.repos.d]#vim Base.repo
优化使用变量
[Base]
name=centos base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=0
enabled=1
~
新增update的yum源
注意:与之前的版本不同, 8 系统有两个yum 源:BaseOS和AppStream ,需要分别设置两个仓库
[Base]name=centos base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=0
enabled=1
[update]
name=update
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=0
enabled=1
选择sl包实现跑火车,导入fedo源[fedor]
name=fedor
baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64/
yum-config-manager命令启用和禁用仓库
增加仓库 yum-config-manager --add-repo url或者file
禁用仓库 yum-config-manage --disable ‘仓库name’
启用仓库 yum-config-manage --enable ‘仓库名’
14:52:34root@LGW-Linux-7yum.repos.d]#yum repolist allLoaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* extras: mirrors.aliyun.com
* update: mirrors.aliyun.com
repo id repo name status
Base/7/x86_64 centos base enabled: 10,072
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com enabled: 512
fedor fedor enabled: 13,758
update/7/x86_64 update enabled: 4,135
repolist: 28,477
[14:52:43root@LGW-Linux-7yum.repos.d]#yum-config-manager --disable fedor
Loaded plugins: fastestmirror, langpacks
================================================================ repo: fedor =================================================================
[fedor]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://dl.fedoraproject.org/pub/epel/7/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/7/fedor
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 0
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/fedor/gpgcadir
gpgcakey =
gpgcheck = False
gpgdir = /var/lib/yum/repos/x86_64/7/fedor/gpgdir
gpgkey =
hdrdir = /var/cache/yum/x86_64/7/fedor/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = fedor
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/fedor
pkgdir = /var/cache/yum/x86_64/7/fedor/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = fedor
ui_repoid_vars = releasever,
basearch
username =
[14:53:05root@LGW-Linux-7yum.repos.d]#yum repolist all
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* extras: mirrors.aliyun.com
* update: mirrors.aliyun.com
repo id repo name status
Base/7/x86_64 centos base enabled: 10,072
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com enabled: 512
fedor fedor disabled
update/7/x86_64 update enabled: 4,135
repolist: 14,719
[14:53:18root@LGW-Linux-7yum.repos.d]#